Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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;
35 changes: 18 additions & 17 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 @@ -80,10 +81,10 @@ export const writeFiles = (
const filename = filePath.pop(); // filepath becomes dirPath (no filename)

if (filePath.length) {
createDirectory(path.join.apply(path, [directory].concat(filePath)));
createDirectory(path.join(directory, ...filePath));
Comment thread
SimenB marked this conversation as resolved.
Outdated
}
fs.writeFileSync(
path.resolve.apply(path, [directory].concat(filePath, [filename])),
path.resolve(directory, ...filePath, filename || ''),
Comment thread
SimenB marked this conversation as resolved.
Outdated
files[fileOrPath],
);
});
Expand Down Expand Up @@ -118,7 +119,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 +169,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 +195,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