Skip to content

Commit fc55505

Browse files
committed
feat(vscode): report test run progress
1 parent f87674d commit fc55505

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+915
-695
lines changed

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,10 @@
5353
"[less]": {
5454
"editor.defaultFormatter": "esbenp.prettier-vscode"
5555
},
56-
"typescript.tsdk": "node_modules/typescript/lib"
56+
"typescript.tsdk": "node_modules/typescript/lib",
57+
"rstest.configFileGlobPattern": [
58+
"packages/core/rstest.config.ts",
59+
"packages/vscode/rstest.config.ts",
60+
"e2e/rstest.config.ts"
61+
]
5762
}

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/reporter/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,28 @@ describe.concurrent('reporters', () => {
7171
});
7272

7373
await cli.exec;
74+
75+
expect(cli.stdout).toContain('[custom reporter] onTestSuiteStart');
76+
expect(
77+
cli.stdout.match(/\[custom reporter\] onTestSuiteStart/g)?.length,
78+
).toBe(1);
79+
80+
expect(cli.stdout).toContain('[custom reporter] onTestSuiteResult');
81+
expect(
82+
cli.stdout.match(/\[custom reporter\] onTestSuiteResult/g)?.length,
83+
).toBe(1);
84+
7485
expect(cli.stdout).toContain('[custom reporter] onTestCaseStart');
7586
expect(
7687
cli.stdout.match(/\[custom reporter\] onTestCaseStart/g)?.length,
7788
).toBe(3);
89+
7890
expect(cli.stdout).toContain('[custom reporter] onTestFileStart');
7991

8092
expect(
8193
cli.stdout.match(/\[custom reporter\] onTestCaseResult/g)?.length,
8294
).toBe(3);
95+
8396
expect(cli.stdout).toContain('[custom reporter] onTestRunEnd');
8497
});
8598

e2e/reporter/rstest.customReporterConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
TestFileInfo,
55
TestFileResult,
66
TestResult,
7+
TestSuiteInfo,
78
} from '@rstest/core';
89
import { defineConfig } from '@rstest/core';
910

@@ -14,6 +15,14 @@ class MyReporter implements Reporter {
1415
reporterResult.push('[custom reporter] onTestFileStart');
1516
}
1617

18+
onTestSuiteStart(_test: TestSuiteInfo) {
19+
reporterResult.push('[custom reporter] onTestSuiteStart');
20+
}
21+
22+
onTestSuiteResult(_result: TestResult) {
23+
reporterResult.push('[custom reporter] onTestSuiteResult');
24+
}
25+
1726
onTestCaseStart(_test: TestCaseInfo) {
1827
reporterResult.push('[custom reporter] onTestCaseStart');
1928
}

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
@@ -84,4 +84,5 @@ export type {
8484
TestFileInfo,
8585
TestFileResult,
8686
TestResult,
87+
TestSuiteInfo,
8788
} 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 {
@@ -62,6 +64,7 @@ const getRuntimeConfig = (context: ProjectContext): RuntimeConfig => {
6264
logHeapUsage,
6365
bail,
6466
chaiConfig,
67+
exact,
6568
} = context.normalizedConfig;
6669

6770
return {
@@ -87,6 +90,7 @@ const getRuntimeConfig = (context: ProjectContext): RuntimeConfig => {
8790
logHeapUsage,
8891
bail,
8992
chaiConfig,
93+
exact,
9094
};
9195
};
9296

@@ -204,7 +208,7 @@ export const createPool = async ({
204208
},
205209
});
206210

207-
const rpcMethods = {
211+
const rpcMethods: Omit<RuntimeRPC, 'getAssetsByEntry'> = {
208212
onTestCaseStart: async (test: TestCaseInfo) => {
209213
context.stateManager.onTestCaseStart(test);
210214
Promise.all(
@@ -231,6 +235,16 @@ export const createPool = async ({
231235
reporters.map((reporter) => reporter.onTestFileStart?.(test)),
232236
);
233237
},
238+
onTestSuiteStart: async (test: TestSuiteInfo) => {
239+
await Promise.all(
240+
reporters.map((reporter) => reporter.onTestSuiteStart?.(test)),
241+
);
242+
},
243+
onTestSuiteResult: async (result: TestResult) => {
244+
await Promise.all(
245+
reporters.map((reporter) => reporter.onTestSuiteResult?.(result)),
246+
);
247+
},
234248
resolveSnapshotPath: (testPath: string): string => {
235249
const snapExtension = '.snap';
236250
const resolver =

packages/core/src/reporter/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ export class DefaultReporter implements Reporter {
3737
this.rootPath = rootPath;
3838
this.config = config;
3939
this.options = options;
40-
if (isTTY()) {
41-
this.statusRenderer = new StatusRenderer(rootPath, testState);
40+
if (isTTY() || options.logger) {
41+
this.statusRenderer = new StatusRenderer(
42+
rootPath,
43+
testState,
44+
options.logger,
45+
);
4246
}
4347
}
4448

0 commit comments

Comments
 (0)