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

feat: remove testURL option, can be set in testEnvironmentOptions #10797

Merged
merged 18 commits into from Feb 23, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
## master

### Features
- [**BREAKING**] `[jest-cli, jest-config]` [**BREAKING**] Remove `testURL` config, use `testEnvironmentOptions` instead

SimenB marked this conversation as resolved.
Show resolved Hide resolved
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))
- `[jest-runner]` [**BREAKING**] set exit code to 1 if test logs after teardown ([#10728](https://github.com/facebook/jest/pull/10728))
Expand Down
1 change: 0 additions & 1 deletion e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Expand Up @@ -63,7 +63,6 @@ exports[`--showConfig outputs config info and exits 1`] = `
],
"testRegex": [],
"testRunner": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-jasmine2/build/index.js",
"testURL": "http://localhost",
"timers": "real",
"transform": [
[
Expand Down
4 changes: 0 additions & 4 deletions packages/jest-cli/src/cli/args.ts
Expand Up @@ -666,10 +666,6 @@ export const options = {
description: 'This option sets the default timeouts of test cases.',
type: 'number',
},
testURL: {
description: 'This option sets the URL for the jsdom environment.',
type: 'string',
},
timers: {
description:
'Setting this value to fake allows the use of fake timers ' +
Expand Down
Expand Up @@ -283,9 +283,6 @@ module.exports = {
// This option allows use of a custom test runner
// testRunner: \\"jasmine2\\",

// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: \\"http://localhost\\",

// Setting this value to \\"fake\\" allows the use of fake timers for functions such as \\"setTimeout\\"
// timers: \\"real\\",

Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/Defaults.ts
Expand Up @@ -63,7 +63,6 @@ const defaultOptions: Config.DefaultOptions = {
testRegex: [],
testRunner: 'jasmine2',
testSequencer: '@jest/test-sequencer',
testURL: 'http://localhost',
timers: 'real',
transformIgnorePatterns: [NODE_MODULES_REGEXP, `\\.pnp\\.[^\\${sep}]+$`],
useStderr: false,
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-config/src/Descriptions.ts
Expand Up @@ -82,8 +82,6 @@ const descriptions: {[key in keyof Config.InitialOptions]: string} = {
testResultsProcessor:
'This option allows the use of a custom results processor',
testRunner: 'This option allows use of a custom test runner',
testURL:
'This option sets the URL for the jsdom environment. It is reflected in properties such as location.href',
timers:
'Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"',
transform: 'A map from regular expressions to paths to transformers',
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-config/src/ValidConfig.ts
Expand Up @@ -103,7 +103,10 @@ const initialOptions: Config.InitialOptions = {
snapshotResolver: '<rootDir>/snapshotResolver.js',
snapshotSerializers: ['my-serializer-module'],
testEnvironment: 'jest-environment-jsdom',
testEnvironmentOptions: {userAgent: 'Agent/007'},
testEnvironmentOptions: {
url: 'http://localhost',
userAgent: 'Agent/007',
},
testFailureExitCode: 1,
testLocationInResults: false,
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
Expand All @@ -117,7 +120,6 @@ const initialOptions: Config.InitialOptions = {
testRunner: 'jasmine2',
testSequencer: '@jest/test-sequencer',
testTimeout: 5000,
testURL: 'http://localhost',
timers: 'real',
transform: {
'\\.js$': '<rootDir>/preprocessor.js',
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -215,7 +215,6 @@ const groupOptions = (
testPathIgnorePatterns: options.testPathIgnorePatterns,
testRegex: options.testRegex,
testRunner: options.testRunner,
testURL: options.testURL,
timers: options.timers,
transform: options.transform,
transformIgnorePatterns: options.transformIgnorePatterns,
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-config/src/normalize.ts
Expand Up @@ -916,7 +916,6 @@ export default function normalize(
case 'testFailureExitCode':
case 'testLocationInResults':
case 'testNamePattern':
case 'testURL':
case 'timers':
case 'useStderr':
case 'verbose':
Expand Down Expand Up @@ -1104,6 +1103,11 @@ export default function normalize(
newOptions.logHeapUsage = false;
}

if (newOptions.testEnvironment.includes('jest-environment-jsdom')) {
SimenB marked this conversation as resolved.
Show resolved Hide resolved
newOptions.testEnvironmentOptions.url =
newOptions.testEnvironmentOptions.url || 'http://localhost';
}

return {
hasDeprecationWarnings,
options: newOptions,
Expand Down
Expand Up @@ -50,7 +50,6 @@ exports[`prints the config object 1`] = `
"\\\\.test\\\\.js$"
],
"testRunner": "myRunner",
"testURL": "http://localhost",
"timers": "real",
"transform": [],
"transformIgnorePatterns": [],
Expand Down
1 change: 0 additions & 1 deletion packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -34,7 +34,6 @@ class JSDOMEnvironment implements JestEnvironment {
this.dom = new JSDOM('<!DOCTYPE html>', {
pretendToBeVisual: true,
runScripts: 'dangerously',
url: config.testURL,
virtualConsole: new VirtualConsole().sendTo(options.console || console),
...config.testEnvironmentOptions,
});
Expand Down
Expand Up @@ -54,7 +54,6 @@ Object {
"\\\\.test\\\\.js$",
],
"testRunner": "jest-jasmine2",
"testURL": "http://localhost",
"timers": "real",
"transform": Array [
Array [
Expand Down Expand Up @@ -234,7 +233,7 @@ exports[`ScriptTransformer uses multiple preprocessors 1`] = `
const TRANSFORMED = {
filename: '/fruits/banana.js',
script: 'module.exports = "banana";',
config: '{"automock":false,"cache":true,"cacheDirectory":"/cache/","clearMocks":false,"coveragePathIgnorePatterns":[],"cwd":"/test_root_dir/","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{},"injectGlobals":true,"moduleDirectories":[],"moduleFileExtensions":["js"],"moduleLoader":"/test_module_loader_path","moduleNameMapper":[],"modulePathIgnorePatterns":[],"modulePaths":[],"name":"test","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/","roots":[],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"skipNodeResolution":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"node","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-jasmine2","testURL":"http://localhost","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}],["\\\\.css$","css-preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}',
config: '{"automock":false,"cache":true,"cacheDirectory":"/cache/","clearMocks":false,"coveragePathIgnorePatterns":[],"cwd":"/test_root_dir/","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{},"injectGlobals":true,"moduleDirectories":[],"moduleFileExtensions":["js"],"moduleLoader":"/test_module_loader_path","moduleNameMapper":[],"modulePathIgnorePatterns":[],"modulePaths":[],"name":"test","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/","roots":[],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"skipNodeResolution":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"node","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-jasmine2","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}],["\\\\.css$","css-preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}',
};
`;

Expand All @@ -251,7 +250,7 @@ exports[`ScriptTransformer uses the supplied preprocessor 1`] = `
const TRANSFORMED = {
filename: '/fruits/banana.js',
script: 'module.exports = "banana";',
config: '{"automock":false,"cache":true,"cacheDirectory":"/cache/","clearMocks":false,"coveragePathIgnorePatterns":[],"cwd":"/test_root_dir/","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{},"injectGlobals":true,"moduleDirectories":[],"moduleFileExtensions":["js"],"moduleLoader":"/test_module_loader_path","moduleNameMapper":[],"modulePathIgnorePatterns":[],"modulePaths":[],"name":"test","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/","roots":[],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"skipNodeResolution":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"node","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-jasmine2","testURL":"http://localhost","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}',
config: '{"automock":false,"cache":true,"cacheDirectory":"/cache/","clearMocks":false,"coveragePathIgnorePatterns":[],"cwd":"/test_root_dir/","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{},"injectGlobals":true,"moduleDirectories":[],"moduleFileExtensions":["js"],"moduleLoader":"/test_module_loader_path","moduleNameMapper":[],"modulePathIgnorePatterns":[],"modulePaths":[],"name":"test","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/","roots":[],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"skipNodeResolution":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"node","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-jasmine2","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}',
};
`;

Expand Down
4 changes: 0 additions & 4 deletions packages/jest-types/src/Config.ts
Expand Up @@ -98,7 +98,6 @@ export type DefaultOptions = {
testRegex: Array<string>;
testRunner: string;
testSequencer: string;
testURL: string;
timers: Timers;
transformIgnorePatterns: Array<Glob>;
useStderr: boolean;
Expand Down Expand Up @@ -212,7 +211,6 @@ export type InitialOptions = Partial<{
testResultsProcessor: string;
testRunner: string;
testSequencer: string;
testURL: string;
testTimeout: number;
timers: Timers;
transform: {
Expand Down Expand Up @@ -364,7 +362,6 @@ export type ProjectConfig = {
testPathIgnorePatterns: Array<string>;
testRegex: Array<string | RegExp>;
testRunner: string;
testURL: string;
timers: Timers;
transform: Array<[string, Path, Record<string, unknown>]>;
transformIgnorePatterns: Array<Glob>;
Expand Down Expand Up @@ -447,7 +444,6 @@ export type Argv = Arguments<
testResultsProcessor: string;
testRunner: string;
testSequencer: string;
testURL: string;
testTimeout: number | null | undefined;
timers: string;
transform: string;
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-validate/src/__tests__/fixtures/jestConfig.ts
Expand Up @@ -48,7 +48,6 @@ const defaultConfig = {
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
testResultsProcessor: null,
testURL: 'http://localhost',
timers: 'real',
transformIgnorePatterns: [NODE_MODULES_REGEXP],
useStderr: false,
Expand Down Expand Up @@ -112,7 +111,6 @@ const validConfig = {
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
testResultsProcessor: 'processor-node-module',
testRunner: 'jasmine2',
testURL: 'http://localhost',
timers: 'real',
transform: {
'\\.js$': '<rootDir>/preprocessor.js',
Expand Down
13 changes: 0 additions & 13 deletions packages/jest-validate/src/__tests__/validateCLIOptions.test.js
Expand Up @@ -19,19 +19,6 @@ test('validates yargs special options', () => {
expect(validateCLIOptions(argv, options)).toBe(true);
});

test('validates testURL', () => {
const options = {
testURL: {
description: 'This option sets the URL for the jsdom environment.',
type: 'string',
},
};
const argv = {
testURL: 'http://localhost',
};
expect(validateCLIOptions(argv, options)).toBe(true);
});

test('fails for unknown option', () => {
const options = ['$0', '_', 'help', 'h'];
const argv = {
Expand Down
5 changes: 3 additions & 2 deletions packages/test-utils/src/config.ts
Expand Up @@ -106,13 +106,14 @@ const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = {
snapshotResolver: undefined,
snapshotSerializers: [],
testEnvironment: 'node',
testEnvironmentOptions: {},
testEnvironmentOptions: {
url: 'http://localhost',
},
testLocationInResults: false,
testMatch: [],
testPathIgnorePatterns: [],
testRegex: ['\\.test\\.js$'],
testRunner: 'jest-jasmine2',
testURL: 'http://localhost',
timers: 'real',
transform: [],
transformIgnorePatterns: [],
Expand Down