-
Notifications
You must be signed in to change notification settings - Fork 507
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] Add an option to save the generated jest.config.js #270
Comments
I was just thinking further. Why not just generate a jest.config.js when creating the project? Is there a good reason why |
@lookfirst I totally agree. I'm working in WebStorm and it has good integration with Jest but it will only work with I ended up creating const {createJestConfig} = require('tsdx/dist/createJestConfig');
const {paths} = require('tsdx/dist/constants');
process.env.BABEL_ENV = 'test';
process.env.NODE_ENV = 'test';
module.exports = createJestConfig(undefined, paths.appRoot); It works although it's far from ideal solution as It would be awesome to add similar functionality to |
Sorry to be an ass and not share... here is what I'm using... jest.config.js: module.exports = {
transform: {
'.(ts|tsx)': 'ts-jest'
},
transformIgnorePatterns: [ '[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$' ],
moduleFileExtensions: [ 'ts', 'tsx', 'js', 'jsx', 'json', 'node' ],
collectCoverageFrom: [ 'src/**/*.{ts,tsx}' ],
testMatch: [ '<rootDir>/**/*.(spec|test).{ts,tsx}' ],
rootDir: '.',
setupFilesAfterEnv: ['./jest.setup.js'],
}; jest.setup.js: global.window = {};
window.scroll = function () {
};
window.__DEV__ = true;
// even with latest react, still running into this on a couple of tests where i could not wrap
// things into an async act. maybe some day this will get fixed, but right now it is just an
// annoying useless warning.
const consoleError = console.error;
beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation((...args) => {
if (!args[0].includes('Warning: An update to %s inside a test was not wrapped in act')) {
consoleError(...args);
}
});
}); |
Yes, tsdx test makes sense so we can |
That answer doesn't make much sense to me because:
|
This comment has been minimized.
This comment has been minimized.
I think a TSDX Jest preset would be helpful (so would an ESLint one and a Babel one) as all these integrations then become one-liners. Something I previously mentioned in #389 (comment) |
@lookfirst it's not a premature operation, that's the sole existence of this platform... Remove configuration and allow for a simpler dependency upgrade strategy a lá I'm interested in that as well, but it's important to acknowledge were going against the grain of his goal. I think @agilgur5's idea for presets is stellar. Maintain what currently occurs, but maybe allow for a way to make the config files for each tool with the preset defined. |
@kylemh I said optimization and so far, |
It removes a large portion of what I would need to define in my Jest config |
... and in my case the command does nothing productive, because I use an IDE that needs the file. The whole point of this issue is to allow the file to be generated automatically. If the file is generated automatically, you don't need the command. 🥇 Large is relative... my file is just a few simple lines. |
If the file is generated automatically, there’s no way to support backwards compatibility for future changes to the Jest config from within TSDX. Again, I’m not disagreeing saying we don’t need a way to help you out, but the solution you’re offering of just exporting the config file by default is a bad idea for most users who aren’t editing the config and don’t use a JetBrains editor, because it ruins the ability for the team to adjust the config and ship the update as a non-breaking change. |
There is always a way, it is code, not rocket science. Updating the file is exporting it again and merging the diff. That is what revision control is for. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
And the test experience is being improved by me and other contributors. The config is currently small, but issues like not using the same Babel config for tests (#383), monorepo support (#122 and some others), auto-mocking assets (#414), etc, etc, are certain to make it larger over time. And bugfixes in To get into some specifics:
Having to manually update is a poor experience. Especially when you use TSDX in multiple libraries, that gets frustrating fast. That's similar to a breaking change. TSDX users shouldn't have to do that.
I think if we use a preset or other method that allows you to do something like |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This is getting too heated folks. |
|
Copying from something Jared said in #118 almost a year ago:
So some of the requirements are currently:
Just listing all those so everyone knows the status; that's why there's a hold-up on this, sorry about that 😓 In the meantime, I did get |
I want to be able to run jest tests from within my IDE (IDEA). It is far easier to just run jest directly than through
tsdx test
.What I did was hacked a
console.log()
intonode_modules/tsdx/lib/index.js
, output the generated jest config and saved that in a jest.config.js file. Had to edit it a bit to remove the absolute paths (🤷♂ why those are there), but it works perfectly.So, it would be nice to have something like the eslintconfig save option, but for the jest config.
The text was updated successfully, but these errors were encountered: