-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Extend tests for --watch
options
#3915
Extend tests for --watch
options
#3915
Conversation
bb66278
to
5a2124b
Compare
Yes, this is non-trivial stuff and I will need some time to digest this. I have doubts about the change from callback to promises. I would have expexted the tests to crash, since our integration tests should also include browser and yes IE11 tests. runMochaJSONRaw: it has been required in just one single spec file? |
As far as I can see from
Yes, only in the watcher spec. (I would actually prefer to move it to the spec file but did not want to make to many changes.) |
Thanks @geigerzaehler |
I pushed your branch to this repo and both additional tests have succeeded. |
This is untrue (unfortunately); only the stuff in I was also hoping to switch to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a welcome addition to our test suites, thank you!
I have a couple requested changes, IMO nothing major. please resolve them or discuss.
.eslintrc.yml
Outdated
@@ -25,6 +25,7 @@ overrides: | |||
- bin/* | |||
- lib/cli/**/*.js | |||
- test/node-unit/**/*.js | |||
- test/integration/**/*.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would prefer if we can list individual files here; would rather not open the floodgates to ES6 in the integration tests, as there are tentative plans to run some portion of them in a browser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/integration/helpers.js
Outdated
@@ -282,7 +287,7 @@ function resolveFixturePath(fixture) { | |||
if (path.extname(fixture) !== '.js') { | |||
fixture += '.fixture.js'; | |||
} | |||
return path.join('test', 'integration', 'fixtures', fixture); | |||
return path.resolve('test', 'integration', 'fixtures', fixture); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this actually change anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was necessary before but I changed the signature of runMochaJSONRawAsync
to not use a special fixturePath
argument. This allows us to revert this change and make the code more understandable.
* Touch a file by appending a space to the end. Returns a promise that resolves | ||
* when the file has been touched. | ||
*/ | ||
function touchFile(file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function doesn't return anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the documentation in 3948056
args = ['--watch'].concat(args); | ||
const [mocha, mochaDone] = runMochaJSONRawAsync(fixture, args, spawnOpts); | ||
const testResults = mochaDone.then(data => { | ||
expect(data.code, 'to be', sigintExitCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can skip this. these tests aren't asserting Mocha exits how we expect; they are --watch
tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @boneskull. I hope I have addressed all your comments |
@boneskull why do we test with "cross-spawn", when in real life Mocha runs with node's "child_process"? |
I don’t think there’s a great reason. There are issues with child_process spawn on windows, but don’t know if those affect mocha in any meaningful way |
@craigtaub could you review this PR, please? I think you have been the author of the first watch test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geigerzaehler thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny comment. Nice work. LGTM
This commit adds two test cases to test the `--watch` option. We check that touching a test file reruns the tests and we test that touching a file that has a correct extensions reruns the test. This commit adds `fs-extra` as a new dev dependency.
2777874
to
c66e6a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@geigerzaehler thanks a ton! |
Thanks for the support |
Requirements
Test coverage for the
--watch
option needs to be improved. We also need a solid base to be able to test the changes proposed in #3912.Description of the Change
This PR adds two test cases to test the
--watch
option. We check that touching a test file reruns the tests and we test that touching file that has a correct extensions reruns the test.With the support code introduced we also update the one existing test.
The change uses promises instead of callbacks. For example we change
runMochaJSONRaw
torunMochaJSONRawAsync
. The use of promises improves the control flow and gives better error messages.Benefits
Possible Drawbacks
The tests introduce
fs-extra
as a dev dependency. We need this for the following reasons:fs.copyFile
fs
module has no method to remove a directory and its content.The tests require quite a lot of non-trivial support code.
With the introduction of
runMochaJSONRawAsync
we mix promise based and callback based APIs. While this is not ideal the benefits of using promises (described above) warrant this inconsistencyApplicable issues
#3912