-
-
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
feat(jest, jest-config): add defineConfig()
helper
#12801
Closed
Closed
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
10a6d6d
feat(jest, jest-config): add defineConfig helper
mrazauskas b3c5a00
skip TS test
mrazauskas 1172f37
without await
mrazauskas 0c0a126
revert configs
mrazauskas ce01e6b
TS test
mrazauskas a52e895
docs
mrazauskas d454204
add changelog entry
mrazauskas 0d71c9a
add ts-node
mrazauskas 8fa0faf
runYarnInstall
mrazauskas 93898c6
getConfig
mrazauskas d1ec09c
babel
mrazauskas 3de7e41
no babel ;D
mrazauskas 02e915a
ups.. runYarnInstall
mrazauskas f294b32
from 'jest-config'
mrazauskas e2dae80
build types
mrazauskas 1431f98
build jest-config types
mrazauskas 0c4a07f
skip TS test - it is too slow
mrazauskas 89a539a
revert gitignore
mrazauskas 5fab7f2
rebase
mrazauskas 8c066bd
fix lock
mrazauskas e0517b0
better tests
mrazauskas 0ca215a
snaps
mrazauskas aafcf44
Revert "snaps"
mrazauskas cfe75a5
roots
mrazauskas f6de5fe
rebase
mrazauskas 875f80d
clean up
mrazauskas 16f18e7
cleaner
mrazauskas e3b37cb
add ts integration tests
mrazauskas bd39c1c
rework tests
mrazauskas 63c9626
clean up
mrazauskas 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* 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 {onNodeVersions} from '@jest/test-utils'; | ||
import {getConfig} from '../runJest'; | ||
|
||
const DIR = path.resolve(__dirname, '../define-config'); | ||
|
||
test('works with object config exported from CJS file', () => { | ||
const {configs, globalConfig} = getConfig(path.join(DIR, 'cjs-object')); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName?.name).toBe('cjs-object-config'); | ||
expect(globalConfig.verbose).toBe(true); | ||
}); | ||
|
||
test('works with function config exported from CJS file', () => { | ||
const {configs, globalConfig} = getConfig(path.join(DIR, 'cjs-function')); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName?.name).toBe('cjs-async-function-config'); | ||
expect(globalConfig.verbose).toBe(true); | ||
}); | ||
|
||
// The versions where vm.Module exists and commonjs with "exports" is not broken | ||
onNodeVersions('>=12.16.0', () => { | ||
test('works with object config exported from ESM file', () => { | ||
const {configs, globalConfig} = getConfig(path.join(DIR, 'esm-object')); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName?.name).toBe('esm-object-config'); | ||
expect(globalConfig.verbose).toBe(true); | ||
}); | ||
|
||
test('works with function config exported from ESM file', () => { | ||
const {configs, globalConfig} = getConfig(path.join(DIR, 'esm-function')); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName?.name).toBe('esm-async-function-config'); | ||
expect(globalConfig.verbose).toBe(true); | ||
}); | ||
}); |
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,55 @@ | ||
/** | ||
* 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 {onNodeVersions} from '@jest/test-utils'; | ||
import {getConfig} from '../runJest'; | ||
|
||
const DIR = path.resolve(__dirname, '../ts-node'); | ||
|
||
test('works with object config exported from TS file', () => { | ||
const {configs, globalConfig} = getConfig( | ||
path.join(DIR, 'defineConfig-object'), | ||
); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName?.name).toBe('ts-object-config'); | ||
expect(globalConfig.verbose).toBe(true); | ||
}); | ||
|
||
test('works with function config exported from TS file', () => { | ||
const {configs, globalConfig} = getConfig( | ||
path.join(DIR, 'defineConfig-function'), | ||
); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName?.name).toBe('ts-async-function-config'); | ||
expect(globalConfig.verbose).toBe(true); | ||
}); | ||
|
||
// The versions where vm.Module exists and commonjs with "exports" is not broken | ||
onNodeVersions('>=12.16.0', () => { | ||
test('works with object config exported from TS file when package.json#type=module', () => { | ||
const {configs, globalConfig} = getConfig( | ||
path.join(DIR, 'defineConfig-esm-object'), | ||
); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName?.name).toBe('ts-object-config'); | ||
expect(globalConfig.verbose).toBe(true); | ||
}); | ||
|
||
test('works with function config exported from TS file when package.json#type=module', () => { | ||
const {configs, globalConfig} = getConfig( | ||
path.join(DIR, 'defineConfig-esm-function'), | ||
); | ||
|
||
expect(configs).toHaveLength(1); | ||
expect(configs[0].displayName?.name).toBe('ts-async-function-config'); | ||
expect(globalConfig.verbose).toBe(true); | ||
}); | ||
}); |
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,10 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
test('dummy', () => { | ||
expect('true').toBeTruthy(); | ||
}); |
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,21 @@ | ||
/** | ||
* 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 {defineConfig} = require('jest'); | ||
|
||
async function getVerbose() { | ||
return true; | ||
} | ||
|
||
module.exports = defineConfig(async () => { | ||
const verbose = await getVerbose(); | ||
|
||
return { | ||
displayName: 'cjs-async-function-config', | ||
verbose, | ||
}; | ||
}); |
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,3 @@ | ||
{ | ||
"name": "define-config-cjs-function" | ||
} |
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,10 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
test('dummy', () => { | ||
expect('true').toBeTruthy(); | ||
}); |
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.
Still thinking. Perhaps it would be better to expose
defineJestConfig()
,JestConfig
andjestDefaults
from'jest'
? Or better from'jest-config'
? It is nice to install onlyjest
, in the other hand these are just devDependencies.