Skip to content
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

feat: support for showing status updates as soon as they change #110

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
30 changes: 4 additions & 26 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Status} from '@jest/test-result';
import {EventEmitter} from 'events';
import {ChildProcess} from 'child_process';
import {Config as JestConfig} from '@jest/types';
import { CoverageMapData } from 'istanbul-lib-coverage';
import ProjectWorkspace, {ProjectWorkspaceConfig, createProjectWorkspace, LoginShell } from './build/project_workspace';
import {SourceLocation} from '@babel/types';
import {JESParserPluginOptions, JESParserOptions} from './build/parsers/helper';
import type {AggregatedResult} from '@jest/test-result';
export {JESParserPluginOptions, JESParserOptions, createProjectWorkspace, ProjectWorkspaceConfig, ProjectWorkspace, LoginShell};
export interface RunArgs {
args: string[];
Expand Down Expand Up @@ -126,7 +128,7 @@ export class TestReconciler {
file: string,
name: string,
): TestFileAssertionStatus | null;
updateFileWithJestStatus(data: any): TestFileAssertionStatus[];
updateFileWithJestStatus(data: AggregatedResult): TestFileAssertionStatus[];
removeTestFile(fileName: string): void;
}

Expand Down Expand Up @@ -170,37 +172,13 @@ export interface TestAssertionStatus {
line?: number;
}

export interface JestFileResults {
name: string;
summary: string;
message: string;
status: 'failed' | 'passed';
startTime: number;
endTime: number;
assertionResults: Array<JestAssertionResults>;
}

export interface JestAssertionResults {
name: string;
title: string;
status: 'failed' | 'passed';
status: Status;
failureMessages: string[];
fullName: string;
}

export interface JestTotalResults {
success: boolean;
startTime: number;
numTotalTests: number;
numTotalTestSuites: number;
numRuntimeErrorTestSuites: number;
numPassedTests: number;
numFailedTests: number;
numPendingTests: number;
coverageMap?: CoverageMapData;
testResults: Array<JestFileResults>;
}

export interface JestTotalResultsMeta {
noTestsFound: boolean;
}
Expand Down
18 changes: 9 additions & 9 deletions src/test_reconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* @flow
*/

import type {AggregatedResult, AssertionResult, Status} from '@jest/test-result';

import path from 'path';
import type {TestFileAssertionStatus, TestAssertionStatus, TestReconciliationState, Location} from './types';

import type {FormattedAssertionResult, FormattedTestResults} from '../types/TestResult';

/**
* You have a Jest test runner watching for changes, and you have
* an extension that wants to know where to show errors after file parsing.
Expand All @@ -31,20 +31,20 @@ export default class TestReconciler {
// instance properties. This is 1) to prevent race condition 2) the data is already
// stored in the this.fileStatuses, no dup is better 3) client will most likely need to process
// all the results anyway.
updateFileWithJestStatus(results: FormattedTestResults): TestFileAssertionStatus[] {
updateFileWithJestStatus(results: AggregatedResult): TestFileAssertionStatus[] {
// Loop through all files inside the report from Jest
const statusList: TestFileAssertionStatus[] = [];
results.testResults.forEach((file) => {
// Did the file pass/fail?
const status = this.statusToReconcilationState(file.status);
const status = this.statusToReconcilationState(file.testExecError ? 'failed' : 'passed');
// Create our own simpler representation
const fileStatus: TestFileAssertionStatus = {
assertions: this.mapAssertions(file.name, file.assertionResults),
file: file.name,
assertions: this.mapAssertions(file.testFilePath, file.testResults),
file: file.testFilePath,
message: file.message,
status,
};
this.fileStatuses[file.name] = fileStatus;
this.fileStatuses[file.testFilePath] = fileStatus;
statusList.push(fileStatus);
});
return statusList;
Expand All @@ -62,7 +62,7 @@ export default class TestReconciler {
// we don't get this as structured data, but what we get
// is useful enough to make it for ourselves

mapAssertions(filename: string, assertions: Array<FormattedAssertionResult>): Array<TestAssertionStatus> {
mapAssertions(filename: string, assertions: Array<AssertionResult>): Array<TestAssertionStatus> {
// convert jest location (column is 0-based and line is 1-based) to all 0-based location used internally in this package
/* eslint-disable no-param-reassign */
const convertJestLocation = (jestLocation: ?Location) => {
Expand Down Expand Up @@ -131,7 +131,7 @@ export default class TestReconciler {
return restOfTrace ? parseInt(restOfTrace.split(':')[1], 10) : null;
}

statusToReconcilationState(status: string): TestReconciliationState {
statusToReconcilationState(status: Status): TestReconciliationState {
switch (status) {
case 'passed':
return 'KnownSuccess';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"strict": false, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"importsNotUsedAsValues": "error"
"forceConsistentCasingInFileNames": true
},
"include": ["./src/**/*.ts", "src/__tests__/parsers/helper.test.js"],
}
86 changes: 0 additions & 86 deletions types/TestResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* @flow
*/

// import type {ConsoleBuffer} from './Console';

export type RawFileCoverage = {|
path: string,
s: {[statementId: number]: number},
Expand Down Expand Up @@ -113,96 +111,12 @@ export type FormattedAssertionResult = {
title: string,
};

export type AggregatedResultWithoutCoverage = {
numFailedTests: number,
numFailedTestSuites: number,
numPassedTests: number,
numPassedTestSuites: number,
numPendingTests: number,
numTodoTests: number,
numPendingTestSuites: number,
numRuntimeErrorTestSuites: number,
numTotalTests: number,
numTotalTestSuites: number,
openHandles: Array<Error>,
snapshot: SnapshotSummary,
startTime: number,
success: boolean,
testResults: Array<TestResult>,
wasInterrupted: boolean,
};

export type AggregatedResult = AggregatedResultWithoutCoverage & {
coverageMap?: ?CoverageMap,
};

export type Suite = {|
title: string,
suites: Array<Suite>,
tests: Array<AssertionResult>,
|};

export type TestResult = {|
// console: ?ConsoleBuffer,
coverage?: RawCoverage,
displayName: ?string,
failureMessage: ?string,
leaks: boolean,
memoryUsage?: Bytes,
numFailingTests: number,
numPassingTests: number,
numPendingTests: number,
numTodoTests: number,
openHandles: Array<Error>,
perfStats: {|
end: Milliseconds,
start: Milliseconds,
|},
skipped: boolean,
snapshot: {|
added: number,
fileDeleted: boolean,
matched: number,
unchecked: number,
uncheckedKeys: Array<string>,
unmatched: number,
updated: number,
|},
sourceMaps: {[sourcePath: string]: string},
testExecError?: SerializableError,
testFilePath: string,
testResults: Array<AssertionResult>,
|};

export type FormattedTestResult = {
message: string,
name: string,
summary: string,
status: 'failed' | 'passed',
startTime: number,
endTime: number,
coverage: any,
assertionResults: Array<FormattedAssertionResult>,
};

export type FormattedTestResults = {
coverageMap?: ?CoverageMap,
numFailedTests: number,
numFailedTestSuites: number,
numPassedTests: number,
numPassedTestSuites: number,
numPendingTests: number,
numPendingTestSuites: number,
numRuntimeErrorTestSuites: number,
numTotalTests: number,
numTotalTestSuites: number,
snapshot: SnapshotSummary,
startTime: number,
success: boolean,
testResults: Array<FormattedTestResult>,
wasInterrupted: boolean,
};

export type CodeCoverageReporter = any;

export type CodeCoverageFormatter = (coverage: ?RawCoverage, reporter?: CodeCoverageReporter) => ?Object;
Expand Down