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

Fix tests for recent broader-options watch plugins PR #6696

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 64 additions & 62 deletions packages/jest-cli/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,66 +441,63 @@ describe('Watch mode flows', () => {
});

it.each`
ok | option
✔︎ | bail
✖︎ | changedFilesWithAncestor
✖︎ | changedSince
✔︎ | collectCoverage
✔︎ | collectCoverageFrom
✔︎ | collectCoverageOnlyFrom
✔︎ | coverageDirectory
✔︎ | coverageReporters
✖︎ | coverageThreshold
✖︎ | detectLeaks
✖︎ | detectOpenHandles
✖︎ | enabledTestsMap
✖︎ | errorOnDeprecated
✖︎ | expand
✖︎ | filter
✖︎ | findRelatedTests
✖︎ | forceExit
✖︎ | globalSetup
✖︎ | globalTeardown
✖︎ | json
✖︎ | lastCommit
✖︎ | listTests
✖︎ | logHeapUsage
✖︎ | maxWorkers
✖︎ | nonFlagArgs
✖︎ | noSCM
✖︎ | noStackTrace
✔︎ | notify
✔︎ | notifyMode
✖︎ | onlyChanged
✔︎ | onlyFailures
✖︎ | outputFile
✖︎ | passWithNoTests
✖︎ | projects
✖︎ | replname
✔︎ | reporters
✖︎ | rootDir
✖︎ | runTestsByPath
✖︎ | silent
✖︎ | skipFilter
✖︎ | testFailureExitCode
✔︎ | testNamePattern
✔︎ | testPathPattern
✖︎ | testResultsProcessor
✔︎ | updateSnapshot
✖︎ | useStderr
✔︎ | verbose
✖︎ | watch
✖︎ | watchAll
✖︎ | watchman
✖︎ | watchPlugins
ok | option
${'✔︎'} | ${'bail'}
${'✖︎'} | ${'changedFilesWithAncestor'}
${'✖︎'} | ${'changedSince'}
${'✔︎'} | ${'collectCoverage'}
${'✔︎'} | ${'collectCoverageFrom'}
${'✔︎'} | ${'collectCoverageOnlyFrom'}
${'✔︎'} | ${'coverageDirectory'}
${'✔︎'} | ${'coverageReporters'}
${'✖︎'} | ${'coverageThreshold'}
${'✖︎'} | ${'detectLeaks'}
${'✖︎'} | ${'detectOpenHandles'}
${'✖︎'} | ${'enabledTestsMap'}
${'✖︎'} | ${'errorOnDeprecated'}
${'✖︎'} | ${'expand'}
${'✖︎'} | ${'filter'}
${'✖︎'} | ${'findRelatedTests'}
${'✖︎'} | ${'forceExit'}
${'✖︎'} | ${'globalSetup'}
${'✖︎'} | ${'globalTeardown'}
${'✖︎'} | ${'json'}
${'✖︎'} | ${'lastCommit'}
${'✖︎'} | ${'listTests'}
${'✖︎'} | ${'logHeapUsage'}
${'✖︎'} | ${'maxWorkers'}
${'✖︎'} | ${'nonFlagArgs'}
${'✖︎'} | ${'noSCM'}
${'✖︎'} | ${'noStackTrace'}
${'✔︎'} | ${'notify'}
${'✔︎'} | ${'notifyMode'}
${'✖︎'} | ${'onlyChanged'}
${'✔︎'} | ${'onlyFailures'}
${'✖︎'} | ${'outputFile'}
${'✖︎'} | ${'passWithNoTests'}
${'✖︎'} | ${'projects'}
${'✖︎'} | ${'replname'}
${'✔︎'} | ${'reporters'}
${'✖︎'} | ${'rootDir'}
${'✖︎'} | ${'runTestsByPath'}
${'✖︎'} | ${'silent'}
${'✖︎'} | ${'skipFilter'}
${'✖︎'} | ${'testFailureExitCode'}
${'✔︎'} | ${'testNamePattern'}
${'✔︎'} | ${'testPathPattern'}
${'✖︎'} | ${'testResultsProcessor'}
${'✔︎'} | ${'updateSnapshot'}
${'✖︎'} | ${'useStderr'}
${'✔︎'} | ${'verbose'}
${'✖︎'} | ${'watch'}
${'✖︎'} | ${'watchAll'}
${'✖︎'} | ${'watchman'}
${'✖︎'} | ${'watchPlugins'}
`(
'allows WatchPlugins to modify only white-listed global config keys',
async ({ok, option}) => {
const pluginPath = `${__dirname}/__fixtures__/plugin_path_config_updater`;
const config = Object.assign({}, globalConfig, {
rootDir: __dirname,
watchPlugins: [{config: {}, path: pluginPath}],
});
ok = ok === '✔︎';
const pluginPath = `${__dirname}/__fixtures__/plugin_path_config_updater_${option}`;

jest.doMock(
pluginPath,
Expand All @@ -518,20 +515,25 @@ describe('Watch mode flows', () => {
{virtual: true},
);

const config = Object.assign({}, globalConfig, {
rootDir: __dirname,
watchPlugins: [{config: {}, path: pluginPath}],
});

watch(config, contexts, pipe, hasteMapInstances, stdin);
await nextTick();

stdin.emit('x');
await nextTick();

const lastCall = updateGlobalConfig.mock.calls.slice(-1)[0];
let expector = expect(lastCall[0]);
// We need the penultimate call as Jest forces a final call to restore
// updateSnapshot because it's not sticky after a run…?
const lastCall = updateGlobalConfig.mock.calls.slice(-2)[0];
let expector = expect(lastCall[1]);
if (!ok) {
expector = expector.not;
}
expector.toMatchObject({
[option]: '__JUST_TRYING__',
});
expector.toHaveProperty(option, '__JUST_TRYING__');
},
);

Expand Down