Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate unit tests to Mocha #5600

Merged
merged 11 commits into from Apr 9, 2020
Merged

Migrate unit tests to Mocha #5600

merged 11 commits into from Apr 9, 2020

Conversation

jackfranklin
Copy link
Collaborator

@mathiasbynens this is a proof of concept of how we can move to Mocha by replacing the custom test runner with a few small helpers.

I have migrated cookies.spec.js and all the tests pass.

I'm keen to plough ahead and start migrating more test files, but wanted to raise this PR to check:

  • do you have any comments on how the new cookie tests look? Before I make similar changes across all files!
  • Using the cookies.mocha.spec.js renaming we can run one test at a time rather than migrate in bulk. Would you rather one PR for one test file or I just do them all in bulk? The changes are mechanical mostly so I think one PR might be OK.

script.js Outdated Show resolved Hide resolved
test/mocha-utils.js Outdated Show resolved Hide resolved
test/mocha-utils.js Outdated Show resolved Hide resolved
test/mocha-utils.js Outdated Show resolved Hide resolved
.mocharc.js Outdated Show resolved Hide resolved
script.js Outdated Show resolved Hide resolved
script.js Outdated Show resolved Hide resolved
@mathiasbynens
Copy link
Member

I love the way the tests look, thanks for taking this on Jack! I can't wait to drop the custom test runner code. To answer your question, I'd prefer a single large PR in this case since the changes are mostly mechanical.

@jackfranklin jackfranklin force-pushed the move-tests-to-mocha branch 3 times, most recently from d58ef39 to f465e2e Compare April 8, 2020 09:43
Copy link
Member

@mathiasbynens mathiasbynens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubberstamp LGTM as discussed offline

@jackfranklin jackfranklin changed the title [WIP] Migrate tests to Mocha Migrate unit tests to Mocha Apr 8, 2020
Rather than maintain our own test runner we should instead lean on the
community and use Mocha which is very popular and also our test runner
of choice in DevTools too.

Note that this commit doesn't remove the TestRunner source as it's still
used for other unit tests, but they will be updated in a future PR and
then we can remove the TestRunner.

The main bulk of this PR is updating the tests as the old TestRunner
passed in contextual data via the `it` function callback whereas Mocha
does not, so we introduce some helpers for the tests to make it easier.
Our custom TestRunner used to look for these but now we aren't using it
let's enforce it using ESLint.
Not all tests need a global browser + page, so we have helpers that can
be imported on a per-test basis.
@mathiasbynens mathiasbynens merged commit 17cd870 into master Apr 9, 2020
const GOLDEN_DIR = path.join(__dirname, 'golden-' + suffix);
const OUTPUT_DIR = path.join(__dirname, 'output-' + suffix);
if (fs.existsSync(OUTPUT_DIR))
rm(OUTPUT_DIR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just hit this: rm() is undefined here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants