From 7c425c85b0fdd6d9a6df75a7f5c9a9e7f255e2e8 Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Sat, 30 Sep 2023 02:38:06 +0200 Subject: [PATCH 1/2] fix: apply ts error fixes --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 0c99e27..5973357 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"], } \ No newline at end of file From 12a6578d31e03fe62b66c4ed762487ba23a76ba6 Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Sat, 30 Sep 2023 02:39:14 +0200 Subject: [PATCH 2/2] fix: apply jest types whenever possible --- index.d.ts | 30 ++------------- src/test_reconciler.js | 18 ++++----- types/TestResult.js | 86 ------------------------------------------ 3 files changed, 13 insertions(+), 121 deletions(-) diff --git a/index.d.ts b/index.d.ts index b6ae6c6..d9ddfeb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,6 +5,7 @@ * 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'; @@ -12,6 +13,7 @@ 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[]; @@ -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; } @@ -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; -} - 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; -} - export interface JestTotalResultsMeta { noTestsFound: boolean; } diff --git a/src/test_reconciler.js b/src/test_reconciler.js index efc5418..2b8b89f 100644 --- a/src/test_reconciler.js +++ b/src/test_reconciler.js @@ -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. @@ -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; @@ -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): Array { + mapAssertions(filename: string, assertions: Array): Array { // 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) => { @@ -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'; diff --git a/types/TestResult.js b/types/TestResult.js index 23c910a..53bb2fa 100644 --- a/types/TestResult.js +++ b/types/TestResult.js @@ -7,8 +7,6 @@ * @flow */ -// import type {ConsoleBuffer} from './Console'; - export type RawFileCoverage = {| path: string, s: {[statementId: number]: number}, @@ -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, - snapshot: SnapshotSummary, - startTime: number, - success: boolean, - testResults: Array, - wasInterrupted: boolean, -}; - -export type AggregatedResult = AggregatedResultWithoutCoverage & { - coverageMap?: ?CoverageMap, -}; - export type Suite = {| title: string, suites: Array, tests: Array, |}; -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, - perfStats: {| - end: Milliseconds, - start: Milliseconds, - |}, - skipped: boolean, - snapshot: {| - added: number, - fileDeleted: boolean, - matched: number, - unchecked: number, - uncheckedKeys: Array, - unmatched: number, - updated: number, - |}, - sourceMaps: {[sourcePath: string]: string}, - testExecError?: SerializableError, - testFilePath: string, - testResults: Array, -|}; - -export type FormattedTestResult = { - message: string, - name: string, - summary: string, - status: 'failed' | 'passed', - startTime: number, - endTime: number, - coverage: any, - assertionResults: Array, -}; - -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, - wasInterrupted: boolean, -}; - export type CodeCoverageReporter = any; export type CodeCoverageFormatter = (coverage: ?RawCoverage, reporter?: CodeCoverageReporter) => ?Object;