-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Rework snapshot matcher to support parallel mocha #5813
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright IBM Corp. 2020. All Rights Reserved. | ||
| // Node module: loopback-next | ||
| // This file is licensed under the MIT License. | ||
| // License text available at https://opensource.org/licenses/MIT | ||
|
|
||
| const {mergeMochaConfigs} = require('./packages/build'); | ||
| const defaultConfig = require('./packages/build/config/.mocharc.json'); | ||
|
|
||
| module.exports = mergeMochaConfigs( | ||
| defaultConfig, | ||
| // Apply Mocha config from packages that require custom Mocha setup | ||
| require('./packages/cli/.mocharc.js'), | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright IBM Corp. 2017,2020. All Rights Reserved. | ||
| // Node module: @loopback/build | ||
| // This file is licensed under the MIT License. | ||
| // License text available at https://opensource.org/licenses/MIT | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const debug = require('debug')('loopback:build:merge-mocha-configs'); | ||
| const {assignWith} = require('lodash'); | ||
|
|
||
| module.exports = mergeMochaConfigs; | ||
|
|
||
| /** | ||
| * Merge multiple Mocha configuration files into a single one. | ||
| * | ||
| * @param {MochaConfig[]} configs A list of Mocha configuration objects | ||
| * as provided by `.mocharc.js` files. | ||
| */ | ||
| function mergeMochaConfigs(...configs) { | ||
bajtos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| debug('Merging mocha configurations', ...configs); | ||
| const result = assignWith({}, ...configs, assignMochaConfigEntry); | ||
| debug('Merged config:', result); | ||
| return result; | ||
| } | ||
|
|
||
| function assignMochaConfigEntry(targetValue, sourceValue, key) { | ||
| switch (key) { | ||
| case 'timeout': | ||
| return Math.max(targetValue || 0, sourceValue); | ||
| case 'require': | ||
| if (Array.isArray(sourceValue)) { | ||
| debug('Adding an array of files to require:', sourceValue); | ||
| return [...(targetValue || []), ...sourceValue]; | ||
| } else { | ||
| debug('Adding a single file to require:', sourceValue); | ||
| return [...(targetValue || []), sourceValue]; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright IBM Corp. 2020. All Rights Reserved. | ||
| // Node module: @loopback/cli | ||
| // This file is licensed under the MIT License. | ||
| // License text available at https://opensource.org/licenses/MIT | ||
|
|
||
| // A workaround to use `--require ./test/snapshot-matcher.js` so that root | ||
| // hooks are executed by mocha parallel testing for each job | ||
|
|
||
| const debug = require('debug')('loopback:cli:test'); | ||
| const {mergeMochaConfigs} = require('@loopback/build'); | ||
|
|
||
| // Start with the default config from `@loopback/build` | ||
| const defaultConfig = require('@loopback/build/config/.mocharc.json'); | ||
| debug('Default mocha config:', defaultConfig); | ||
|
|
||
| // Resolve `./test/snapshot-matcher.js` to get the absolute path | ||
| const mochaHooksFile = require.resolve('./test/snapshot-matcher.js'); | ||
| debug('Root hooks for --require %s', mochaHooksFile); | ||
|
|
||
| // Custom configuration for CLI tests | ||
| const CLI_MOCHA_CONFIG = { | ||
| timeout: 5000, | ||
| require: mochaHooksFile, | ||
| }; | ||
|
|
||
| const config = mergeMochaConfigs(defaultConfig, CLI_MOCHA_CONFIG); | ||
| debug('Final mocha config:', config); | ||
|
|
||
| module.exports = config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.