Skip to content

Commit

Permalink
Vscode jest monorepo support (jestjs#4572)
Browse files Browse the repository at this point in the history
* added watch mode and test_reconciler changes + upgrade typescript version

* upgrade typescript (jest-test-typescript-parser)

* clean up
  • Loading branch information
connectdotz authored and tabrindle committed Oct 2, 2017
1 parent f249e40 commit 5dcc04a
Show file tree
Hide file tree
Showing 8 changed files with 874 additions and 63 deletions.
474 changes: 474 additions & 0 deletions fixtures/failing_jsons/monorepo_root_1.json

Large diffs are not rendered by default.

246 changes: 246 additions & 0 deletions fixtures/failing_jsons/monorepo_root_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
{
"numFailedTestSuites": 2,
"numFailedTests": 2,
"numPassedTestSuites": 2,
"numPassedTests": 21,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numRuntimeErrorTestSuites": 0,
"numTotalTestSuites": 4,
"numTotalTests": 23,
"snapshot": {
"added": 0,
"didUpdate": false,
"failure": false,
"filesAdded": 0,
"filesRemoved": 0,
"filesUnmatched": 0,
"filesUpdated": 0,
"matched": 0,
"total": 0,
"unchecked": 0,
"unmatched": 0,
"updated": 0
},
"startTime": 1506716960031,
"success": false,
"testResults": [
{
"assertionResults": [
{
"ancestorTitles": ["curry"],
"failureMessages": [],
"fullName": "curry simple curry",
"status": "passed",
"title": "simple curry"
},
{
"ancestorTitles": ["curry"],
"failureMessages": [],
"fullName": "curry can parse middleware",
"status": "passed",
"title": "can parse middleware"
},
{
"ancestorTitles": ["curry"],
"failureMessages": [],
"fullName": "curry can be used many times",
"status": "passed",
"title": "can be used many times"
},
{
"ancestorTitles": ["curry"],
"failureMessages": [],
"fullName": "curry can be used with deferred functions many times",
"status": "passed",
"title": "can be used with deferred functions many times"
},
{
"ancestorTitles": ["curry"],
"failureMessages": [
"Error: Failed: intentionally failed\n at stackFormatter (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/expectation_result_factory.js:49:427)\n at expectationResultFactory (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/expectation_result_factory.js:49:591)\n at Spec.Object.<anonymous>.Spec.addExpectationResult (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/jasmine/Spec.js:73:70)\n at Env.fail (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/jasmine/Env.js:510:25)\n at fail (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/jasmine/jasmine_light.js:116:23)\n at Object.<anonymous> (/Z/Y/packages/Y-keeper/src/redux/doable/__tests__/learn-ramda.test.ts:75:9)\n at Object.asyncFn (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/jasmine_async.js:124:345)\n at resolve (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/queue_runner.js:46:12)\n at tryCallTwo (/Z/Y/node_modules/promise/lib/core.js:45:5)\n at doResolve (/Z/Y/node_modules/promise/lib/core.js:200:13)"
],
"fullName": "curry keeper jest test",
"status": "failed",
"title": "keeper jest test"
}
],
"endTime": 1506716960706,
"message":
" ● curry › keeper jest test\n\n Failed: intentionally failed\n \n at stackFormatter (node_modules/jest/node_modules/jest-jasmine2/build/expectation_result_factory.js:49:427)\n at Object.<anonymous> (packages/Y-keeper/src/redux/doable/__tests__/learn-ramda.test.ts:75:9)\n at tryCallTwo (node_modules/promise/lib/core.js:45:5)\n at doResolve (node_modules/promise/lib/core.js:200:13)\n",
"name":
"/X/packages/Y-keeper/src/redux/doable/__tests__/learn-ramda.test.ts",
"startTime": 1506716960103,
"status": "failed",
"summary": ""
},
{
"assertionResults": [
{
"ancestorTitles": ["testing EthNumber..."],
"failureMessages": [],
"fullName":
"testing EthNumber... can take various format bigNumber can take",
"status": "passed",
"title": "can take various format bigNumber can take"
},
{
"ancestorTitles": ["testing EthNumber..."],
"failureMessages": [],
"fullName":
"testing EthNumber... can handle empty and null as expected",
"status": "passed",
"title": "can handle empty and null as expected"
},
{
"ancestorTitles": ["testing EthNumber..."],
"failureMessages": [],
"fullName": "testing EthNumber... should prevent toNumber for money",
"status": "passed",
"title": "should prevent toNumber for money"
},
{
"ancestorTitles": ["testing EthNumber..."],
"failureMessages": [],
"fullName": "testing EthNumber... can understand unit",
"status": "passed",
"title": "can understand unit"
},
{
"ancestorTitles": ["testing EthNumber..."],
"failureMessages": [],
"fullName": "testing EthNumber... can compare across unit",
"status": "passed",
"title": "can compare across unit"
},
{
"ancestorTitles": ["testing EthNumber..."],
"failureMessages": [],
"fullName": "testing EthNumber... can operate across unit",
"status": "passed",
"title": "can operate across unit"
},
{
"ancestorTitles": ["testing Address"],
"failureMessages": [],
"fullName": "testing Address can prevent invalid address",
"status": "passed",
"title": "can prevent invalid address"
},
{
"ancestorTitles": ["testing Address"],
"failureMessages": [],
"fullName":
"testing Address can accept valid address with or without prefix",
"status": "passed",
"title": "can accept valid address with or without prefix"
},
{
"ancestorTitles": ["testing Address"],
"failureMessages": [],
"fullName": "testing Address can detect if address is empty",
"status": "passed",
"title": "can detect if address is empty"
}
],
"endTime": 1506716961514,
"message": "",
"name": "/X/packages/Y-core/src/eth/__tests__/types.test.ts",
"startTime": 1506716960759,
"status": "passed",
"summary": ""
},
{
"assertionResults": [
{
"ancestorTitles": [],
"failureMessages": [],
"fullName": "renders correctly",
"status": "passed",
"title": "renders correctly"
},
{
"ancestorTitles": [],
"failureMessages": [
"Error: Failed: make jest fail for react-native\n at stackFormatter (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/expectation_result_factory.js:49:427)\n at expectationResultFactory (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/expectation_result_factory.js:49:591)\n at Spec.Object.<anonymous>.Spec.addExpectationResult (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/jasmine/Spec.js:73:70)\n at Env.fail (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/jasmine/Env.js:510:25)\n at fail (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/jasmine/jasmine_light.js:116:23)\n at Object.<anonymous> (/Z/Y/packages/Y-app-vault/native/__tests__/index.ios.js:14:1)\n at Object.asyncFn (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/jasmine_async.js:124:345)\n at resolve (/Z/Y/node_modules/jest/node_modules/jest-jasmine2/build/queue_runner.js:46:12)\n at tryCallTwo (/Z/Y/node_modules/promise/lib/core.js:45:5)\n at doResolve (/Z/Y/node_modules/promise/lib/core.js:200:13)"
],
"fullName": "testing jest with react-native",
"status": "failed",
"title": "testing jest with react-native"
}
],
"endTime": 1506716961734,
"message":
" ● testing jest with react-native\n\n Failed: make jest fail for react-native\n \n at stackFormatter (node_modules/jest/node_modules/jest-jasmine2/build/expectation_result_factory.js:49:427)\n at Object.<anonymous> (packages/Y-app-vault/native/__tests__/index.ios.js:14:1)\n at tryCallTwo (node_modules/promise/lib/core.js:45:5)\n at doResolve (node_modules/promise/lib/core.js:200:13)\n",
"name": "/X/packages/Y-app-vault/native/__tests__/index.ios.js",
"startTime": 1506716961553,
"status": "failed",
"summary": ""
},
{
"assertionResults": [
{
"ancestorTitles": ["testing HDKeyMaker"],
"failureMessages": [],
"fullName":
"testing HDKeyMaker can create account and generate mnemonic phrase",
"status": "passed",
"title": "can create account and generate mnemonic phrase"
},
{
"ancestorTitles": ["testing HDKeyMaker"],
"failureMessages": [],
"fullName":
"testing HDKeyMaker same mnemonic will generate same keys and same order",
"status": "passed",
"title": "same mnemonic will generate same keys and same order"
},
{
"ancestorTitles": ["testing HDKeyMaker"],
"failureMessages": [],
"fullName":
"testing HDKeyMaker different mnemonic will generate different keys",
"status": "passed",
"title": "different mnemonic will generate different keys"
},
{
"ancestorTitles": ["testing HDKeyMaker"],
"failureMessages": [],
"fullName":
"testing HDKeyMaker can add more accounts, while to be restorable",
"status": "passed",
"title": "can add more accounts, while to be restorable"
},
{
"ancestorTitles": ["testing HDKeyMaker"],
"failureMessages": [],
"fullName": "testing HDKeyMaker has the right type",
"status": "passed",
"title": "has the right type"
},
{
"ancestorTitles": ["testing HDKeyMaker"],
"failureMessages": [],
"fullName":
"testing HDKeyMaker can serialize then deserialize correctly",
"status": "passed",
"title": "can serialize then deserialize correctly"
},
{
"ancestorTitles": ["testing HDKeyMaker"],
"failureMessages": [],
"fullName": "testing HDKeyMaker satisfy KeyMakerCreatable interface",
"status": "passed",
"title": "satisfy KeyMakerCreatable interface"
}
],
"endTime": 1506716961992,
"message": "",
"name": "/X/packages/Y-key-hd/src/__tests__/HDKeyMaker.test.ts",
"startTime": 1506716961763,
"status": "passed",
"summary": ""
}
],
"wasInterrupted": false
}
29 changes: 17 additions & 12 deletions packages/jest-editor-support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import {EventEmitter} from 'events';
import { EventEmitter } from 'events';

export class Runner extends EventEmitter {
constructor(workspace: ProjectWorkspace);
start(): void;
watchMode: boolean;
start(watchMode?: boolean): void;
closeProcess(): void;
runJestWithUpdateForSnapshots(completion: any): void;
}
Expand All @@ -28,7 +29,7 @@ export class ProjectWorkspace {
rootPath: string,
pathToJest: string,
pathToConfig: string,
localJestMajorVersin: number
localJestMajorVersin: number,
);
pathToJest: string;
rootPath: string;
Expand Down Expand Up @@ -61,15 +62,19 @@ export class Expect extends Node {}

export class TestReconciler {
stateForTestFile(file: string): TestReconcilationState;
stateForTestAssertion(file: string, name: string): TestFileAssertionStatus | null;
failedStatuses(): Array<TestFileAssertionStatus>;
updateFileWithJestStatus(data): void;
assertionsForTestFile(file: string): TestAssertionStatus[] | null;
stateForTestAssertion(
file: string,
name: string,
): TestFileAssertionStatus | null;
updateFileWithJestStatus(data): TestFileAssertionStatus[];
}

export type TestReconcilationState = "Unknown" |
"KnownSuccess" |
"KnownFail" |
"KnownSkip";
export type TestReconcilationState =
| 'Unknown'
| 'KnownSuccess'
| 'KnownFail'
| 'KnownSkip';

export interface TestFileAssertionStatus {
file: string;
Expand All @@ -91,7 +96,7 @@ export interface JestFileResults {
name: string;
summary: string;
message: string;
status: "failed" | "passed";
status: 'failed' | 'passed';
startTime: number;
endTime: number;
assertionResults: Array<JestAssertionResults>;
Expand All @@ -100,7 +105,7 @@ export interface JestFileResults {
export interface JestAssertionResults {
name: string;
title: string;
status: "failed" | "passed";
status: 'failed' | 'passed';
failureMessages: string[];
}

Expand Down
15 changes: 7 additions & 8 deletions packages/jest-editor-support/src/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class Runner extends EventEmitter {
workspace: ProjectWorkspace,
args: Array<string>,
) => ChildProcess;
watchMode: boolean;

constructor(workspace: ProjectWorkspace, options?: Options) {
super();
Expand All @@ -35,21 +36,19 @@ export default class Runner extends EventEmitter {
this.outputPath = tmpdir() + '/jest_runner.json';
}

start() {
start(watchMode: boolean = true) {
if (this.debugprocess) {
return;
}

this.watchMode = watchMode;

// Handle the arg change on v18
const belowEighteen = this.workspace.localJestMajorVersion < 18;
const outputArg = belowEighteen ? '--jsonOutputFile' : '--outputFile';

const args = [
'--json',
'--useStderr',
'--watch',
outputArg,
this.outputPath,
];
const args = ['--json', '--useStderr', outputArg, this.outputPath];
if (this.watchMode) args.push('--watch');

this.debugprocess = this._createProcess(this.workspace, args);
this.debugprocess.stdout.on('data', (data: Buffer) => {
Expand Down
Loading

0 comments on commit 5dcc04a

Please sign in to comment.