Skip to content

Commit

Permalink
Fixed some integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rubennorte committed May 2, 2018
1 parent e7b32f6 commit 5c45921
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 23 deletions.
64 changes: 43 additions & 21 deletions integration-tests/__tests__/multi_project_runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ const DIR = path.resolve(os.tmpdir(), 'multi_project_runner_test');

SkipOnWindows.suite();

const fileContentWithProvidesModule = name => `/*
* @providesModule ${name}
*/
module.exports = {};
`;
const SAMPLE_FILE_CONTENT = 'module.exports = {};';

beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));
Expand Down Expand Up @@ -58,29 +53,51 @@ test('--listTests doesnt duplicate the test files', () => {
test('can pass projects or global config', () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'base_config.js': `
module.exports = {
haste: {
hasteImplModulePath: '<rootDir>/hasteImpl.js',
},
};
`,
'hasteImpl.js': `
module.exports = {
getHasteName(path) {
return path
.substr(path.lastIndexOf('/') + 1)
.replace(/\.js$/, '');
},
};
`,
'package.json': '{}',
'project1/__tests__/file1.test.js': `
const file1 = require('file1');
test('file1', () => {});
`,
'project1/file1.js': fileContentWithProvidesModule('file1'),
'project1/jest.config.js': `module.exports = {rootDir: './', displayName: 'BACKEND'}`,
'project1/file1.js': SAMPLE_FILE_CONTENT,
'project1/jest.config.js': `module.exports = {rootDir: './', displayName: 'BACKEND', haste: {
hasteImplModulePath: '<rootDir>/../hasteImpl.js',
},}`,
'project2/__tests__/file1.test.js': `
const file1 = require('file1');
test('file1', () => {});
`,
'project2/file1.js': fileContentWithProvidesModule('file1'),
'project2/jest.config.js': `module.exports = {rootDir: './'}`,
'project2/file1.js': SAMPLE_FILE_CONTENT,
'project2/jest.config.js': `module.exports = {rootDir: './', haste: {
hasteImplModulePath: '<rootDir>/../hasteImpl.js',
},}`,
'project3/__tests__/file1.test.js': `
const file1 = require('file1');
test('file1', () => {});
`,
'project3/file1.js': fileContentWithProvidesModule('file1'),
'project3/jest.config.js': `module.exports = {rootDir: './', displayName: 'UI'}`,
'project3/file1.js': SAMPLE_FILE_CONTENT,
'project3/jest.config.js': `module.exports = {rootDir: './', displayName: 'UI', haste: {
hasteImplModulePath: '<rootDir>/../hasteImpl.js',
},}`,
});
let stderr;

({stderr} = runJest(DIR, ['--no-watchman']));
({stderr} = runJest(DIR, ['--no-watchman', '--config', 'base_config.js']));
expect(stderr).toMatch(
'The name `file1` was looked up in the Haste module map. It cannot be resolved, because there exists several different files',
);
Expand All @@ -91,6 +108,9 @@ test('can pass projects or global config', () => {
'global_config.js': `
module.exports = {
projects: ['project1/', 'project2/', 'project3/'],
haste: {
hasteImplModulePath: '<rootDir>/hasteImpl.js',
},
};
`,
});
Expand All @@ -102,6 +122,8 @@ test('can pass projects or global config', () => {
'project1',
'project2',
'project3',
'--config',
'base_config.js',
]));

const result1 = extractSummary(stderr);
Expand Down Expand Up @@ -129,16 +151,16 @@ test('"No tests found" message for projects', () => {
'.watchmanconfig': '',
'package.json': '{}',
'project1/__tests__/file1.test.js': `
const file1 = require('file1');
const file1 = require('../file1');
test('file1', () => {});
`,
'project1/file1.js': fileContentWithProvidesModule('file1'),
'project1/file1.js': SAMPLE_FILE_CONTENT,
'project1/jest.config.js': `module.exports = {rootDir: './'}`,
'project2/__tests__/file1.test.js': `
const file1 = require('file1');
const file1 = require('../file1');
test('file1', () => {});
`,
'project2/file1.js': fileContentWithProvidesModule('file1'),
'project2/file1.js': SAMPLE_FILE_CONTENT,
'project2/jest.config.js': `module.exports = {rootDir: './'}`,
});
const {stdout: verboseOutput} = runJest(DIR, [
Expand Down Expand Up @@ -173,16 +195,16 @@ test('projects can be workspaces with non-JS/JSON files', () => {
'packages/README.md': '# Packages README',
'packages/project1/README.md': '# Project1 README',
'packages/project1/__tests__/file1.test.js': `
const file1 = require('file1');
const file1 = require('../file1');
test('file1', () => {});
`,
'packages/project1/file1.js': fileContentWithProvidesModule('file1'),
'packages/project1/file1.js': SAMPLE_FILE_CONTENT,
'packages/project1/package.json': '{}',
'packages/project2/__tests__/file2.test.js': `
const file2 = require('file2');
const file2 = require('../file2');
test('file2', () => {});
`,
'packages/project2/file2.js': fileContentWithProvidesModule('file2'),
'packages/project2/file2.js': SAMPLE_FILE_CONTENT,
'packages/project2/package.json': '{}',
});

Expand Down
13 changes: 13 additions & 0 deletions packages/jest-cli/src/__tests__/search_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ jest.setTimeout(15000);

const SkipOnWindows = require('../../../../scripts/SkipOnWindows');

const hasteImplModulePath = path.join(
__dirname,
'..',
'..',
'..',
'jest-haste-map',
'src',
'__tests__',
'haste_impl',
);
const rootDir = path.resolve(__dirname, 'test_root');
const testRegex = path.sep + '__testtests__' + path.sep;
const testMatch = ['**/__testtests__/**/*'];
Expand Down Expand Up @@ -377,6 +387,9 @@ describe('SearchSource', () => {
{
name: 'SearchSource-findRelatedTests-tests',
rootDir,
haste: {
hasteImplModulePath,
},
},
{},
);
Expand Down
9 changes: 7 additions & 2 deletions packages/jest-haste-map/src/__tests__/haste_impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

module.exports = {
getHasteName(path) {
if (path.includes('__mocks__') || path.includes('NoHaste')) {
if (
path.includes('__mocks__') ||
path.includes('NoHaste') ||
path.includes('/module_dir/') ||
path.includes('/sourcemaps/')
) {
return undefined;
}

return path
.substr(path.lastIndexOf('/') + 1)
.replace(/(\.(android|ios))?\.js$/, '');
.replace(/(\.(android|ios|native))?\.js$/, '');
},
};
12 changes: 12 additions & 0 deletions packages/jest-runtime/src/__mocks__/createRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ module.exports = function createRuntime(filename, config) {
{
name: 'Runtime-' + filename.replace(/\W/, '-') + '.tests',
rootDir: path.resolve(path.dirname(filename), 'test_root'),
haste: {
hasteImplModulePath: path.resolve(
__dirname,
'..',
'..',
'..',
'jest-haste-map',
'src',
'__tests__',
'haste_impl.js',
),
},
},
config,
),
Expand Down

0 comments on commit 5c45921

Please sign in to comment.