/
jest.config.js.test.ts
68 lines (57 loc) · 2.15 KB
/
jest.config.js.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import * as path from 'path';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import runJest from '../runJest';
const DIR = path.resolve(__dirname, '../jest-config-js');
beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
test('works with jest.config.js', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': "test('banana', () => expect(1).toBe(1));",
'jest.config.js': "module.exports = {testRegex: '.*-banana.js'};",
'package.json': '{}',
});
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
const {rest, summary} = extractSummary(stderr);
expect(exitCode).toBe(0);
expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
});
test('traverses directory tree up until it finds jest.config', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
const slash = require('slash');
test('banana', () => expect(1).toBe(1));
test('abc', () => console.log(slash(process.cwd())));
`,
'jest.config.js': "module.exports = {testRegex: '.*-banana.js'};",
'package.json': '{}',
'some/nested/directory/file.js': '// nothing special',
});
const {stderr, exitCode, stdout} = runJest(
path.join(DIR, 'some', 'nested', 'directory'),
['-w=1', '--ci=false'],
{skipPkgJsonCheck: true},
);
// Snapshot the console.loged `process.cwd()` and make sure it stays the same
expect(stdout.replace(/^\W+(.*)e2e/gm, '<<REPLACED>>')).toMatchSnapshot();
const {rest, summary} = extractSummary(stderr);
expect(exitCode).toBe(0);
expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
});
test('invalid JS in jest.config.js', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': "test('banana', () => expect(1).toBe(1));",
'jest.config.js': "module.exports = i'll break this file yo",
'package.json': '{}',
});
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
expect(stderr).toMatch('SyntaxError: ');
expect(exitCode).toBe(1);
});