-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new
injectGlobals
config and CLI option to disable inject…
…ing global variables into the runtime (#10484)
- Loading branch information
Showing
17 changed files
with
178 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`globals are undefined if passed \`false\` from CLI 1`] = ` | ||
PASS __tests__/test.js | ||
✓ no globals injected | ||
`; | ||
|
||
exports[`globals are undefined if passed \`false\` from CLI 2`] = ` | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: <<REPLACED>> | ||
Ran all test suites. | ||
`; | ||
exports[`globals are undefined if passed \`false\` from config 1`] = ` | ||
PASS __tests__/test.js | ||
✓ no globals injected | ||
`; | ||
exports[`globals are undefined if passed \`false\` from config 2`] = ` | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: <<REPLACED>> | ||
Ran all test suites. | ||
`; |
This file contains 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 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,57 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as path from 'path'; | ||
import {tmpdir} from 'os'; | ||
import {wrap} from 'jest-snapshot-serializer-raw'; | ||
import {skipSuiteOnJasmine} from '@jest/test-utils'; | ||
import {json as runJest} from '../runJest'; | ||
import { | ||
cleanup, | ||
createEmptyPackage, | ||
extractSummary, | ||
writeFiles, | ||
} from '../Utils'; | ||
|
||
const DIR = path.resolve(tmpdir(), 'injectGlobalVariables.test'); | ||
const TEST_DIR = path.resolve(DIR, '__tests__'); | ||
|
||
skipSuiteOnJasmine(); | ||
|
||
beforeEach(() => { | ||
cleanup(DIR); | ||
createEmptyPackage(DIR); | ||
|
||
const content = ` | ||
const {expect: importedExpect, test: importedTest} = require('@jest/globals'); | ||
importedTest('no globals injected', () =>{ | ||
importedExpect(typeof expect).toBe('undefined'); | ||
importedExpect(typeof test).toBe('undefined'); | ||
importedExpect(typeof jest).toBe('undefined'); | ||
importedExpect(typeof beforeEach).toBe('undefined'); | ||
}); | ||
`; | ||
|
||
writeFiles(TEST_DIR, {'test.js': content}); | ||
}); | ||
|
||
afterAll(() => cleanup(DIR)); | ||
|
||
test.each` | ||
configSource | args | ||
${'CLI'} | ${['--inject-globals', 'false']} | ||
${'config'} | ${['--config', JSON.stringify({injectGlobals: false})]} | ||
`('globals are undefined if passed `false` from $configSource', ({args}) => { | ||
const {json, stderr, exitCode} = runJest(DIR, args); | ||
|
||
const {summary, rest} = extractSummary(stderr); | ||
expect(wrap(rest)).toMatchSnapshot(); | ||
expect(wrap(summary)).toMatchSnapshot(); | ||
expect(exitCode).toBe(0); | ||
expect(json.numPassedTests).toBe(1); | ||
}); |
This file contains 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 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 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 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 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 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 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 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 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 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 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