Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ test-temp-*
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/tasks.json
!.vscode/extensions/
!.vscode/extensions/**
.idea/
.nx/
.history/
Expand Down
22 changes: 22 additions & 0 deletions .vscode/extensions/rslib-problem-matcher/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "rslib-problem-matcher",
"version": "0.0.1",
"engines": {
"vscode": "^1.97.0"
},
"contributes": {
"problemMatchers": [
{
"name": "rslib-watch",
"background": {
"activeOnStart": true,
"beginsPattern": "build started...",
"endsPattern": "build complete, watching for changes..."
},
"pattern": {
"regexp": "build failed in"
}
}
]
}
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"${workspaceFolder}/packages/vscode/sample"
],
"outFiles": ["${workspaceFolder}/packages/vscode/dist/**/*.js"],
"preLaunchTask": "npm: watch:local",
"preLaunchTask": "vscode dev",
"autoAttachChildProcesses": true
}
]
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@
"[less]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"rstest.configFileGlobPattern": [
"packages/core/rstest.config.ts",
"packages/vscode/rstest.config.ts",
"e2e/rstest.config.ts"
]
}
43 changes: 29 additions & 14 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,42 @@
"version": "2.0.0",
"tasks": [
{
"label": "core dev",
"type": "npm",
"script": "dev",
"path": "packages/core",
"problemMatcher": "$rslib-watch",
"isBackground": true,
"group": {
"kind": "build"
}
},
{
"label": "coverage-istanbul dev",
"type": "npm",
"script": "dev",
"path": "packages/coverage-istanbul",
"problemMatcher": "$rslib-watch",
"isBackground": true,
"dependsOn": ["core dev"],
"dependsOrder": "parallel",
"group": {
"kind": "build"
}
},
{
"label": "vscode dev",
"type": "npm",
"script": "watch:local",
"path": "packages/vscode",
"problemMatcher": {
// tells vscode when the build task is running
"background": {
"activeOnStart": true,
"beginsPattern": "build started|building",
"endsPattern": "built in|build complete"
},
// although we don't care about it, pattern is required to implement problemMatcher
"pattern": { "regexp": "build failed in" }
},
"problemMatcher": "$rslib-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
},
"dependsOn": ["core dev", "coverage-istanbul dev"],
"dependsOrder": "parallel"
}
]
}
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"devDependencies": {
"@rsbuild/core": "1.6.0-beta.1",
"@rslib/core": "0.17.1",
"@rslib/core": "0.18.1",
"@rstest/core": "workspace:*",
"@rstest/tsconfig": "workspace:*",
"@types/jest-image-snapshot": "^6.4.0",
Expand Down
13 changes: 13 additions & 0 deletions e2e/reporter/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,28 @@ describe.concurrent('reporters', () => {
});

await cli.exec;

expect(cli.stdout).toContain('[custom reporter] onTestSuiteStart');
expect(
cli.stdout.match(/\[custom reporter\] onTestSuiteStart/g)?.length,
).toBe(1);

expect(cli.stdout).toContain('[custom reporter] onTestSuiteResult');
expect(
cli.stdout.match(/\[custom reporter\] onTestSuiteResult/g)?.length,
).toBe(1);

expect(cli.stdout).toContain('[custom reporter] onTestCaseStart');
expect(
cli.stdout.match(/\[custom reporter\] onTestCaseStart/g)?.length,
).toBe(3);

expect(cli.stdout).toContain('[custom reporter] onTestFileStart');

expect(
cli.stdout.match(/\[custom reporter\] onTestCaseResult/g)?.length,
).toBe(3);

expect(cli.stdout).toContain('[custom reporter] onTestRunEnd');
});

Expand Down
9 changes: 9 additions & 0 deletions e2e/reporter/rstest.customReporterConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
TestFileInfo,
TestFileResult,
TestResult,
TestSuiteInfo,
} from '@rstest/core';
import { defineConfig } from '@rstest/core';

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

onTestSuiteStart(_test: TestSuiteInfo) {
reporterResult.push('[custom reporter] onTestSuiteStart');
}

onTestSuiteResult(_result: TestResult) {
reporterResult.push('[custom reporter] onTestSuiteResult');
}

