-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Transformer configs #7288
Merged
Merged
Transformer configs #7288
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
bd728ed
working version of passing config to transformers via config file.
eightypop e8c084b
ignore flow errors
eightypop 2c4228d
refactor normalize for babel jest and fix tests
eightypop 6b73a0d
remove fixme's from setup since flow annot was removed
eightypop eecd99b
e2e test
eightypop c918098
fix failing test and remove console log
eightypop 3e322bb
fix typo
eightypop 6956e54
update normalize to handle ts
eightypop 653abf0
update changelog
eightypop 04351cb
Update CHANGELOG.md
SimenB 836e700
Update packages/jest-config/src/__tests__/normalize.test.js
thymikee 7c57d0a
use preset instead of transform
eightypop c49fef3
update copyright headers
eightypop d2b958e
Update CHANGELOG.md
jeysal 58f5ac9
add a specific configuration example.
eightypop f6e8179
clean up copy pasta :sweat-smile:
eightypop 614f6df
Merge branch 'master' into transformer-configs
SimenB 48af06b
Merge commit '544984ea118f248017f83ddb5bf10c21a69d9dd6' into transfor…
SimenB 305930c
Merge commit '7ae3f076a03e24e570857db52ce43df263d22f67' into transfor…
SimenB 118b1f2
Merge commit 'e998c9230cb78b3befe0b1b57b36fd5353e766f0' into transfor…
SimenB f933bd4
Merge commit 'ecf7636426ffba5530ad07b513f13179dc4f4e07' into transfor…
SimenB 8556974
Merge branch 'master' into transformer-configs
SimenB b1a60e9
remove old files
SimenB c02aa9d
tweak normalize
SimenB 00a5539
reduce diff
SimenB 192f170
fix lint error
SimenB 94c9a74
normalize for 3.5
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ | ||
{} |
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,12 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
const thisFunctionIsNeverInstrumented = () => null; | ||
|
||
module.exports = { | ||
thisFunctionIsNeverInstrumented, | ||
}; |
15 changes: 15 additions & 0 deletions
15
e2e/transform/transformer-config/__tests__/transformer-config.test.js
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,15 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
require('../this-directory-is-covered/ExcludedFromCoverage'); | ||
|
||
it('strips flowtypes using babel-jest and config passed to transformer', () => { | ||
const a: string = 'a'; | ||
expect(a).toBe('a'); | ||
}); |
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,25 @@ | ||
{ | ||
"dependencies": { | ||
"@babel/preset-flow": "7.0.0" | ||
}, | ||
"jest": { | ||
"collectCoverageOnlyFrom": { | ||
"<rootDir>/this-directory-is-covered/Covered.js": true, | ||
"<rootDir>/this-directory-is-covered/ExcludedFromCoverage.js": true | ||
}, | ||
"coveragePathIgnorePatterns": [ | ||
"ExcludedFromCoverage" | ||
], | ||
"testEnvironment": "node", | ||
"transform": { | ||
"\\.js$": [ | ||
"babel-jest", | ||
{ | ||
"presets": [ | ||
"@babel/preset-flow" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
e2e/transform/transformer-config/this-directory-is-covered/Covered.js
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,19 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
const thisFunctionIsCovered = (): null => null; | ||
|
||
thisFunctionIsCovered(); | ||
|
||
const thisFunctionIsNotCovered = (): void => { | ||
throw new Error('Never Called'); | ||
}; | ||
|
||
module.exports = { | ||
thisFunctionIsCovered, | ||
thisFunctionIsNotCovered, | ||
}; |
15 changes: 15 additions & 0 deletions
15
e2e/transform/transformer-config/this-directory-is-covered/ExcludedFromCoverage.js
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,15 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
require('./Covered'); | ||
require('../NotCovered'); | ||
|
||
const thisFunctionIsNeverInstrumented = () => null; | ||
|
||
module.exports = { | ||
thisFunctionIsNeverInstrumented, | ||
}; |
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,34 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
babel-plugin-syntax-flow@^6.8.0: | ||
version "6.18.0" | ||
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d" | ||
integrity sha1-TDqyCiryaqIM0lmVw5jE63AxDI0= | ||
|
||
[email protected]: | ||
version "6.8.0" | ||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.8.0.tgz#2351d85e3a52152e1a55d3f08ae635e21ece17a0" | ||
integrity sha1-I1HYXjpSFS4aVdPwiuY14h7OF6A= | ||
dependencies: | ||
babel-plugin-syntax-flow "^6.8.0" | ||
babel-runtime "^6.0.0" | ||
|
||
babel-runtime@^6.0.0: | ||
version "6.23.0" | ||
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz#0a9489f144de70efb3ce4300accdb329e2fc543b" | ||
integrity sha1-CpSJ8UTecO+zzkMArM2zKeL8VDs= | ||
dependencies: | ||
core-js "^2.4.0" | ||
regenerator-runtime "^0.10.0" | ||
|
||
core-js@^2.4.0: | ||
version "2.4.1" | ||
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e" | ||
integrity sha1-TekR5mew6ukSTjQlS1OupvxhjT4= | ||
|
||
regenerator-runtime@^0.10.0: | ||
version "0.10.4" | ||
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.4.tgz#74cb6598d3ba2eb18694e968a40e2b3b4df9cf93" | ||
integrity sha1-dMtlmNO6LrGGlOlopA4rO035z5M= |
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 |
---|---|---|
|
@@ -46,19 +46,29 @@ type AllOptions = Config.ProjectConfig & Config.GlobalConfig; | |
const createConfigError = (message: string) => | ||
new ValidationError(ERROR, message, DOCUMENTATION_NOTE); | ||
|
||
const mergeOptionWithPreset = ( | ||
// TS 3.5 forces us to split these into 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jeysal is this something you know how to fix? 😀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const mergeModuleNameMapperWithPreset = ( | ||
options: Config.InitialOptions, | ||
preset: Config.InitialOptions, | ||
) => { | ||
if (options['moduleNameMapper'] && preset['moduleNameMapper']) { | ||
options['moduleNameMapper'] = { | ||
...options['moduleNameMapper'], | ||
...preset['moduleNameMapper'], | ||
...options['moduleNameMapper'], | ||
}; | ||
} | ||
}; | ||
|
||
const mergeTransformWithPreset = ( | ||
options: Config.InitialOptions, | ||
preset: Config.InitialOptions, | ||
optionName: keyof Pick< | ||
Config.InitialOptions, | ||
'moduleNameMapper' | 'transform' | ||
>, | ||
) => { | ||
if (options[optionName] && preset[optionName]) { | ||
options[optionName] = { | ||
...options[optionName], | ||
...preset[optionName], | ||
...options[optionName], | ||
if (options['transform'] && preset['transform']) { | ||
options['transform'] = { | ||
...options['transform'], | ||
...preset['transform'], | ||
...options['transform'], | ||
}; | ||
} | ||
}; | ||
|
@@ -121,8 +131,8 @@ const setupPreset = ( | |
options.modulePathIgnorePatterns, | ||
); | ||
} | ||
mergeOptionWithPreset(options, preset, 'moduleNameMapper'); | ||
mergeOptionWithPreset(options, preset, 'transform'); | ||
mergeModuleNameMapperWithPreset(options, preset); | ||
mergeTransformWithPreset(options, preset); | ||
|
||
return {...preset, ...options}; | ||
}; | ||
|
@@ -140,27 +150,26 @@ const setupBabelJest = (options: Config.InitialOptions) => { | |
return regex.test('a.ts') || regex.test('a.tsx'); | ||
}); | ||
|
||
if (customJSPattern) { | ||
const customJSTransformer = transform[customJSPattern]; | ||
|
||
if (customJSTransformer === 'babel-jest') { | ||
babelJest = require.resolve('babel-jest'); | ||
transform[customJSPattern] = babelJest; | ||
} else if (customJSTransformer.includes('babel-jest')) { | ||
babelJest = customJSTransformer; | ||
} | ||
} | ||
|
||
if (customTSPattern) { | ||
const customTSTransformer = transform[customTSPattern]; | ||
|
||
if (customTSTransformer === 'babel-jest') { | ||
babelJest = require.resolve('babel-jest'); | ||
transform[customTSPattern] = babelJest; | ||
} else if (customTSTransformer.includes('babel-jest')) { | ||
babelJest = customTSTransformer; | ||
[customJSPattern, customTSPattern].forEach(pattern => { | ||
if (pattern) { | ||
const customTransformer = transform[pattern]; | ||
if (Array.isArray(customTransformer)) { | ||
if (customTransformer[0] === 'babel-jest') { | ||
babelJest = require.resolve('babel-jest'); | ||
customTransformer[0] = babelJest; | ||
} else if (customTransformer[0].includes('babel-jest')) { | ||
babelJest = customTransformer[0]; | ||
} | ||
} else { | ||
if (customTransformer === 'babel-jest') { | ||
babelJest = require.resolve('babel-jest'); | ||
transform[pattern] = babelJest; | ||
} else if (customTransformer.includes('babel-jest')) { | ||
babelJest = customTransformer; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} else { | ||
babelJest = require.resolve('babel-jest'); | ||
options.transform = { | ||
|
@@ -620,14 +629,20 @@ export default function normalize( | |
const transform = oldOptions[key]; | ||
value = | ||
transform && | ||
Object.keys(transform).map(regex => [ | ||
regex, | ||
resolve(newOptions.resolver, { | ||
filePath: transform[regex], | ||
key, | ||
rootDir: options.rootDir, | ||
}), | ||
]); | ||
Object.keys(transform).map(regex => { | ||
const transformElement = transform[regex]; | ||
return [ | ||
regex, | ||
resolve(newOptions.resolver, { | ||
filePath: Array.isArray(transformElement) | ||
? transformElement[0] | ||
: transformElement, | ||
key, | ||
rootDir: options.rootDir, | ||
}), | ||
...(Array.isArray(transformElement) ? [transformElement[1]] : []), | ||
]; | ||
}); | ||
break; | ||
case 'coveragePathIgnorePatterns': | ||
case 'modulePathIgnorePatterns': | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we pay any perf penalty for making this an array of variable length (previously always a tuple, now an array of 2 or 3 items). It's accessed before every file transform, so definitely something worth double-checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be uniform in most cases that are using only one config file?