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
- `[jest-config, jest-cli, jest-core,jest-tranform, jest-environment-jsdom, jest-types, jest-validate, test-utils]` [**BREAKING**] Remove `testURL` config, use `can be set in "testEnvironmentOptions`
SimenB marked this conversation as resolved.
Show resolved Hide resolved

### Fixes

Expand Down
5 changes: 3 additions & 2 deletions e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Expand Up @@ -52,7 +52,9 @@ exports[`--showConfig outputs config info and exits 1`] = `
"slowTestThreshold": 5,
"snapshotSerializers": [],
"testEnvironment": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-environment-jsdom/build/index.js",
"testEnvironmentOptions": {},
"testEnvironmentOptions": {
"url": "http://localhost"
},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
Expand All @@ -63,7 +65,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 @@ -258,7 +258,9 @@ module.exports = {
// testEnvironment: \\"jest-environment-jsdom\\",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
// testEnvironmentOptions: {
// \\"url\\": \\"http://localhost\\"
// },

// Adds a location field to test results
// testLocationInResults: false,
Expand All @@ -283,9 +285,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
5 changes: 3 additions & 2 deletions packages/jest-config/src/Defaults.ts
Expand Up @@ -55,15 +55,16 @@ const defaultOptions: Config.DefaultOptions = {
slowTestThreshold: 5,
snapshotSerializers: [],
testEnvironment: 'jest-environment-jsdom',
testEnvironmentOptions: {},
testEnvironmentOptions: {
url: 'http://localhost',
},
SimenB marked this conversation as resolved.
Show resolved Hide resolved
testFailureExitCode: 1,
testLocationInResults: false,
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
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 @@ -216,7 +216,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
1 change: 0 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 @@ -42,15 +42,16 @@ exports[`prints the config object 1`] = `
"slowTestThreshold": 5,
"snapshotSerializers": [],
"testEnvironment": "node",
"testEnvironmentOptions": {},
"testEnvironmentOptions": {
"url": "http://localhost"
},
"testLocationInResults": false,
"testMatch": [],
"testPathIgnorePatterns": [],
"testRegex": [
"\\\\.test\\\\.js$"
],
"testRunner": "myRunner",
"testURL": "http://localhost",
"timers": "real",
"transform": [],
"transformIgnorePatterns": [],
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -34,7 +34,8 @@ class JSDOMEnvironment implements JestEnvironment {
this.dom = new JSDOM('<!DOCTYPE html>', {
pretendToBeVisual: true,
runScripts: 'dangerously',
url: config.testURL,
// @ts-expect-error
SimenB marked this conversation as resolved.
Show resolved Hide resolved
url: config.testEnvironmentOptions.url,
virtualConsole: new VirtualConsole().sendTo(options.console || console),
...config.testEnvironmentOptions,
});
Expand Down
Expand Up @@ -46,15 +46,16 @@ Object {
"snapshotResolver": undefined,
"snapshotSerializers": Array [],
"testEnvironment": "node",
"testEnvironmentOptions": Object {},
"testEnvironmentOptions": Object {
"url": "http://localhost",
},
"testLocationInResults": false,
"testMatch": Array [],
"testPathIgnorePatterns": Array [],
"testRegex": Array [
"\\\\.test\\\\.js$",
],
"testRunner": "jest-jasmine2",
"testURL": "http://localhost",
"timers": "real",
"transform": Array [
Array [
Expand Down Expand Up @@ -232,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":{"url":"http://localhost"},"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 @@ -249,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":{"url":"http://localhost"},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-jasmine2","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}',
};
`;

Expand Down
10 changes: 3 additions & 7 deletions packages/jest-types/src/Config.ts
Expand Up @@ -90,15 +90,14 @@ export type DefaultOptions = {
slowTestThreshold: number;
snapshotSerializers: Array<Path>;
testEnvironment: string;
testEnvironmentOptions: Record<string, unknown>;
testEnvironmentOptions?: Record<string, any>;
SimenB marked this conversation as resolved.
Show resolved Hide resolved
testFailureExitCode: string | number;
testLocationInResults: boolean;
testMatch: Array<Glob>;
testPathIgnorePatterns: Array<string>;
testRegex: Array<string>;
testRunner: string;
testSequencer: string;
testURL: string;
timers: Timers;
transformIgnorePatterns: Array<Glob>;
useStderr: boolean;
Expand Down Expand Up @@ -201,7 +200,7 @@ export type InitialOptions = Partial<{
snapshotSerializers: Array<Path>;
errorOnDeprecated: boolean;
testEnvironment: string;
testEnvironmentOptions: Record<string, unknown>;
testEnvironmentOptions?: Record<string, any>;
testFailureExitCode: string | number;
testLocationInResults: boolean;
testMatch: Array<Glob>;
Expand All @@ -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 @@ -363,13 +361,12 @@ export type ProjectConfig = {
snapshotResolver?: Path;
snapshotSerializers: Array<Path>;
testEnvironment: string;
testEnvironmentOptions: Record<string, unknown>;
testEnvironmentOptions?: Record<string, any>;
testMatch: Array<Glob>;
testLocationInResults: boolean;
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 @@ -452,7 +449,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 @@ -107,13 +107,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