-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Migrate e2e tests to TypeScript #7990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
049de0b
aa2e4d5
5346d00
0aac8b4
51d1673
c96d455
a034827
85b6196
9f566c5
6d3ff78
151f7f2
1384aef
38a8529
ec02d6a
644f5d4
4bc74f7
49623c3
fa0893d
3d8dc7a
c6dce70
2ffbbeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,23 +4,24 @@ | |
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| * @flow | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| import type {Path} from 'types/Config'; | ||
|
|
||
| import {sync as spawnSync} from 'execa'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import {Config} from '@jest/types'; | ||
|
|
||
| import {sync as spawnSync, ExecaReturns} from 'execa'; | ||
| import {createDirectory} from 'jest-util'; | ||
| import rimraf from 'rimraf'; | ||
|
|
||
| export const run = (cmd: string, cwd?: Path) => { | ||
| export type RunResult = ExecaReturns & { | ||
| status: number; | ||
| error: Error; | ||
| }; | ||
| export const run = (cmd: string, cwd?: Config.Path): RunResult => { | ||
| const args = cmd.split(/\s/).slice(1); | ||
| const spawnOptions = {cwd, reject: false}; | ||
| const result = spawnSync(cmd.split(/\s/)[0], args, spawnOptions); | ||
| const result = spawnSync(cmd.split(/\s/)[0], args, spawnOptions) as RunResult; | ||
|
|
||
| // For compat with cross-spawn | ||
| result.status = result.code; | ||
|
|
@@ -39,7 +40,7 @@ export const run = (cmd: string, cwd?: Path) => { | |
| return result; | ||
| }; | ||
|
|
||
| export const linkJestPackage = (packageName: string, cwd: Path) => { | ||
| export const linkJestPackage = (packageName: string, cwd: Config.Path) => { | ||
| const packagesDir = path.resolve(__dirname, '../packages'); | ||
| const packagePath = path.resolve(packagesDir, packageName); | ||
| const destination = path.resolve(cwd, 'node_modules/', packageName); | ||
|
|
@@ -50,8 +51,8 @@ export const linkJestPackage = (packageName: string, cwd: Path) => { | |
|
|
||
| export const makeTemplate = ( | ||
| str: string, | ||
| ): ((values?: Array<any>) => string) => (values: ?Array<any>) => | ||
| str.replace(/\$(\d+)/g, (match, number) => { | ||
| ): ((values?: Array<any>) => string) => (values?: Array<any>) => | ||
| str.replace(/\$(\d+)/g, (_match, number) => { | ||
| if (!Array.isArray(values)) { | ||
| throw new Error('Array of values must be passed to the template.'); | ||
| } | ||
|
|
@@ -83,6 +84,7 @@ export const writeFiles = ( | |
| createDirectory(path.join.apply(path, [directory].concat(filePath))); | ||
| } | ||
| fs.writeFileSync( | ||
| // @ts-ignore | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the ignore? The code looks really convoluted (I guess it's from a time before rest params), could we do path.resolve(directory, ...filePath, filename),? Same above, just do
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh the issue here was that filename is can possibly undefined from the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've pushed up some changes to make the code simpler regarding your comments. I'll just continue tomorrow. It's midnight where I'm at. Happy coding :) |
||
| path.resolve.apply(path, [directory].concat(filePath, [filename])), | ||
| files[fileOrPath], | ||
| ); | ||
|
|
@@ -118,7 +120,7 @@ export const sortLines = (output: string) => | |
| .join('\n'); | ||
|
|
||
| export const createEmptyPackage = ( | ||
| directory: Path, | ||
| directory: Config.Path, | ||
| packageJson?: {[keys: string]: any}, | ||
| ) => { | ||
| const DEFAULT_PACKAGE_JSON = { | ||
|
|
@@ -168,7 +170,7 @@ export const extractSummary = (stdout: string) => { | |
| const sortTests = (stdout: string) => | ||
| stdout | ||
| .split('\n') | ||
| .reduce((tests, line, i) => { | ||
| .reduce((tests: Array<Array<string>>, line) => { | ||
| if (['RUNS', 'PASS', 'FAIL'].includes(line.slice(0, 4))) { | ||
| tests.push([line.trimRight()]); | ||
| } else if (line) { | ||
|
|
@@ -194,11 +196,11 @@ export const extractSortedSummary = (stdout: string) => { | |
|
|
||
| export const extractSummaries = ( | ||
| stdout: string, | ||
| ): Array<{rest: string, summary: string}> => { | ||
| ): Array<{rest: string; summary: string}> => { | ||
| const regex = /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm; | ||
|
|
||
| let match = regex.exec(stdout); | ||
| const matches = []; | ||
| const matches: Array<RegExpExecArray> = []; | ||
|
|
||
| while (match) { | ||
| matches.push(match); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.