Skip to content

Commit a782ce5

Browse files
Alcedo Nathaniel De Guzman JrSimenB
authored andcommitted
Migrate e2e tests to TypeScript (#7990)
1 parent 12542a2 commit a782ce5

193 files changed

Lines changed: 195 additions & 368 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = {
7171
},
7272
{
7373
files: [
74-
'e2e/__tests__/**/*',
74+
'e2e/__tests__/**/*.js',
7575
'packages/babel-jest/**/*.test.js',
7676
'packages/babel-plugin-jest-hoist/**/*.test.js',
7777
'packages/babel-preset-jest/**/*.test.js',

e2e/MockStdinWatchPlugin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ class MockStdinWatchPlugin {
2424
});
2525
}
2626
}
27+
28+
/**
29+
* Watch plugins are not transpiled hence why we're leaving
30+
* this file out of typescript migration
31+
*/
2732
module.exports = MockStdinWatchPlugin;

e2e/Utils.js renamed to e2e/Utils.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
87
*/
98

10-
'use strict';
11-
12-
import type {Path} from 'types/Config';
13-
14-
import {sync as spawnSync} from 'execa';
159
import fs from 'fs';
1610
import path from 'path';
11+
import {Config} from '@jest/types';
12+
13+
import {sync as spawnSync, ExecaReturns} from 'execa';
1714
import {createDirectory} from 'jest-util';
1815
import rimraf from 'rimraf';
1916

20-
export const run = (cmd: string, cwd?: Path) => {
17+
export type RunResult = ExecaReturns & {
18+
status: number;
19+
error: Error;
20+
};
21+
export const run = (cmd: string, cwd?: Config.Path): RunResult => {
2122
const args = cmd.split(/\s/).slice(1);
2223
const spawnOptions = {cwd, reject: false};
23-
const result = spawnSync(cmd.split(/\s/)[0], args, spawnOptions);
24+
const result = spawnSync(cmd.split(/\s/)[0], args, spawnOptions) as RunResult;
2425

2526
// For compat with cross-spawn
2627
result.status = result.code;
@@ -39,7 +40,7 @@ export const run = (cmd: string, cwd?: Path) => {
3940
return result;
4041
};
4142

42-
export const linkJestPackage = (packageName: string, cwd: Path) => {
43+
export const linkJestPackage = (packageName: string, cwd: Config.Path) => {
4344
const packagesDir = path.resolve(__dirname, '../packages');
4445
const packagePath = path.resolve(packagesDir, packageName);
4546
const destination = path.resolve(cwd, 'node_modules/', packageName);
@@ -50,8 +51,8 @@ export const linkJestPackage = (packageName: string, cwd: Path) => {
5051

5152
export const makeTemplate = (
5253
str: string,
53-
): ((values?: Array<any>) => string) => (values: ?Array<any>) =>
54-
str.replace(/\$(\d+)/g, (match, number) => {
54+
): ((values?: Array<any>) => string) => (values?: Array<any>) =>
55+
str.replace(/\$(\d+)/g, (_match, number) => {
5556
if (!Array.isArray(values)) {
5657
throw new Error('Array of values must be passed to the template.');
5758
}
@@ -76,14 +77,13 @@ export const writeFiles = (
7677
) => {
7778
createDirectory(directory);
7879
Object.keys(files).forEach(fileOrPath => {
79-
const filePath = fileOrPath.split('/'); // ['tmp', 'a.js']
80-
const filename = filePath.pop(); // filepath becomes dirPath (no filename)
80+
const dirname = path.dirname(fileOrPath);
8181

82-
if (filePath.length) {
83-
createDirectory(path.join.apply(path, [directory].concat(filePath)));
82+
if (dirname !== '/') {
83+
createDirectory(path.join(directory, dirname));
8484
}
8585
fs.writeFileSync(
86-
path.resolve.apply(path, [directory].concat(filePath, [filename])),
86+
path.resolve(directory, ...fileOrPath.split('/')),
8787
files[fileOrPath],
8888
);
8989
});
@@ -118,7 +118,7 @@ export const sortLines = (output: string) =>
118118
.join('\n');
119119

120120
export const createEmptyPackage = (
121-
directory: Path,
121+
directory: Config.Path,
122122
packageJson?: {[keys: string]: any},
123123
) => {
124124
const DEFAULT_PACKAGE_JSON = {
@@ -168,7 +168,7 @@ export const extractSummary = (stdout: string) => {
168168
const sortTests = (stdout: string) =>
169169
stdout
170170
.split('\n')
171-
.reduce((tests, line, i) => {
171+
.reduce((tests: Array<Array<string>>, line) => {
172172
if (['RUNS', 'PASS', 'FAIL'].includes(line.slice(0, 4))) {
173173
tests.push([line.trimRight()]);
174174
} else if (line) {
@@ -194,11 +194,11 @@ export const extractSortedSummary = (stdout: string) => {
194194

195195
export const extractSummaries = (
196196
stdout: string,
197-
): Array<{rest: string, summary: string}> => {
197+
): Array<{rest: string; summary: string}> => {
198198
const regex = /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm;
199199

200200
let match = regex.exec(stdout);
201-
const matches = [];
201+
const matches: Array<RegExpExecArray> = [];
202202

203203
while (match) {
204204
matches.push(match);
File renamed without changes.
File renamed without changes.

e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.js.snap renamed to e2e/__tests__/__snapshots__/cliHandlesExactFilenames.test.ts.snap

File renamed without changes.
File renamed without changes.

e2e/__tests__/__snapshots__/consoleAfterTeardown.test.js.snap renamed to e2e/__tests__/__snapshots__/consoleAfterTeardown.test.ts.snap

File renamed without changes.

e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.js.snap renamed to e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap

File renamed without changes.

e2e/__tests__/__snapshots__/coverageRemapping.test.js.snap renamed to e2e/__tests__/__snapshots__/coverageRemapping.test.ts.snap

File renamed without changes.

0 commit comments

Comments
 (0)