Skip to content

Commit c6411a8

Browse files
committed
feat(vscode): report test run progress
1 parent 0d2ef07 commit c6411a8

32 files changed

+667
-668
lines changed

e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"devDependencies": {
1010
"@rsbuild/core": "1.6.0-beta.1",
11-
"@rslib/core": "0.17.1",
11+
"@rslib/core": "0.18.1",
1212
"@rstest/core": "workspace:*",
1313
"@rstest/tsconfig": "workspace:*",
1414
"@types/jest-image-snapshot": "^6.4.0",

e2e/rstest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig } from '@rstest/core';
22

33
export default defineConfig({
44
setupFiles: ['../scripts/rstest.setup.ts'],
5-
testTimeout: process.env.CI ? 10_000 : 5_000,
5+
testTimeout: 10_000,
66
slowTestThreshold: 2_000,
77
output: {
88
externals: {

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"scripts": {
4949
"build": "rslib build && npx prettier ./LICENSE.md --write",
5050
"typecheck": "tsc --noEmit",
51-
"dev": "rslib build --watch",
51+
"dev": "cross-env SOURCEMAP=true rslib build --watch",
5252
"test": "npx rstest --globals"
5353
},
5454
"dependencies": {
@@ -65,7 +65,7 @@
6565
"@babel/code-frame": "^7.27.1",
6666
"@jridgewell/trace-mapping": "0.3.31",
6767
"@microsoft/api-extractor": "^7.53.3",
68-
"@rslib/core": "0.17.1",
68+
"@rslib/core": "0.18.1",
6969
"@rstest/tsconfig": "workspace:*",
7070
"@sinonjs/fake-timers": "^14.0.0",
7171
"@types/babel__code-frame": "^7.0.6",

packages/core/rslib.config.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,26 @@ export default defineConfig({
1414
advancedEsm: true,
1515
},
1616
dts: {
17-
bundle: {
18-
bundledPackages: [
19-
'@types/sinonjs__fake-timers',
20-
'@types/istanbul-reports',
21-
'@types/istanbul-lib-report',
22-
'@types/istanbul-lib-coverage',
23-
'@jridgewell/trace-mapping',
24-
'@vitest/expect',
25-
'@vitest/snapshot',
26-
'@vitest/utils',
27-
'@vitest/spy',
28-
'tinyrainbow',
29-
'@vitest/pretty-format',
30-
],
31-
},
17+
bundle: process.env.SOURCEMAP
18+
? false
19+
: {
20+
bundledPackages: [
21+
'@types/sinonjs__fake-timers',
22+
'@types/istanbul-reports',
23+
'@types/istanbul-lib-report',
24+
'@types/istanbul-lib-coverage',
25+
'@jridgewell/trace-mapping',
26+
'@vitest/expect',
27+
'@vitest/snapshot',
28+
'@vitest/utils',
29+
'@vitest/spy',
30+
'tinyrainbow',
31+
'@vitest/pretty-format',
32+
],
33+
},
3234
},
3335
output: {
36+
sourceMap: process.env.SOURCEMAP === 'true',
3437
externals: {
3538
// Temporary fix: `import * as timers from 'timers'` reassign error
3639
timers: 'commonjs timers',

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ export type {
7777
TestFileInfo,
7878
TestFileResult,
7979
TestResult,
80+
TestSuiteInfo,
8081
} from './types';

packages/core/src/pool/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import type {
77
ProjectContext,
88
RstestContext,
99
RuntimeConfig,
10+
RuntimeRPC,
1011
Test,
1112
TestCaseInfo,
1213
TestFileInfo,
1314
TestFileResult,
1415
TestResult,
16+
TestSuiteInfo,
1517
UserConsoleLog,
1618
} from '../types';
1719
import { needFlagExperimentalDetectModule, serializableConfig } from '../utils';
@@ -58,6 +60,7 @@ const getRuntimeConfig = (context: ProjectContext): RuntimeConfig => {
5860
logHeapUsage,
5961
bail,
6062
chaiConfig,
63+
exact,
6164
} = context.normalizedConfig;
6265

6366
return {
@@ -83,6 +86,7 @@ const getRuntimeConfig = (context: ProjectContext): RuntimeConfig => {
8386
logHeapUsage,
8487
bail,
8588
chaiConfig,
89+
exact,
8690
};
8791
};
8892

@@ -200,7 +204,7 @@ export const createPool = async ({
200204
},
201205
});
202206

203-
const rpcMethods = {
207+
const rpcMethods: Omit<RuntimeRPC, 'getAssetsByEntry'> = {
204208
onTestCaseStart: async (test: TestCaseInfo) => {
205209
Promise.all(
206210
reporters.map((reporter) => reporter.onTestCaseStart?.(test)),
@@ -226,6 +230,16 @@ export const createPool = async ({
226230
reporters.map((reporter) => reporter.onTestFileStart?.(test)),
227231
);
228232
},
233+
onTestSuiteStart: async (test: TestSuiteInfo) => {
234+
await Promise.all(
235+
reporters.map((reporter) => reporter.onTestSuiteStart?.(test)),
236+
);
237+
},
238+
onTestSuiteResult: async (result: TestResult) => {
239+
await Promise.all(
240+
reporters.map((reporter) => reporter.onTestSuiteResult?.(result)),
241+
);
242+
},
229243
resolveSnapshotPath: (testPath: string): string => {
230244
const snapExtension = '.snap';
231245
const resolver =

packages/core/src/reporter/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export class DefaultReporter implements Reporter {
3636
this.rootPath = rootPath;
3737
this.config = config;
3838
this.options = options;
39-
if (isTTY()) {
40-
this.statusRenderer = new StatusRenderer(rootPath);
39+
if (isTTY() || options.logger) {
40+
this.statusRenderer = new StatusRenderer(rootPath, options.logger);
4141
}
4242
}
4343

packages/core/src/reporter/statusRenderer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
TestFileSummaryLabel,
1414
TestSummaryLabel,
1515
} from './summary';
16-
import { WindowRenderer } from './windowedRenderer';
16+
import {
17+
WindowRenderer,
18+
type Options as WindowRendererOptions,
19+
} from './windowedRenderer';
1720

1821
export class StatusRenderer {
1922
private rootPath: string;
@@ -25,11 +28,11 @@ export class StatusRenderer {
2528
private testModules: TestFileResult[] = [];
2629
private startTime: number | undefined = undefined;
2730

28-
constructor(rootPath: string) {
31+
constructor(rootPath: string, logger?: WindowRendererOptions['logger']) {
2932
this.rootPath = rootPath;
3033
this.renderer = new WindowRenderer({
3134
getWindow: () => this.getContent(),
32-
logger: {
35+
logger: logger ?? {
3336
outputStream: process.stdout,
3437
errorStream: process.stderr,
3538
getColumns: () => {

packages/core/src/reporter/windowedRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const MOVE_CURSOR_ONE_ROW_UP = `${ESC}1A`;
2424
const SYNC_START = `${ESC}?2026h`;
2525
const SYNC_END = `${ESC}?2026l`;
2626

27-
interface Options {
27+
export interface Options {
2828
logger: {
2929
outputStream: Writable;
3030
errorStream: Writable;

packages/core/src/runtime/runner/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
2626
const {
2727
testPath,
2828
project,
29-
runtimeConfig: { testNamePattern },
29+
runtimeConfig: { testNamePattern, exact },
3030
} = workerState;
3131
const runtime = createRuntimeAPI({
3232
project,
@@ -48,7 +48,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
4848
runner: {
4949
runTests: async (testPath: string, hooks: RunnerHooks, api: Rstest) => {
5050
const tests = await runtime.instance.getTests();
51-
traverseUpdateTest(tests, testNamePattern);
51+
traverseUpdateTest(tests, testNamePattern, exact);
5252
runtime.instance.updateStatus('running');
5353

5454
const results = await testRunner.runTests({
@@ -63,7 +63,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
6363
},
6464
collectTests: async () => {
6565
const tests = await runtime.instance.getTests();
66-
traverseUpdateTest(tests, testNamePattern);
66+
traverseUpdateTest(tests, testNamePattern, exact);
6767

6868
return tests;
6969
},

0 commit comments

Comments
 (0)