Skip to content

Commit

Permalink
chore: get rid of custom abstraction on top of execa in e2e tests (#8901
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SimenB authored Sep 2, 2019
1 parent 5545730 commit c588c18
Show file tree
Hide file tree
Showing 96 changed files with 535 additions and 548 deletions.
2 changes: 1 addition & 1 deletion e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const NUMBER_OF_TESTS_TO_FORCE_USING_WORKERS = 25;
* Slow and modifies the test output. Use sparingly.
*/
export const generateTestFilesToForceUsingWorkers = () => {
const testFiles = {};
const testFiles: Record<string, string> = {};
for (let i = 0; i <= NUMBER_OF_TESTS_TO_FORCE_USING_WORKERS; i++) {
testFiles[`__tests__/test${i}.test.js`] = `
test.todo('test ${i}');
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/autoClearMocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import runJest from '../runJest';

test('suite with auto-clear', () => {
const result = runJest('auto-clear-mocks/with-auto-clear');
expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);
});

test('suite without auto-clear', () => {
const result = runJest('auto-clear-mocks/without-auto-clear');
expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);
});
4 changes: 2 additions & 2 deletions e2e/__tests__/autoResetMocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import runJest from '../runJest';

test('suite with auto-reset', () => {
const result = runJest('auto-reset-mocks/with-auto-reset');
expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);
});

test('suite without auto-reset', () => {
const result = runJest('auto-reset-mocks/without-auto-reset');
expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);
});
4 changes: 2 additions & 2 deletions e2e/__tests__/autoRestoreMocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import runJest from '../runJest';

test('suite with auto-restore', () => {
const result = runJest('auto-restore-mocks/with-auto-restore');
expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);
});

test('suite without auto-restore', () => {
const result = runJest('auto-restore-mocks/without-auto-restore');
expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);
});
10 changes: 5 additions & 5 deletions e2e/__tests__/clearCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ const CACHE = path.resolve(tmpdir(), 'clear-cache-directory');

describe('jest --clearCache', () => {
test('normal run results in cache directory being written', () => {
const {status} = runJest('clear-cache', [`--cacheDirectory=${CACHE}`]);
const {exitCode} = runJest('clear-cache', [`--cacheDirectory=${CACHE}`]);

expect(fs.existsSync(CACHE)).toBe(true);
expect(status).toBe(0);
expect(exitCode).toBe(0);
});
test('clearCache results in deleted directory and exit status 0', () => {
test('clearCache results in deleted directory and exitCode 0', () => {
expect(fs.existsSync(CACHE)).toBe(true);

const {status, stdout, stderr} = runJest('clear-cache', [
const {exitCode, stdout, stderr} = runJest('clear-cache', [
'--clearCache',
`--cacheDirectory=${CACHE}`,
]);

expect(fs.existsSync(CACHE)).toBe(false);
expect(stdout).toBe(`Cleared ${CACHE}`);
expect(stderr).toBe('');
expect(status).toBe(0);
expect(exitCode).toBe(0);
});
});
4 changes: 2 additions & 2 deletions e2e/__tests__/cliHandlesExactFilenames.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('CLI accepts exact file names if matchers matched', () => {

const result = runJest(DIR, ['-i', '--forceExit', './foo/bar.spec.js']);

expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);

const {rest, summary} = extractSummary(result.stderr);

Expand All @@ -47,7 +47,7 @@ test('CLI skips exact file names if no matchers matched', () => {

const result = runJest(DIR, ['-i', '--forceExit', './foo/bar.js']);

expect(result.status).toBe(1);
expect(result.exitCode).toBe(1);
expect(result.stdout).toMatch(/No tests found([\S\s]*)2 files checked./);
expect(result.stderr).toEqual('');
});
6 changes: 3 additions & 3 deletions e2e/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('config as JSON', () => {
}),
]);

expect(result.status).toBe(1);
expect(result.exitCode).toBe(1);
expect(result.stdout).toMatch('No tests found');
});

Expand All @@ -28,7 +28,7 @@ test('works with sane config JSON', () => {
}),
]);

expect(result.status).toBe(1);
expect(result.exitCode).toBe(1);
expect(result.stderr).toMatch('works just fine');
});

Expand Down Expand Up @@ -65,6 +65,6 @@ test('works with jsdom testEnvironmentOptions config JSON', () => {
}),
]);

expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);
expect(result.stderr).toContain('found url jestjs.io');
});
20 changes: 10 additions & 10 deletions e2e/__tests__/console.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ import {extractSummary, run} from '../Utils';
import runJest from '../runJest';

test('console printing', () => {
const {stderr, status} = runJest('console');
const {stderr, exitCode} = runJest('console');
const {summary, rest} = extractSummary(stderr);

expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
});

test('console printing with --verbose', () => {
const {stderr, stdout, status} = runJest('console', [
const {stderr, stdout, exitCode} = runJest('console', [
'--verbose',
'--no-cache',
]);
const {summary, rest} = extractSummary(stderr);

expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(wrap(stdout)).toMatchSnapshot();
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
});

test('does not print to console with --silent', () => {
const {stderr, stdout, status} = runJest('console', [
const {stderr, stdout, exitCode} = runJest('console', [
// Need to pass --config because console test specifies `verbose: false`
'--config=' +
JSON.stringify({
Expand All @@ -44,18 +44,18 @@ test('does not print to console with --silent', () => {
]);
const {summary, rest} = extractSummary(stderr);

expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(wrap(stdout)).toMatchSnapshot();
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
});

// issue: https://github.com/facebook/jest/issues/5223
test('the jsdom console is the same as the test console', () => {
const {stderr, stdout, status} = runJest('console-jsdom');
const {stderr, stdout, exitCode} = runJest('console-jsdom');
const {summary, rest} = extractSummary(stderr);

expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(wrap(stdout)).toMatchSnapshot();
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
Expand All @@ -64,10 +64,10 @@ test('the jsdom console is the same as the test console', () => {
test('does not error out when using winston', () => {
const dir = path.resolve(__dirname, '../console-winston');
run('yarn', dir);
const {stderr, stdout, status} = runJest(dir);
const {stderr, stdout, exitCode} = runJest(dir);
const {summary, rest} = extractSummary(stderr);

expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(wrap(stdout)).toMatchSnapshot();
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/consoleAfterTeardown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {extractSummary} from '../Utils';
import runJest from '../runJest';

test('console printing', () => {
const {stderr, status} = runJest('console-after-teardown');
const {stderr, exitCode} = runJest('console-after-teardown');
const {rest} = extractSummary(stderr);

expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(wrap(rest)).toMatchSnapshot();
});
4 changes: 2 additions & 2 deletions e2e/__tests__/consoleLogOutputWhenRunInBand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ test('prints console.logs when run with forceExit', () => {
'package.json': '{}',
});

const {stderr, stdout, status} = runJest(DIR, [
const {stderr, stdout, exitCode} = runJest(DIR, [
'-i',
'--ci=false',
'--forceExit',
]);
const {rest, summary} = extractSummary(stderr);
expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
expect(wrap(stdout)).toMatchSnapshot();
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageRemapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ it('maps code coverage against original source', () => {
run('yarn', dir);
const result = runJest(dir, ['--coverage', '--no-cache']);

expect(result.status).toBe(0);
expect(result.exitCode).toBe(0);

const coverageMapFile = path.join(coverageDir, 'coverage-final.json');
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
Expand Down
38 changes: 19 additions & 19 deletions e2e/__tests__/coverageReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ beforeAll(() => {
});

test('outputs coverage report', () => {
const {stdout, status} = runJest(DIR, ['--no-cache', '--coverage'], {
const {stdout, exitCode} = runJest(DIR, ['--no-cache', '--coverage'], {
stripAnsi: true,
});
const coverageDir = path.join(DIR, 'coverage');
Expand All @@ -31,7 +31,7 @@ test('outputs coverage report', () => {
expect(wrap(stdout)).toMatchSnapshot();

expect(() => fs.accessSync(coverageDir, fs.F_OK)).not.toThrow();
expect(status).toBe(0);
expect(exitCode).toBe(0);
});

test('collects coverage only from specified file', () => {
Expand Down Expand Up @@ -86,26 +86,26 @@ test('collects coverage only from specified files avoiding dependencies', () =>
});

test('json reporter printing with --coverage', () => {
const {stderr, status} = runJest('json-reporter', ['--coverage'], {
const {stderr, exitCode} = runJest('json-reporter', ['--coverage'], {
stripAnsi: true,
});
const {summary} = extractSummary(stderr);
expect(status).toBe(1);
expect(exitCode).toBe(1);
expect(wrap(summary)).toMatchSnapshot();
});

test('outputs coverage report as json', () => {
const {stdout, status} = runJest(
const {stdout, exitCode} = runJest(
DIR,
['--no-cache', '--coverage', '--json'],
{stripAnsi: true},
);
expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(() => JSON.parse(stdout)).not.toThrow();
});

test('outputs coverage report when text is requested', () => {
const {stdout, status} = runJest(
const {stdout, exitCode} = runJest(
DIR,
[
'--no-cache',
Expand All @@ -115,24 +115,24 @@ test('outputs coverage report when text is requested', () => {
],
{stripAnsi: true},
);
expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(stdout).toMatch(/Stmts | . Branch/);
expect(wrap(stdout)).toMatchSnapshot();
});

test('outputs coverage report when text-summary is requested', () => {
const {stdout, status} = runJest(
const {stdout, exitCode} = runJest(
DIR,
['--no-cache', '--coverage', '--coverageReporters=text-summary'],
{stripAnsi: true},
);
expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(stdout).toMatch(/Coverage summary/);
expect(wrap(stdout)).toMatchSnapshot();
});

test('outputs coverage report when text and text-summary is requested', () => {
const {stdout, status} = runJest(
const {stdout, exitCode} = runJest(
DIR,
[
'--no-cache',
Expand All @@ -142,27 +142,27 @@ test('outputs coverage report when text and text-summary is requested', () => {
],
{stripAnsi: true},
);
expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(stdout).toMatch(/Stmts | . Branch/);
expect(stdout).toMatch(/Coverage summary/);
expect(wrap(stdout)).toMatchSnapshot();
});

test('does not output coverage report when html is requested', () => {
const {stdout, status} = runJest(
const {stdout, exitCode} = runJest(
DIR,
['--no-cache', '--coverage', '--coverageReporters=html'],
{stripAnsi: true},
);
expect(status).toBe(0);
expect(exitCode).toBe(0);
expect(stdout).toMatch(/^$/);
expect(wrap(stdout)).toMatchSnapshot();
});

test('collects coverage from duplicate files avoiding shared cache', () => {
const args = [
'--coverage',
// Ensure the status code is non-zero if super edge case with coverage triggers
// Ensure the exitCode is non-zero if super edge case with coverage triggers
'--coverageThreshold',
'{"global": {"lines": 100}}',
'--collectCoverageOnlyFrom',
Expand All @@ -176,17 +176,17 @@ test('collects coverage from duplicate files avoiding shared cache', () => {
runJest(DIR, args, {stripAnsi: true});

// Run for the second time
const {stdout, status} = runJest(DIR, args, {stripAnsi: true});
const {stdout, exitCode} = runJest(DIR, args, {stripAnsi: true});
expect(wrap(stdout)).toMatchSnapshot();
expect(status).toBe(0);
expect(exitCode).toBe(0);
});

test('generates coverage when using the testRegex config param ', () => {
const {stdout, status} = runJest(DIR, [
const {stdout, exitCode} = runJest(DIR, [
'--no-cache',
'--testRegex=__tests__',
'--coverage',
]);
expect(wrap(stdout)).toMatchSnapshot();
expect(status).toBe(0);
expect(exitCode).toBe(0);
});
Loading

0 comments on commit c588c18

Please sign in to comment.