-
-
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
Conversation
|
||
### Defaults | ||
## Options | ||
|
||
You can retrieve Jest's default options to expand them if needed: | ||
|
||
```js title="jest.config.js" | ||
const {defaults} = require('jest-config'); |
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
and jestDefaults
from 'jest'
? Or better from 'jest-config'
? It is nice to install only jest
, in the other hand these are just devDependencies.
this allows to have typed config without having @types/jest installed? |
Hm.. Do you mean |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import jest from 'jest'; |
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.
Can’t figure out why, but import {defineConfig} from 'jest'
throws an error in ESM. import {defineConfig} from 'jest-config'
works as expected. Seems like they both export defineConfig
in the same way. Strange.
@SimenB @Smrtnyk What do you think? Somewhat cleaner way to have type definitions and autocompletion in config files. The difference I am trying to introduce here is the following – Current (JS with type hints and autocompletion, no type checks yet, but // jest.config.js
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
verbose: true,
};
module.exports = config; This branch: const {defineConfig} = require('jest');
module.exports = defineConfig({
verbose: true,
}); Current (TS with type checking through // jest.config.ts
import type {Config} from '@jest/types';
const config: Config.InitialOptions = {
verbose: true,
};
export default config; This branch (type checks still through import {defineConfig} from 'jest';
export default defineConfig({
verbose: true,
}); |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Idea borrowed from Vue ecosystem (at this is there I saw it): a
defineConfig()
helper function which helps with types and autocompletion in CJS, ESM or TS:It takes an object, or function, or async function:
Is this interesting and useful? Or sort of exotic and complicated?
Test plan
E2e and type tests added.