Skip to content
Merged
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"
}
}
]
}
}
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"${workspaceFolder}/packages/vscode/sample"
],
"outFiles": ["${workspaceFolder}/packages/vscode/dist/**/*.js"],
"preLaunchTask": "npm: watch:local",
"autoAttachChildProcesses": true
"preLaunchTask": "vscode dev",
// only enable this on demand, this causes test run slowly, and child process sourcemap not working
"autoAttachChildProcesses": false
}
]
}
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"
}
]
}
12 changes: 9 additions & 3 deletions e2e/bail/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ describe('test bail option', () => {

expectLog(/Test run aborted/);

const logs = cli.stdout.split('\n').filter((log) => log.includes('Tests'));
const logs = cli.stdout
.split('\n')
.filter((log) => log.startsWith(' Tests'));
// `Tests 1 failed | 1 passed (2)` => 2
const totalCount = Number(logs[0]!.match(/\((\d+)\)/)?.[1]);
expect(totalCount).toBe(2);
Expand All @@ -41,7 +43,9 @@ describe('test bail option', () => {

await expectExecFailed();

const logs = cli.stdout.split('\n').filter((log) => log.includes('Tests'));
const logs = cli.stdout
.split('\n')
.filter((log) => log.startsWith(' Tests'));
// `Tests 1 failed | 1 passed (2)` => 2
const totalCount = Number(logs[0]!.match(/\((\d+)\)/)?.[1]);
expect(totalCount).toBe(2);
Expand All @@ -60,7 +64,9 @@ describe('test bail option', () => {

await expectExecFailed();

const logs = cli.stdout.split('\n').filter((log) => log.includes('Tests'));
const logs = cli.stdout
.split('\n')
.filter((log) => log.startsWith(' Tests'));
// `Tests 1 failed | 2 passed (3)` => 3
const totalCount = Number(logs[0]!.match(/\((\d+)\)/)?.[1]);
expect(totalCount).toBe(3);
Expand Down
12 changes: 5 additions & 7 deletions e2e/basic/test/filePath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ describe('current URL', () => {
expect(
pathe
.normalize(__filename)
.endsWith('/rstest/e2e/basic/test/filePath.test.ts'),
.endsWith('/e2e/basic/test/filePath.test.ts'),
).toBe(true);
});

it('__dirname', () => {
expect(__dirname.startsWith('file://')).toBe(false);
expect(
pathe.normalize(__dirname).endsWith('/rstest/e2e/basic/test'),
).toBe(true);
expect(pathe.normalize(__dirname).endsWith('/e2e/basic/test')).toBe(true);
});

it('import.meta.url', () => {
expect(import.meta.url.startsWith('file://')).toBe(true);
expect(
import.meta.url.endsWith('/rstest/e2e/basic/test/filePath.test.ts'),
).toBe(true);
expect(import.meta.url.endsWith('/e2e/basic/test/filePath.test.ts')).toBe(
true,
);
});
});
});
6 changes: 2 additions & 4 deletions e2e/basic/test/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { aDirName, aFileName, aMetaDirname, aMetaFileName } from '../src/meta';

describe('import.meta', () => {
it('should get test file meta correctly', async () => {
expect(pathe.normalize(__dirname).endsWith('/e2e/basic/test')).toBeTruthy();
expect(
pathe.normalize(__dirname).endsWith('/rstest/e2e/basic/test'),
).toBeTruthy();
expect(
pathe.normalize(__filename).endsWith('/basic/test/meta.test.ts'),
pathe.normalize(__filename).endsWith('/e2e/basic/test/meta.test.ts'),
).toBeTruthy();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ Licensed under MIT license in the repository at https://github.com/chaijs/loupe.

### magic-string

Licensed under MIT license in the repository at https://github.com/rich-harris/magic-string.git.
Licensed under MIT license in the repository at git+https://github.com/Rich-Harris/magic-string.git.

> Copyright 2018 Rich Harris
>
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@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 Down
10 changes: 9 additions & 1 deletion packages/core/src/pool/forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export const createForksPool = (poolOptions: {

const pool = new Tinypool(options);

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

// FIXME It seems that there are still some edge cases where the worker is not killed when the parent process exits.
process.on('SIGTERM', destroy);

return {
name: 'forks',
runTest: async ({ options, rpcMethods }: RunWorkerOptions) => {
Expand All @@ -100,6 +105,9 @@ export const createForksPool = (poolOptions: {
cleanup();
}
},
close: () => pool.destroy(),
close: () => {
process.off('SIGTERM', destroy);
return destroy();
},
};
};
2 changes: 1 addition & 1 deletion packages/core/src/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,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
3 changes: 2 additions & 1 deletion packages/core/src/types/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
FileCoverageData,
Totals,
} from 'istanbul-lib-coverage';
import type { ReportBase } from 'istanbul-lib-report';
import type { ReportOptions } from 'istanbul-reports';

type ReportWithOptions<Name extends keyof ReportOptions = keyof ReportOptions> =
Expand Down Expand Up @@ -83,7 +84,7 @@ export type CoverageOptions = {
* The reporters to use for coverage collection.
* @default ['text', 'html', 'clover', 'json']
*/
reporters?: (keyof ReportOptions | ReportWithOptions)[];
reporters?: (keyof ReportOptions | ReportWithOptions | ReportBase)[];

/**
* The directory to store coverage reports.
Expand Down
2 changes: 1 addition & 1 deletion packages/coverage-istanbul/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"scripts": {
"build": "rslib build",
"dev": "rslib build --watch"
"dev": "cross-env SOURCEMAP=true rslib build --watch"
},
"peerDependencies": {
"@rstest/core": "workspace:~"
Expand Down
3 changes: 3 additions & 0 deletions packages/coverage-istanbul/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default defineConfig({
format: 'esm',
syntax: ['node 18'],
dts: true,
output: {
sourceMap: process.env.SOURCEMAP === 'true',
},
},
],
});
14 changes: 9 additions & 5 deletions packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ export class CoverageProvider implements RstestCoverageProvider {
});
const reportersList = this.options.reporters;
for (const reporter of reportersList) {
const [reporterName, reporterOptions] = Array.isArray(reporter)
? reporter
: [reporter, {}];
const report = reports.create(reporterName, reporterOptions);
report.execute(context);
if (typeof reporter === 'object' && 'execute' in reporter) {
reporter.execute(context);
} else {
const [reporterName, reporterOptions] = Array.isArray(reporter)
? reporter
: [reporter, {}];
const report = reports.create(reporterName, reporterOptions);
report.execute(context);
}
}
} catch (error) {
console.error('Failed to generate coverage reports:', error);
Expand Down
3 changes: 2 additions & 1 deletion packages/coverage-istanbul/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"baseUrl": "./",
"rootDir": "src",
"composite": true,
"isolatedDeclarations": true
"isolatedDeclarations": true,
"declarationMap": true
},
"include": ["src"]
}
8 changes: 4 additions & 4 deletions packages/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ The extension activates automatically when your workspace contains Rstest config

## Configuration

| Setting | Type | Default | Description |
| ---------------------------- | -------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `rstest.testFileGlobPattern` | string[] | `["**/*.test.*", "**/*.spec.*"]` | Glob pattern(s) used to discover test files in the workspace. |
| `rstest.rstestPackagePath` | string | `undefined` | The path to a `package.json` file of a Rstest executable (it's usually inside `node_modules`) in case the extension cannot find it. It will be used to resolve Rstest API paths. This should be used as a last resort fix. Supports `${workspaceFolder}` placeholder. |
| Setting | Type | Default | Description |
| ------------------------------ | -------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `rstest.rstestPackagePath` | string | `undefined` | The path to a `package.json` file of a Rstest executable (it's usually inside `node_modules`) in case the extension cannot find it. It will be used to resolve Rstest API paths. This should be used as a last resort fix. Supports `${workspaceFolder}` placeholder. |
| `rstest.configFileGlobPattern` | string[] | `["**/rstest.config.{mjs,ts,js,cjs,mts,cts}"]` | Glob patterns used to discover config files. |

## How it works

Expand Down
21 changes: 5 additions & 16 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@
"configuration": {
"title": "Rstest",
"properties": {
"rstest.testFileGlobPattern": {
"markdownDescription": "Glob patterns used to discover test files. Must be an array of strings.",
"scope": "resource",
"type": "array",
"items": {
"type": "string"
},
"default": [
"**/*.{test,spec}.[jt]s",
"**/*.{test,spec}.[cm][jt]s",
"**/*.{test,spec}.[jt]sx",
"**/*.{test,spec}.[cm][jt]sx"
]
},
"rstest.rstestPackagePath": {
"markdownDescription": "The path to a `package.json` file of a Rstest executable (it's usually inside `node_modules`) in case the extension cannot find it. It will be used to resolve Rstest API paths. This should be used as a last resort fix. Supports `${workspaceFolder}` placeholder.",
"scope": "resource",
Expand Down Expand Up @@ -105,19 +91,22 @@
"@rsbuild/core": "1.6.12-canary-20251204065915",
"@rslib/core": "0.18.3",
"@rstest/core": "workspace:*",
"@rstest/coverage-istanbul": "workspace:*",
"@swc/core": "^1.15.3",
"@types/glob": "^7.2.0",
"@types/istanbul-lib-report": "^3.0.3",
"@types/mocha": "^10.0.10",
"@types/node": "^22.16.5",
"@types/picomatch": "^4.0.2",
"@types/vscode": "1.97.0",
"@vscode/test-cli": "^0.0.12",
"@vscode/test-electron": "^2.5.2",
"@vscode/vsce": "3.7.1",
"birpc": "2.9.0",
"core-js-pure": "^3.47.0",
"glob": "^7.2.3",
"mocha": "^11.7.5",
"ovsx": "^0.10.7",
"picomatch": "^4.0.3",
"tinyglobby": "^0.2.15",
"typescript": "^5.9.3",
"valibot": "^1.2.0"
}
Expand Down
8 changes: 0 additions & 8 deletions packages/vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import vscode from 'vscode';
// Centralized configuration types for the extension.
// Add new keys here to extend configuration in a type-safe way.
const configSchema = v.object({
// Glob patterns that determine which files are considered tests.
// Must be an array of strings.
testFileGlobPattern: v.fallback(v.array(v.string()), [
'**/*.{test,spec}.[jt]s',
'**/*.{test,spec}.[cm][jt]s',
'**/*.{test,spec}.[jt]sx',
'**/*.{test,spec}.[cm][jt]sx',
]),
// The path to a package.json file of a Rstest executable.
// Used as a last resort if the extension cannot auto-detect @rstest/core.
rstestPackagePath: v.fallback(v.optional(v.string()), undefined),
Expand Down
Loading
Loading