-
Notifications
You must be signed in to change notification settings - Fork 1.1k
test(cli): rework snapshots to support parallel test execution #5724
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
Conversation
0513520 to
59834fa
Compare
|
I believe I tried this approach at the beginning and it didn't work as the I have some concerns here as https://github.com/strongloop/loopback-next/blob/59834fa6c1c6f181dc01f3c988da053f24fd4b1e/packages/cli/test/snapshot-matcher.js#L71 depends on when the file is |
I think this is misunderstanding. function initializeSnapshots(snapshotDir) {
// ...
beforeEach(setupSnapshots);
// ...
}The code in The problem was introduced when I added CLI-specific This pull request is fixing the design so that You can run the tests with |
BREAKING CHANGE: We have upgraded to `mocha@8.0.1` and removed support for `--opts` and `test/mocha.opts`. It may break your application if it depends on earlier version of `@loopback/build` for `npm test`. See a list of breaking changes of mocha 8.x at: https://github.com/mochajs/mocha/releases/tag/v8.0.0
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
59834fa to
b107660
Compare
|
I was referring to the usage such as I'm adding b107660 to show the problem I have in mind. It might be an edge case. We can remove the commit afterward. |
I see. Originally, I wanted to call the factory from within a // packages/cli/test/integration/dummy/test1.integration.js
const setupSnapshots = require('../../snapshots');
describe('test1', () => {
const {expectToMatchSnapshot} = setupSnapshots();
it('matches snapshot 1', () => {
expectToMatchSnapshot('test1 result');
});
});Are you ok to continue with my proposal and move snapshot initialization into |
|
Oh, so actually it's enough to move snapshot setup into exports.commonTest = function () {
const {expectToMatchSnapshot} = require('../../snapshots')();
describe('common', () => {
it('matches snapshot 1', function () {
expectToMatchSnapshot('common result');
});
});
}; |
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
|
@bajtos CI is failing. |
|
Your test case @raymondfeng is very good, it uncovers subtle problems in the assumptions made by the current snapshot design. Here is what happens:
There are two problems:
(@raymondfeng I am not sure if the solution you proposed in 20da28e is actually addressing those problems too.) I think the solution is to change the snapshot matcher to compute the snapshot file name based on the test file loaded by Mocha ( I am going to start with refactoring your dummy tests into a permanent part of |
Interestingly enough, this is already happening (at least when the shared test suite is called from inside a The problem with my solution proposed here is that it registers two places that try to write to the same snapshot file - one snapshot matcher instance is created from |
| }); | ||
| }); | ||
|
|
||
| require('./common.integration').commonTest(); |
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.
Calling commonTest outside of any describe block does not make sense to me. It creates duplicate entries in the list of test cases. In my experience with shared test suites, a shared test suite is typically called from inside a describe block, to scope each instance of the suite to the particular scenario being tested.
For example:
|
Opened #5803 to add debug logs + tests for shared test suite. |
|
@bajtos CI is still failing. Do you need to make further changes here? I'm willing to approve it as soon as the CI is green so that we can enable parallel testing soon. From the technical perspective, I still prefer to have a better way to receive |
I think my approach is a dead-end. I'd like to land #5803 instead, and then take a look if 20da28e supports this edge case you identified. If yes, then I'd like to take another look at your implementation to see if it's good as-is or what improvements should be made.
+1 to enable parallel tests soon.
Yeah, that would be best. |
Rework snapshot helper API from a global snapshot matcher cached via
require.cacheinto per-test-file snapshot matchers. Implementation-wise, I am changingsnapshots.jsfrom exporting snapshot-related APIs to export a factory/initialization function instead. This is forcing all test files to explicitly initialize the matcher, which ensures that hooks are correctly installed even when running the tests in parallel.This PR is an alternate solution to 20da28e (see #5011).
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