Skip to content

Commit e5c4502

Browse files
committed
Fix dependency clash test modified in jestjs#6104
1 parent 8a7b4a9 commit e5c4502

1 file changed

Lines changed: 37 additions & 28 deletions

File tree

e2e/__tests__/dependency_clash.test.js

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,61 @@ skipSuiteOnWindows();
2424

2525
// doing test in a temp directory because we don't want jest node_modules affect it
2626
const tempDir = path.resolve(os.tmpdir(), 'clashing-dependencies-test');
27-
const thirdPartyDir = path.resolve(tempDir, 'third-party');
27+
const hasteImplModulePath = path.resolve(
28+
'./packages/jest-haste-map/src/__tests__/haste_impl.js',
29+
);
2830

2931
beforeEach(() => {
3032
cleanup(tempDir);
3133
createEmptyPackage(tempDir);
32-
mkdirp(path.join(thirdPartyDir, 'node_modules'));
33-
linkJestPackage('babel-jest', thirdPartyDir);
3434
});
3535

3636
// This test case is checking that when having both
3737
// `invariant` package from npm and `invariant.js` that provides `invariant`
3838
// module we can still require the right invariant. This is pretty specific
3939
// use case and in the future we should probably delete this test.
4040
// see: https://github.com/facebook/jest/pull/6687
41-
test('fails with syntax error on flow types', () => {
42-
const babelFileThatRequiresInvariant = require.resolve(
43-
'babel-traverse/lib/path/index.js',
44-
);
45-
46-
expect(fs.existsSync(babelFileThatRequiresInvariant)).toBe(true);
47-
// make sure the babel depenency that depends on `invariant` from npm still
48-
// exists, otherwise the test will pass regardless of whether the bug still
49-
// exists or no.
50-
expect(fs.readFileSync(babelFileThatRequiresInvariant).toString()).toMatch(
51-
/invariant/,
52-
);
41+
test('does not require project modules from inside node_modules', () => {
5342
writeFiles(tempDir, {
54-
'.babelrc': `
55-
{
56-
"plugins": [
57-
"${require.resolve('babel-plugin-transform-flow-strip-types')}"
58-
]
59-
}
60-
`,
6143
'__tests__/test.js': `
62-
const invariant = require('../invariant');
44+
const invariant = require('invariant');
6345
test('haii', () => expect(invariant(false, 'haii')).toBe('haii'));
6446
`,
65-
'invariant.js': `/**
66-
* @flow
67-
*/
68-
const invariant = (condition: boolean, message: string) => message;
47+
'invariant.js': `
48+
INVALID CODE FRAGMENT THAT WILL BE REMOVED BY THE TRANSFORMER
49+
const invariant = (condition, message) => message;
6950
module.exports = invariant;
7051
`,
52+
'third-party/node_modules/invariant/index.js': `
53+
const invariant = (condition, message) => {
54+
if (!condition) {
55+
throw new Error(message);
56+
}
57+
};
58+
module.exports = invariant;
59+
`,
60+
'third-party/node_modules/transform/index.js': `
61+
const invariant = require('invariant');
62+
module.exports = {
63+
process: script => {
64+
let threw = false;
65+
try {
66+
invariant(false, 'this should throw');
67+
} catch (e) {
68+
threw = true;
69+
}
70+
if (!threw) {
71+
throw new Error('It used the wrong invariant module!');
72+
}
73+
return script.replace('INVALID CODE FRAGMENT THAT WILL BE REMOVED BY THE TRANSFORMER', '');
74+
},
75+
};
76+
`,
7177
'jest.config.js': `module.exports = {
72-
transform: {'.*\\.js': './third-party/node_modules/babel-jest'},
78+
haste: {
79+
hasteImplModulePath: '${hasteImplModulePath}',
80+
},
81+
transform: {'.*\\.js': './third-party/node_modules/transform'},
7382
};`,
7483
});
7584
const {stderr, status} = runJest(tempDir, ['--no-cache', '--no-watchman']);

0 commit comments

Comments
 (0)