Fix for the jest.config.ts compiler to not interfere with tsconfig.json files#10675
Conversation
jest.config.ts compiler to not interfere with tsconfig.json filejest.config.ts compiler to not interfere with tsconfig.json files
SimenB
left a comment
There was a problem hiding this comment.
thanks!
I just noticed const DIR = path.resolve(__dirname, '../jest.config.ts'); - can you rename this to look like a directory instead of looking like a file? just
- const DIR = path.resolve(__dirname, '../jest.config.ts');
+ const DIR = path.resolve(__dirname, '../jest-config-ts');or something.
Possibly stick it in tmp as well?
| import {cleanup, extractSummary, writeFiles} from '../Utils'; | ||
|
|
||
| const DIR = path.resolve(__dirname, '../jest.config.js'); | ||
| const DIR = path.resolve(__dirname, '../tmp/jest-config-js'); |
There was a problem hiding this comment.
I meant
import {tmpdir} from 'os';`
😅
There was a problem hiding this comment.
@SimenB If I move it to tmp the traverses directory tree up until it finds jest.config test will fail because it can't find the slash package.
There was a problem hiding this comment.
we should install slash in it, then. We have a runYarn helper already - I don't think it takes args, but that should be a simple refactor.
We can do it later, though 🙂
There was a problem hiding this comment.
Ah nice, runYarn is exactly what I was looking for
There was a problem hiding this comment.
@SimenB I've reverted the change with the tmp bacause I couldn't make runYarn to install the slash package. I even tried run('yarn install', DIR) with same module does not exist error.
As you said, we can do it later so we don't need to delay this fix.
Full example:
test('traverses directory tree up until it finds jest.config', () => {
writeFiles(DIR, {
'__tests__/a-giraffe.js': `
const slash = require('slash');
test('giraffe', () => expect(1).toBe(1));
test('abc', () => console.log(slash(process.cwd())));
`,
'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
'package.json': '{ "devDependencies": { "slash": "^3.0.0" } }',
'some/nested/directory/file.js': '// nothing special',
});
// 1st try with small local refactoring to allow args
runYarn(DIR, undefined, ['install']);
// 2nd try
run('yarn install', DIR);
const {stderr, exitCode, stdout} = runJest(
path.join(DIR, 'some', 'nested', 'directory'),
['-w=1', '--ci=false'],
{skipPkgJsonCheck: true},
);
// expects...
});
|
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
This PR resolves #10652.
The bug occurs when the consumer have a
tsconfig.jsonfile in the project defining themoduleconfiguration. In this case the internal compiler which takes care of processing thejest.config.tsautomatically detect that. With this PR, I've added explicit definition on whatmodulewe want to use for output.CHANGELOG.mdfile was updated to reflect these changes.