onTestCaseStart(_test: TestCaseInfo) {
reporterResult.push('[custom reporter] onTestCaseStart');
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/rstest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from '@rstest/core';

export default defineConfig({
setupFiles: ['../scripts/rstest.setup.ts'],
testTimeout: process.env.CI ? 10_000 : 5_000,
testTimeout: 10_000,
slowTestThreshold: 2_000,
output: {
externals: {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"scripts": {
"build": "rslib build && npx prettier ./LICENSE.md --write",
"typecheck": "tsc --noEmit",
"dev": "rslib build --watch",
"dev": "cross-env SOURCEMAP=true rslib build --watch",
"test": "npx rstest --globals"
},
"dependencies": {
Expand All @@ -65,12 +65,13 @@
"@babel/code-frame": "^7.27.1",
"@jridgewell/trace-mapping": "0.3.31",
"@microsoft/api-extractor": "^7.53.3",
"@rslib/core": "0.17.1",
"@rslib/core": "0.18.1",
"@rstest/tsconfig": "workspace:*",
"@sinonjs/fake-timers": "^14.0.0",
"@types/babel__code-frame": "^7.0.6",
"@types/istanbul-reports": "^3.0.4",
"@types/istanbul-lib-coverage": "^2.0.6",
"@types/istanbul-lib-report": "^3.0.3",
"@types/jsdom": "^21.1.7",
"@types/sinonjs__fake-timers": "^8.1.5",
"@types/source-map-support": "^0.5.10",
Expand All @@ -82,6 +83,7 @@
"jsdom": "^26.1.0",
"webpack-license-plugin": "^4.5.1",
"picocolors": "^1.1.1",
"pretty-format": "^30.2.0",
"rslog": "^1.3.0",
"source-map-support": "^0.5.21",
"std-env": "^3.10.0",
Expand Down
33 changes: 18 additions & 15 deletions packages/core/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ export default defineConfig({
advancedEsm: true,
},
dts: {
bundle: {
bundledPackages: [
'@types/sinonjs__fake-timers',
'@types/istanbul-reports',
'@types/istanbul-lib-report',
'@types/istanbul-lib-coverage',
'@jridgewell/trace-mapping',
'@vitest/expect',
'@vitest/snapshot',
'@vitest/utils',
'@vitest/spy',
'tinyrainbow',
'@vitest/pretty-format',
],
},
bundle: process.env.SOURCEMAP
? false
: {
bundledPackages: [
'@types/sinonjs__fake-timers',
'@types/istanbul-reports',
'@types/istanbul-lib-report',
'@types/istanbul-lib-coverage',
'@jridgewell/trace-mapping',
'@vitest/expect',
'@vitest/snapshot',
'@vitest/utils',
'@vitest/spy',
'tinyrainbow',
'@vitest/pretty-format',
],
},
},
output: {
sourceMap: process.env.SOURCEMAP === 'true',
externals: {
// Temporary fix: `import * as timers from 'timers'` reassign error
timers: 'commonjs timers',
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ export type {
TestFileInfo,
TestFileResult,
TestResult,
TestSuiteInfo,
} from './types';
9 changes: 8 additions & 1 deletion packages/core/src/pool/forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export const createForksPool = (poolOptions: {

const pool = new Tinypool(options);

const destroy = pool.destroy.bind(pool);

process.on('SIGTERM', destroy);

return {
name: 'forks',
runTest: async ({ options, rpcMethods }: RunWorkerOptions) => {
Expand All @@ -100,6 +104,9 @@ export const createForksPool = (poolOptions: {
cleanup();
}
},
close: () => pool.destroy(),
close: () => {
process.off('SIGTERM', destroy);
return destroy();
},
};
};
16 changes: 14 additions & 2 deletions packages/core/src/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import type {
ProjectContext,
RstestContext,
RuntimeConfig,
RuntimeRPC,
Test,
TestCaseInfo,
TestFileInfo,
TestFileResult,
TestResult,
TestSuiteInfo,
UserConsoleLog,
} from '../types';
import {
Expand Down Expand Up @@ -82,7 +84,7 @@ const getRuntimeConfig = (context: ProjectContext): RuntimeConfig => {
disableConsoleIntercept,
testEnvironment,
isolate,
coverage,
coverage: { ...coverage, reporters: [] }, // reporters may be functions so remove it
snapshotFormat,
logHeapUsage,
bail,
Expand Down Expand Up @@ -204,7 +206,7 @@ export const createPool = async ({
},
});

const rpcMethods = {
const rpcMethods: Omit<RuntimeRPC, 'getAssetsByEntry'> = {
onTestCaseStart: async (test: TestCaseInfo) => {
context.stateManager.onTestCaseStart(test);
Promise.all(
Expand All @@ -231,6 +233,16 @@ export const createPool = async ({
reporters.map((reporter) => reporter.onTestFileStart?.(test)),
);
},
onTestSuiteStart: async (test: TestSuiteInfo) => {
await Promise.all(
reporters.map((reporter) => reporter.onTestSuiteStart?.(test)),
);
},
onTestSuiteResult: async (result: TestResult) => {
await Promise.all(
reporters.map((reporter) => reporter.onTestSuiteResult?.(result)),
);
},
resolveSnapshotPath: (testPath: string): string => {
const snapExtension = '.snap';
const resolver =
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/reporter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export class DefaultReporter implements Reporter {
this.rootPath = rootPath;
this.config = config;
this.options = options;
if (isTTY()) {
this.statusRenderer = new StatusRenderer(rootPath, testState);
if (isTTY() || options.logger) {
this.statusRenderer = new StatusRenderer(
rootPath,
testState,
options.logger,
);
}
}

Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/reporter/statusRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@ import {
TestFileSummaryLabel,
TestSummaryLabel,
} from './summary';
import { WindowRenderer } from './windowedRenderer';
import {
WindowRenderer,
type Options as WindowRendererOptions,
} from './windowedRenderer';

export class StatusRenderer {
private rootPath: string;
private renderer: WindowRenderer;
private startTime: number | undefined = undefined;
private testState: RstestTestState;

constructor(rootPath: string, state: RstestTestState) {
constructor(
rootPath: string,
state: RstestTestState,
logger?: WindowRendererOptions['logger'],
) {
this.rootPath = rootPath;
this.renderer = new WindowRenderer({
getWindow: () => this.getContent(),
logger: {
logger: logger ?? {
outputStream: process.stdout,
errorStream: process.stderr,
getColumns: () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/reporter/windowedRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const MOVE_CURSOR_ONE_ROW_UP = `${ESC}1A`;
const SYNC_START = `${ESC}?2026h`;
const SYNC_END = `${ESC}?2026l`;

interface Options {
export interface Options {
logger: {
outputStream: Writable;
errorStream: Writable;
Expand Down
Loading