fix: simplify transform RegExp (#10207)

This commit is contained in:
Elad Ossadon 2020-10-19 04:44:24 -07:00 committed by GitHub
parent ecb31a71f0
commit 7d7e97fb9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 64 additions and 68 deletions

View File

@ -6,6 +6,7 @@
### Fixes
- `[jest-config]` Simplify transform RegExp ([#10207](https://github.com/facebook/jest/pull/10207))
- `[jest-fake-timers]` Lazily instantiate mock timers ([#10551](https://github.com/facebook/jest/pull/10551))
- `[jest-runtime]` `require.main` is no longer `undefined` when using `jest.resetModules` ([#10626](https://github.com/facebook/jest/pull/10626))
- `[@jest/types]` Add missing values for `timers` ([#10632](https://github.com/facebook/jest/pull/10632))

View File

@ -1223,7 +1223,7 @@ If the value is `modern`, [`@sinonjs/fake-timers`](https://github.com/sinonjs/fa
### `transform` [object\<string, pathToTransformer | [pathToTransformer, object]>]
Default: `{"^.+\\.[jt]sx?$": "babel-jest"}`
Default: `{"\\.[jt]sx?$": "babel-jest"}`
A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/master/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md).
@ -1238,7 +1238,7 @@ You can pass configuration to a transformer like `{filePattern: ['path-to-transf
_Note: a transformer is only run once per file unless the file has changed. During the development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._
_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"^.+\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_
_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_
### `transformIgnorePatterns` [array\<string>]

View File

@ -125,8 +125,8 @@ _Note: if you are using babel-jest with additional code preprocessors, you have
```json
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.css$": "custom-transformer",
"\\.js$": "babel-jest",
"\\.css$": "custom-transformer",
...
}
```

View File

@ -67,7 +67,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"timers": "real",
"transform": [
[
"^.+\\\\.[jt]sx?$",
"\\\\.[jt]sx?$",
"<<REPLACED_JEST_PACKAGES_DIR>>/babel-jest/build/index.js",
{}
]

View File

@ -2,7 +2,7 @@
"jest": {
"rootDir": "./",
"transform": {
"^.+\\.(ts|js)$": "<rootDir>/typescriptPreprocessor.js"
"\\.(ts|js)$": "<rootDir>/typescriptPreprocessor.js"
},
"testEnvironment": "node"
},

View File

@ -2,7 +2,7 @@
"jest": {
"rootDir": "./",
"transform": {
"^.+\\.(js)$": "<rootDir>/preprocessor.js"
"\\.(js)$": "<rootDir>/preprocessor.js"
},
"testRegex": "/__tests__/.*\\.(js)$",
"testEnvironment": "node",

View File

@ -3,7 +3,7 @@
"testEnvironment": "node",
"globalSetup": "<rootDir>/setup.js",
"transform": {
"^.+\\.js$": "<rootDir>/transformer.js"
"\\.js$": "<rootDir>/transformer.js"
}
}
}

View File

@ -2,7 +2,7 @@
"jest": {
"testEnvironment": "node",
"transform": {
"^.+\\.jsx?$": "../../packages/babel-jest"
"\\.jsx?$": "../../packages/babel-jest"
}
}
}

View File

@ -1,7 +1,7 @@
{
"jest": {
"transform": {
"^.+\\.js$": "<rootDir>/../packages/babel-jest"
"\\.js$": "<rootDir>/../packages/babel-jest"
},
"testEnvironment": "node",
"testPathIgnorePatterns": [

View File

@ -2,7 +2,7 @@
"jest": {
"testEnvironment": "node",
"transform": {
"^.+\\.js$": "<rootDir>/transformer.js"
"\\.js$": "<rootDir>/transformer.js"
},
"snapshotSerializers": [
"./plugins/foo",

View File

@ -2,7 +2,7 @@
"jest": {
"rootDir": "./",
"transform": {
"^.+\\.(ts)$": "<rootDir>/preprocessor.js"
"\\.(ts)$": "<rootDir>/preprocessor.js"
},
"testEnvironment": "node",
"testRegex": "fails"

View File

@ -2,7 +2,7 @@
"jest": {
"rootDir": "./",
"transform": {
"^.+\\.(ts)$": "<rootDir>/preprocessor.js"
"\\.(ts)$": "<rootDir>/preprocessor.js"
},
"testEnvironment": "node",
"testRegex": "fails"

View File

@ -7,7 +7,7 @@
"<rootDir>/ignored/"
],
"transform": {
"^.+\\.js$": "<rootDir>/preprocessor.js"
"\\.js$": "<rootDir>/preprocessor.js"
}
}
}

View File

@ -4,7 +4,7 @@
"jest": {
"testEnvironment": "node",
"transform": {
"^.+\\.js$": "<rootDir>/transformer.js"
"\\.js$": "<rootDir>/transformer.js"
}
}
}

View File

@ -1,7 +1,7 @@
{
"jest": {
"transform": {
"^.+\\.js$": "<rootDir>/preprocessor.js"
"\\.js$": "<rootDir>/preprocessor.js"
},
"testEnvironment": "node"
}

View File

@ -12,7 +12,7 @@
"**/__tests__/**/*.mjs"
],
"transform": {
"^.+\\.mjs?$": "../../../packages/babel-jest"
"\\.mjs?$": "../../../packages/babel-jest"
}
}
}

View File

@ -1,9 +1,9 @@
{
"jest": {
"transform": {
"^.+\\.css$": "<rootDir>/cssPreprocessor.js",
"^.+\\.js$": "<rootDir>/jsPreprocessor.js",
"^.+\\.svg$": "<rootDir>/filePreprocessor.js"
"\\.css$": "<rootDir>/cssPreprocessor.js",
"\\.js$": "<rootDir>/jsPreprocessor.js",
"\\.svg$": "<rootDir>/filePreprocessor.js"
},
"testEnvironment": "node"
},

View File

@ -2,7 +2,7 @@
"jest": {
"rootDir": "./",
"transform": {
"^.+\\.(ts|js)$": "<rootDir>/typescriptPreprocessor.js"
"\\.(ts|js)$": "<rootDir>/typescriptPreprocessor.js"
},
"testEnvironment": "node"
},

View File

@ -4,8 +4,8 @@
"jest": {
"testEnvironment": "node",
"transform": {
"^.+\\.[jt]sx?$": "babel-jest",
"^.+\\.css$": "<rootDir>/cssTransform.js"
"\\.[jt]sx?$": "babel-jest",
"\\.css$": "<rootDir>/cssTransform.js"
}
}
}

View File

@ -2,9 +2,6 @@ module.exports = {
moduleFileExtensions: ['ts', 'html', 'js', 'json'],
setupFilesAfterEnv: ['<rootDir>/setupJest.js'],
transform: {
'^.+\\.[t|j]s$': [
'babel-jest',
{configFile: require.resolve('./.babelrc')},
],
'\\.[tj]s$': ['babel-jest', {configFile: require.resolve('./.babelrc')}],
},
};

View File

@ -1,6 +1,6 @@
module.exports = {
preset: 'react-native',
transform: {
'^.+\\.(js|ts|tsx)$': require.resolve('react-native/jest/preprocessor.js'),
'\\.(js|ts|tsx)$': require.resolve('react-native/jest/preprocessor.js'),
},
};

View File

@ -63,7 +63,7 @@ module.exports = {
'/e2e/__tests__/iterator-to-null-test.ts',
],
transform: {
'^.+\\.[jt]sx?$': '<rootDir>/packages/babel-jest',
'\\.[jt]sx?$': '<rootDir>/packages/babel-jest',
},
watchPathIgnorePatterns: ['coverage'],
watchPlugins: [

View File

@ -20,6 +20,6 @@ To explicitly define `babel-jest` as a transformer for your JavaScript code, map
```json
"transform": {
"^.+\\.[t|j]sx?$": "babel-jest"
"\\.[jt]sx?$": "babel-jest"
},
```

View File

@ -119,7 +119,7 @@ const initialOptions: Config.InitialOptions = {
testURL: 'http://localhost',
timers: 'real',
transform: {
'^.+\\.js$': '<rootDir>/preprocessor.js',
'\\.js$': '<rootDir>/preprocessor.js',
},
transformIgnorePatterns: [NODE_MODULES_REGEXP],
unmockedModulePathPatterns: ['mock'],

View File

@ -14,7 +14,7 @@ import Defaults from '../Defaults';
import {DEFAULT_JS_PATTERN} from '../constants';
const DEFAULT_CSS_PATTERN = '^.+\\.(css)$';
const DEFAULT_CSS_PATTERN = '\\.(css)$';
jest
.mock('jest-resolve')
@ -779,7 +779,7 @@ describe('babel-jest', () => {
});
it('uses babel-jest if babel-jest is explicitly specified in a custom transform options', () => {
const customJSPattern = '^.+\\.js$';
const customJSPattern = '\\.js$';
const {options} = normalize(
{
rootDir: '/root',

View File

@ -8,7 +8,7 @@
import * as path from 'path';
export const NODE_MODULES = path.sep + 'node_modules' + path.sep;
export const DEFAULT_JS_PATTERN = '^.+\\.[jt]sx?$';
export const DEFAULT_JS_PATTERN = '\\.[jt]sx?$';
export const DEFAULT_REPORTER_LABEL = 'default';
export const PACKAGE_JSON = 'package.json';
export const JEST_CONFIG_BASE_NAME = 'jest.config';

View File

@ -51,7 +51,7 @@ describe('generateEmptyCoverage', () => {
cacheDirectory: os.tmpdir(),
cwd: rootDir,
rootDir,
transform: [['^.+\\.js$', require.resolve('babel-jest')]],
transform: [['\\.js$', require.resolve('babel-jest')]],
}),
);
@ -95,7 +95,7 @@ describe('generateEmptyCoverage', () => {
cacheDirectory: os.tmpdir(),
cwd: rootDir,
rootDir,
transform: [['^.+\\.js$', require.resolve('babel-jest')]],
transform: [['\\.js$', require.resolve('babel-jest')]],
}),
);
@ -124,7 +124,7 @@ describe('generateEmptyCoverage', () => {
cacheDirectory: os.tmpdir(),
cwd: rootDir,
rootDir,
transform: [['^.+\\.js$', require.resolve('babel-jest')]],
transform: [['\\.js$', require.resolve('babel-jest')]],
}),
);

View File

@ -22,7 +22,7 @@ describe('Runtime', () => {
describe('internalModule', () => {
it('loads modules and applies transforms', () =>
createRuntime(__filename, {
transform: {'^.+\\.js$': './test_preprocessor'},
transform: {'\\.js$': './test_preprocessor'},
}).then(runtime => {
const modulePath = path.resolve(
path.dirname(runtime.__mockRootPath),
@ -35,7 +35,7 @@ describe('Runtime', () => {
it('loads internal modules without applying transforms', () =>
createRuntime(__filename, {
transform: {'^.+\\.js$': './test_preprocessor'},
transform: {'\\.js$': './test_preprocessor'},
}).then(runtime => {
const modulePath = path.resolve(
path.dirname(runtime.__mockRootPath),
@ -47,7 +47,7 @@ describe('Runtime', () => {
it('loads JSON modules and applies transforms', () =>
createRuntime(__filename, {
transform: {'^.+\\.json$': './test_json_preprocessor'},
transform: {'\\.json$': './test_json_preprocessor'},
}).then(runtime => {
const modulePath = path.resolve(
path.dirname(runtime.__mockRootPath),
@ -59,7 +59,7 @@ describe('Runtime', () => {
it('loads internal JSON modules without applying transforms', () =>
createRuntime(__filename, {
transform: {'^.+\\.json$': './test_json_preprocessor'},
transform: {'\\.json$': './test_json_preprocessor'},
}).then(runtime => {
const modulePath = path.resolve(
path.dirname(runtime.__mockRootPath),

View File

@ -58,7 +58,7 @@ Object {
"timers": "real",
"transform": Array [
Array [
"^.+\\\\.js$",
"\\\\.js$",
"test_preprocessor",
],
],
@ -231,7 +231,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","testURL":"http://localhost","timers":"real","transform":[["\\\\.js$","test_preprocessor"],["\\\\.css$","css-preprocessor"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}',
};
`;
@ -248,7 +248,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","testURL":"http://localhost","timers":"real","transform":[["\\\\.js$","test_preprocessor"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}',
};
`;

View File

@ -281,7 +281,7 @@ describe('ScriptTransformer', () => {
() => {
config = {
...config,
transform: [['^.+\\.js$', 'passthrough-preprocessor']],
transform: [['\\.js$', 'passthrough-preprocessor']],
};
const scriptTransformer = new ScriptTransformer(config);
@ -317,7 +317,7 @@ describe('ScriptTransformer', () => {
it("throws an error if `process` doesn't defined", () => {
config = {
...config,
transform: [['^.+\\.js$', 'skipped-required-props-preprocessor']],
transform: [['\\.js$', 'skipped-required-props-preprocessor']],
};
const scriptTransformer = new ScriptTransformer(config);
expect(() =>
@ -329,7 +329,7 @@ describe('ScriptTransformer', () => {
config = {
...config,
transform: [
['^.+\\.js$', 'skipped-required-create-transformer-props-preprocessor'],
['\\.js$', 'skipped-required-create-transformer-props-preprocessor'],
],
};
const scriptTransformer = new ScriptTransformer(config);
@ -341,7 +341,7 @@ describe('ScriptTransformer', () => {
it("shouldn't throw error without process method. But with corrent createTransformer method", () => {
config = {
...config,
transform: [['^.+\\.js$', 'skipped-process-method-preprocessor']],
transform: [['\\.js$', 'skipped-process-method-preprocessor']],
};
const scriptTransformer = new ScriptTransformer(config);
expect(() =>
@ -350,7 +350,7 @@ describe('ScriptTransformer', () => {
});
it('uses the supplied preprocessor', () => {
config = {...config, transform: [['^.+\\.js$', 'test_preprocessor']]};
config = {...config, transform: [['\\.js$', 'test_preprocessor']]};
const scriptTransformer = new ScriptTransformer(config);
const res1 = scriptTransformer.transform('/fruits/banana.js', {});
@ -367,8 +367,8 @@ describe('ScriptTransformer', () => {
config = {
...config,
transform: [
['^.+\\.js$', 'test_preprocessor'],
['^.+\\.css$', 'css-preprocessor'],
['\\.js$', 'test_preprocessor'],
['\\.css$', 'css-preprocessor'],
],
};
const scriptTransformer = new ScriptTransformer(config);
@ -389,7 +389,7 @@ describe('ScriptTransformer', () => {
it('writes source map if preprocessor supplies it', () => {
config = {
...config,
transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']],
transform: [['\\.js$', 'preprocessor-with-sourcemaps']],
};
const scriptTransformer = new ScriptTransformer(config);
@ -419,7 +419,7 @@ describe('ScriptTransformer', () => {
it('writes source map if preprocessor inlines it', () => {
config = {
...config,
transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']],
transform: [['\\.js$', 'preprocessor-with-sourcemaps']],
};
const scriptTransformer = new ScriptTransformer(config);
@ -454,7 +454,7 @@ describe('ScriptTransformer', () => {
config = {
...config,
transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']],
transform: [['\\.js$', 'preprocessor-with-sourcemaps']],
};
const scriptTransformer = new ScriptTransformer(config);
@ -488,7 +488,7 @@ describe('ScriptTransformer', () => {
it('writes source maps if given by the transformer', () => {
config = {
...config,
transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']],
transform: [['\\.js$', 'preprocessor-with-sourcemaps']],
};
const scriptTransformer = new ScriptTransformer(config);
@ -521,7 +521,7 @@ describe('ScriptTransformer', () => {
it('does not write source map if not given by the transformer', () => {
config = {
...config,
transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']],
transform: [['\\.js$', 'preprocessor-with-sourcemaps']],
};
const scriptTransformer = new ScriptTransformer(config);
@ -543,7 +543,7 @@ describe('ScriptTransformer', () => {
it('should write a source map for the instrumented file when transformed', () => {
const transformerConfig = {
...config,
transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']],
transform: [['\\.js$', 'preprocessor-with-sourcemaps']],
};
const scriptTransformer = new ScriptTransformer(transformerConfig);
@ -626,7 +626,7 @@ describe('ScriptTransformer', () => {
});
it('passes expected transform options to getCacheKey', () => {
config = {...config, transform: [['^.+\\.js$', 'test_preprocessor']]};
config = {...config, transform: [['\\.js$', 'test_preprocessor']]};
const scriptTransformer = new ScriptTransformer(config);
scriptTransformer.transform(
@ -643,9 +643,7 @@ describe('ScriptTransformer', () => {
it('creates transformer with config', () => {
const transformerConfig = {};
config = Object.assign(config, {
transform: [
['^.+\\.js$', 'configureable-preprocessor', transformerConfig],
],
transform: [['\\.js$', 'configureable-preprocessor', transformerConfig]],
});
const scriptTransformer = new ScriptTransformer(config);
@ -658,7 +656,7 @@ describe('ScriptTransformer', () => {
it('reads values from the cache', () => {
const transformConfig = {
...config,
transform: [['^.+\\.js$', 'test_preprocessor']],
transform: [['\\.js$', 'test_preprocessor']],
};
let scriptTransformer = new ScriptTransformer(transformConfig);
scriptTransformer.transform('/fruits/banana.js', {});
@ -699,7 +697,7 @@ describe('ScriptTransformer', () => {
it('reads values from the cache when the file contains colons', () => {
const transformConfig = {
...config,
transform: [['^.+\\.js$', 'test_preprocessor']],
transform: [['\\.js$', 'test_preprocessor']],
};
let scriptTransformer = new ScriptTransformer(transformConfig);
scriptTransformer.transform('/fruits/banana:colon.js', {});
@ -727,14 +725,14 @@ describe('ScriptTransformer', () => {
it('does not reuse the in-memory cache between different projects', () => {
const scriptTransformer = new ScriptTransformer({
...config,
transform: [['^.+\\.js$', 'test_preprocessor']],
transform: [['\\.js$', 'test_preprocessor']],
});
scriptTransformer.transform('/fruits/banana.js', {});
const anotherScriptTransformer = new ScriptTransformer({
...config,
transform: [['^.+\\.js$', 'css-preprocessor']],
transform: [['\\.js$', 'css-preprocessor']],
});
anotherScriptTransformer.transform('/fruits/banana.js', {});
@ -746,7 +744,7 @@ describe('ScriptTransformer', () => {
it('preload transformer when using `preloadTransformer`', () => {
const scriptTransformer = new ScriptTransformer({
...config,
transform: [['^.+\\.js$', 'test_preprocessor']],
transform: [['\\.js$', 'test_preprocessor']],
});
expect(Array.from(scriptTransformer._transformCache.entries())).toEqual([]);

View File

@ -131,7 +131,7 @@ This will output:
Example:
{
"transform": {
"^.+\\.js$": "<rootDir>/preprocessor.js"
"\\.js$": "<rootDir>/preprocessor.js"
}
}

View File

@ -115,7 +115,7 @@ const validConfig = {
testURL: 'http://localhost',
timers: 'real',
transform: {
'^.+\\.js$': '<rootDir>/preprocessor.js',
'\\.js$': '<rootDir>/preprocessor.js',
},
transformIgnorePatterns: [NODE_MODULES_REGEXP],
unmockedModulePathPatterns: ['mock'],