Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions e2e/MockStdinWatchPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ class MockStdinWatchPlugin {
});
}
}

/**
* Tried re-writing this in typescript but the tests just failed
Comment thread
SimenB marked this conversation as resolved.
Outdated
*
* I've tried exporting them the following way
* 1. "module.exports = MockStdinWatchPlugin"
* 2. "exports = MockStdinWatchPlugin"
Comment thread
SimenB marked this conversation as resolved.
Outdated
* 3. "export default = MockStdinWatchPlugin" (in Progress)
*/
module.exports = MockStdinWatchPlugin;
32 changes: 17 additions & 15 deletions e2e/Utils.js → e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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.');
}
Expand Down Expand Up @@ -83,6 +84,7 @@ export const writeFiles = (
createDirectory(path.join.apply(path, [directory].concat(filePath)));
}
fs.writeFileSync(
// @ts-ignore
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 path.join(directory, ...filePath)

Copy link
Copy Markdown
Author

@natealcedo natealcedo Feb 26, 2019

Choose a reason for hiding this comment

The 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 pop call. It doesnt fit the type expected by path.resolve

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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],
);
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* @flow
*/

import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';

describe('Correct BeforeAll run', () => {
it('ensures the BeforeAll of ignored suite is not run', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* @flow
*/

import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';

describe('Correct beforeEach order', () => {
it('ensures the correct order for beforeEach', () => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*/

import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import {skipSuiteOnWindows} from '../../scripts/ConditionalTest';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';

const DIR = path.resolve(__dirname, '../cli_accepts_exact_filenames');

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @flow
*/

import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary} from '../Utils';
import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';

test('console printing', () => {
const {stderr, status} = runJest('console');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @flow
*/

import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary} from '../Utils';
import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';

test('console printing', () => {
const {stderr, status} = runJest('console-after-teardown');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';

const DIR = path.resolve(__dirname, '../console-log-output-when-run-in-band');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import fs from 'fs';
import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary} from '../Utils';
import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';

const DIR = path.resolve(__dirname, '../coverage-report');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';

const DIR = path.resolve(__dirname, '../coverage-threshold');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @flow
*/

import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {extractSummary} from '../Utils';
import {wrap} from 'jest-snapshot-serializer-raw';

test('works with custom matchers', () => {
const {stderr} = runJest('custom-matcher-stack-trace', ['sync.test.js']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* @flow
*/

import {cleanup, extractSummary, writeFiles} from '../Utils';
import runJest from '../runJest';
import os from 'os';
import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {cleanup, extractSummary, writeFiles} from '../Utils';

const DIR = path.resolve(os.tmpdir(), 'custom-reporters-test-dir');

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import path from 'path';
import os from 'os';
import {cleanup, createEmptyPackage, writeFiles} from '../Utils';
import runJest from '../runJest';
import os from 'os';
import {skipSuiteOnWindows} from '../../scripts/ConditionalTest';

skipSuiteOnWindows();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* @flow
*/

import runJest, {until} from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest, {until} from '../runJest';

try {
// $FlowFixMe: Node core
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/each.test.js → e2e/__tests__/each.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {extractSummary} from '../Utils';
import {wrap} from 'jest-snapshot-serializer-raw';

const dir = path.resolve(__dirname, '../each');

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* @flow
*/

import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';

test('prints useful error for environment methods after test is done', () => {
const {stderr} = runJest('environment-after-teardown');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* @flow
*/

import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {extractSummary} from '../Utils';
import {skipSuiteOnJestCircus} from '../../scripts/ConditionalTest';
import {wrap} from 'jest-snapshot-serializer-raw';

skipSuiteOnJestCircus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';

const DIR = path.resolve(__dirname, '../execute-tests-once-in-mpr');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {extractSummary} from '../Utils';
import {wrap} from 'jest-snapshot-serializer-raw';
const dir = path.resolve(__dirname, '../expect-async-matcher');

test('works with passing tests', () => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary} from '../Utils';
import runJest from '../runJest';
import {wrap} from 'jest-snapshot-serializer-raw';

const dir = path.resolve(__dirname, '../failures');

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* @flow
*/

import runJest from '../runJest';
import os from 'os';
import path from 'path';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import runJest from '../runJest';

const DIR = path.resolve(os.tmpdir(), 'find-related-tests-test');

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @flow
*/

import runJest from '../runJest';
import os from 'os';
import path from 'path';
import runJest from '../runJest';
import {cleanup, writeFiles} from '../Utils';

const DIR = path.resolve(os.tmpdir(), 'force-exit-test');
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
'use strict';

import fs from 'fs';
import {createDirectory} from 'jest-util';
import os from 'os';
import path from 'path';
import {createDirectory} from 'jest-util';
import runJest, {json as runWithJson} from '../runJest';
import {cleanup} from '../Utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

import path from 'path';
import os from 'os';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {
cleanup,
createEmptyPackage,
extractSummary,
writeFiles,
} from '../Utils';
import {wrap} from 'jest-snapshot-serializer-raw';

const DIR = path.resolve(os.tmpdir(), 'globalVariables.test');
const TEST_DIR = path.resolve(DIR, '__tests__');
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import os from 'os';
import path from 'path';
import HasteMap from 'jest-haste-map';
import {cleanup, writeFiles} from '../Utils';
import {sync as realpath} from 'realpath-native';
import {cleanup, writeFiles} from '../Utils';

const DIR = path.resolve(realpath(os.tmpdir()), 'haste_map_size');

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {cleanup, extractSummary, writeFiles} from '../Utils';
import {wrap} from 'jest-snapshot-serializer-raw';

const DIR = path.resolve(__dirname, '../jest.config.js');

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @flow
*/

import runJest from '../runJest';
import path from 'path';
import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';

const testRootDir = path.resolve(__dirname, '..', '..');

Expand Down
File renamed without changes.
File renamed without changes.
Loading