Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7490da22c0 | |||
| 3b2a5982a2 | |||
| 099eff0b1e | |||
| 3a56040c5b | |||
| 8435c45b4b | |||
| 18904d18e8 |
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"json.schemas": [
|
"json.schemas": [
|
||||||
{
|
{
|
||||||
"fileMatch": ["/npmextra.json"],
|
"fileMatch": ["/.smartconfig.json"],
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
21
changelog.md
21
changelog.md
@@ -1,5 +1,26 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-03-27 - 3.6.2 - fix(cli,chromium-runtime)
|
||||||
|
clean up long-lived test runner resources after runs to prevent hanging processes
|
||||||
|
|
||||||
|
- call TsTest.cleanup() after non-watch CLI runs so smartexit handlers are deregistered
|
||||||
|
- terminate active WebSocket clients before closing the Chromium runtime server to release open connections cleanly
|
||||||
|
|
||||||
|
## 2026-03-26 - 3.6.1 - fix(chromium runtime)
|
||||||
|
encode Chromium test bundle names correctly for nested file paths
|
||||||
|
|
||||||
|
- Use replaceAll() so bundle cache filenames consistently handle test paths with multiple directory separators.
|
||||||
|
- URL-encode the bundleName query parameter before opening the Chromium test page to avoid lookup issues with generated bundle filenames.
|
||||||
|
|
||||||
|
## 2026-03-24 - 3.6.0 - feat(config)
|
||||||
|
migrate project metadata to .smartconfig and refresh build configuration
|
||||||
|
|
||||||
|
- replace npmextra.json with .smartconfig.json and update packaged files accordingly
|
||||||
|
- add module-level README documentation under ts/readme.md
|
||||||
|
- bump build and runtime dependencies including tsbuild, tsbundle, smartstorage, smartwatch, smartserve, and ws
|
||||||
|
- relax TypeScript compiler strictness and include Node types in tsconfig
|
||||||
|
- update README license links to point to license.md
|
||||||
|
|
||||||
## 2026-03-23 - 3.5.1 - fix(runtime)
|
## 2026-03-23 - 3.5.1 - fix(runtime)
|
||||||
handle expected exitCode rejection after terminating timed out test processes
|
handle expected exitCode rejection after terminating timed out test processes
|
||||||
|
|
||||||
|
|||||||
@@ -9,5 +9,5 @@
|
|||||||
"target": "ES2022"
|
"target": "ES2022"
|
||||||
},
|
},
|
||||||
"nodeModulesDir": true,
|
"nodeModulesDir": true,
|
||||||
"version": "3.5.1"
|
"version": "3.6.2"
|
||||||
}
|
}
|
||||||
|
|||||||
16
package.json
16
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@git.zone/tstest",
|
"name": "@git.zone/tstest",
|
||||||
"version": "3.5.1",
|
"version": "3.6.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A powerful, modern test runner for TypeScript with multi-runtime support (Node.js, Deno, Bun, Chromium) and a batteries-included test framework.",
|
"description": "A powerful, modern test runner for TypeScript with multi-runtime support (Node.js, Deno, Bun, Chromium) and a batteries-included test framework.",
|
||||||
"exports": {
|
"exports": {
|
||||||
@@ -25,11 +25,11 @@
|
|||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^4.3.0",
|
"@git.zone/tsbuild": "^4.4.0",
|
||||||
"@types/node": "^25.5.0"
|
"@types/node": "^25.5.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@git.zone/tsbundle": "^2.9.1",
|
"@git.zone/tsbundle": "^2.10.0",
|
||||||
"@git.zone/tsrun": "^2.0.1",
|
"@git.zone/tsrun": "^2.0.1",
|
||||||
"@push.rocks/consolecolor": "^2.0.3",
|
"@push.rocks/consolecolor": "^2.0.3",
|
||||||
"@push.rocks/qenv": "^6.1.3",
|
"@push.rocks/qenv": "^6.1.3",
|
||||||
@@ -47,14 +47,14 @@
|
|||||||
"@push.rocks/smartpath": "^6.0.0",
|
"@push.rocks/smartpath": "^6.0.0",
|
||||||
"@push.rocks/smartpromise": "^4.2.3",
|
"@push.rocks/smartpromise": "^4.2.3",
|
||||||
"@push.rocks/smartrequest": "^5.0.1",
|
"@push.rocks/smartrequest": "^5.0.1",
|
||||||
"@push.rocks/smartserve": "^2.0.1",
|
"@push.rocks/smartserve": "^2.0.3",
|
||||||
"@push.rocks/smartshell": "^3.3.8",
|
"@push.rocks/smartshell": "^3.3.8",
|
||||||
"@push.rocks/smartstorage": "^6.0.1",
|
"@push.rocks/smartstorage": "^6.3.2",
|
||||||
"@push.rocks/smarttime": "^4.2.3",
|
"@push.rocks/smarttime": "^4.2.3",
|
||||||
"@push.rocks/smartwatch": "^6.3.0",
|
"@push.rocks/smartwatch": "^6.4.0",
|
||||||
"@types/ws": "^8.18.1",
|
"@types/ws": "^8.18.1",
|
||||||
"figures": "^6.1.0",
|
"figures": "^6.1.0",
|
||||||
"ws": "^8.19.0"
|
"ws": "^8.20.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
".smartconfig.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
|
|||||||
752
pnpm-lock.yaml
generated
752
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -624,7 +624,7 @@ const messages = parser.parseLine('ok 1 - test ⟦TSTEST:time:42⟧');
|
|||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license.md) file.
|
||||||
|
|
||||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@git.zone/tstest',
|
name: '@git.zone/tstest',
|
||||||
version: '3.5.1',
|
version: '3.6.2',
|
||||||
description: 'A powerful, modern test runner for TypeScript with multi-runtime support (Node.js, Deno, Bun, Chromium) and a batteries-included test framework.'
|
description: 'A powerful, modern test runner for TypeScript with multi-runtime support (Node.js, Deno, Bun, Chromium) and a batteries-included test framework.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ export const runCli = async () => {
|
|||||||
await tsTestInstance.runWatch(watchIgnorePatterns);
|
await tsTestInstance.runWatch(watchIgnorePatterns);
|
||||||
} else {
|
} else {
|
||||||
await tsTestInstance.run();
|
await tsTestInstance.run();
|
||||||
|
await tsTestInstance.cleanup();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
147
ts/readme.md
Normal file
147
ts/readme.md
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
# @git.zone/tstest
|
||||||
|
|
||||||
|
> 🚀 Multi-runtime TypeScript test runner with beautiful output and intelligent test orchestration
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# tstest is the main CLI entry point
|
||||||
|
pnpm install --save-dev @git.zone/tstest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Issue Reporting and Security
|
||||||
|
|
||||||
|
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
This is the core test runner module of `@git.zone/tstest`. It provides the CLI, test discovery, multi-runtime execution, TAP output parsing, structured logging, and test orchestration. It ties together the entire testing pipeline — from finding test files to dispatching them across Node.js, Chromium, Deno, Bun, and Docker runtimes.
|
||||||
|
|
||||||
|
## Key Features
|
||||||
|
|
||||||
|
- 🔍 **Smart Test Discovery** — Glob patterns, directory scanning, and single-file mode
|
||||||
|
- 🏃 **Multi-Runtime Execution** — Node.js, Chromium, Deno, Bun, and Docker adapters
|
||||||
|
- 📊 **TAP Protocol Parsing** — Full Protocol V2 support with structured metadata
|
||||||
|
- 🎨 **Rich Logging** — Color-coded output, JSON mode, per-file log files, diff tracking
|
||||||
|
- ⚡ **Parallel Execution** — File-level parallel groups via `*.para__N.*` naming
|
||||||
|
- 👀 **Watch Mode** — Re-run tests on file changes with debouncing
|
||||||
|
- 🏷️ **Tag Filtering** — Run only tests matching specific tags
|
||||||
|
- ⏱️ **Timeout Management** — Per-file timeouts with process tree termination
|
||||||
|
- 📝 **Test File Directives** — Inline comments to configure runtime permissions and flags
|
||||||
|
- 🔄 **Before Scripts** — `package.json`-based lifecycle hooks (`test:before`, `test:before:testfile`)
|
||||||
|
- 🐳 **Docker Testing** — Run tests inside Docker containers via `*.docker.sh` files
|
||||||
|
- 🔀 **Legacy Migration** — Automatic rename of `.browser.ts` → `.chromium.ts` patterns
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
### Runtime Adapter System
|
||||||
|
|
||||||
|
Each runtime is implemented as a `RuntimeAdapter` with a unified interface:
|
||||||
|
|
||||||
|
| Adapter | Runtime | How It Executes Tests |
|
||||||
|
|---|---|---|
|
||||||
|
| `NodeRuntimeAdapter` | Node.js | Spawns via `@git.zone/tsrun`, streams TAP output |
|
||||||
|
| `ChromiumRuntimeAdapter` | Chromium | Bundles with esbuild, serves over HTTP, communicates via WebSocket |
|
||||||
|
| `DenoRuntimeAdapter` | Deno | Runs `deno run` with configurable permissions |
|
||||||
|
| `BunRuntimeAdapter` | Bun | Runs `bun run` with auto-discovered config |
|
||||||
|
| `DockerRuntimeAdapter` | Docker | Builds image from Dockerfile, runs `docker run` |
|
||||||
|
|
||||||
|
### Test File Naming Convention
|
||||||
|
|
||||||
|
Test filenames determine which runtime(s) execute them:
|
||||||
|
|
||||||
|
| Pattern | Runtimes |
|
||||||
|
|---|---|
|
||||||
|
| `*.ts` | Node.js (default) |
|
||||||
|
| `*.node.ts` | Node.js only |
|
||||||
|
| `*.chromium.ts` | Chromium browser |
|
||||||
|
| `*.deno.ts` | Deno |
|
||||||
|
| `*.bun.ts` | Bun |
|
||||||
|
| `*.all.ts` | All runtimes |
|
||||||
|
| `*.node+chromium.ts` | Node.js + Chromium |
|
||||||
|
| `*.para__N.ts` | Parallel group N |
|
||||||
|
| `*.docker.sh` | Docker container |
|
||||||
|
|
||||||
|
### Execution Flow
|
||||||
|
|
||||||
|
1. **Discovery** — `TestDirectory` scans for test files based on mode (directory/file/glob)
|
||||||
|
2. **Grouping** — Files are split into serial and parallel groups (via `*.para__N.*` naming)
|
||||||
|
3. **Before Scripts** — `test:before` / `test:before:testfile` from `package.json` run
|
||||||
|
4. **Dispatch** — Each file is parsed for runtime specifiers and directives, then routed to the appropriate `RuntimeAdapter`
|
||||||
|
5. **Parsing** — `TapParser` processes TAP output using Protocol V2, tracking results and events
|
||||||
|
6. **Aggregation** — `TapCombinator` merges results from all test files
|
||||||
|
7. **Reporting** — `TsTestLogger` outputs structured results (console, JSON, or log files)
|
||||||
|
|
||||||
|
### Inline Directives
|
||||||
|
|
||||||
|
Test files can include comment directives at the top (before imports) to configure runtime behavior:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// tstest:deno:allowAll
|
||||||
|
// tstest:node:flag:--max-old-space-size=4096
|
||||||
|
// tstest:env:MY_VAR=value
|
||||||
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
|
```
|
||||||
|
|
||||||
|
Directives in `00init.ts` files apply to all tests in that directory and are merged with per-file directives.
|
||||||
|
|
||||||
|
## CLI Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Directory mode — scan recursively for test files
|
||||||
|
tstest test/
|
||||||
|
|
||||||
|
# File mode — run a single test
|
||||||
|
tstest test/test.math.ts
|
||||||
|
|
||||||
|
# Glob mode — match patterns
|
||||||
|
tstest "test/**/*.node.ts"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
| Flag | Description |
|
||||||
|
|---|---|
|
||||||
|
| `--verbose`, `-v` | Show all console output from tests |
|
||||||
|
| `--quiet`, `-q` | Minimal output for CI |
|
||||||
|
| `--json` | Machine-readable JSON output |
|
||||||
|
| `--logfile` | Write per-file logs to `.nogit/testlogs/` |
|
||||||
|
| `--tags <tags>` | Filter tests by comma-separated tags |
|
||||||
|
| `--timeout <sec>` | Per-file timeout in seconds |
|
||||||
|
| `--startFrom <n>` | Start from file number N |
|
||||||
|
| `--stopAt <n>` | Stop at file number N |
|
||||||
|
| `--watch`, `-w` | Re-run tests on file changes |
|
||||||
|
| `--watch-ignore <pat>` | Comma-separated ignore patterns |
|
||||||
|
| `--no-color` | Disable ANSI colors |
|
||||||
|
|
||||||
|
## Public API
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { runCli, TestExecutionMode } from '@git.zone/tstest';
|
||||||
|
```
|
||||||
|
|
||||||
|
| Export | Type | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `runCli()` | `async function` | CLI entry point — parses `process.argv` and runs tests |
|
||||||
|
| `TestExecutionMode` | `enum` | `DIRECTORY`, `FILE`, or `GLOB` |
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](../license.md) file.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
||||||
|
|
||||||
|
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
@@ -103,7 +103,7 @@ export class ChromiumRuntimeAdapter extends RuntimeAdapter {
|
|||||||
|
|
||||||
// lets get all our paths sorted
|
// lets get all our paths sorted
|
||||||
const tsbundleCacheDirPath = plugins.path.join(paths.cwd, './.nogit/tstest_cache');
|
const tsbundleCacheDirPath = plugins.path.join(paths.cwd, './.nogit/tstest_cache');
|
||||||
const bundleFileName = testFile.replace('/', '__') + '.js';
|
const bundleFileName = testFile.replaceAll('/', '__') + '.js';
|
||||||
const bundleFilePath = plugins.path.join(tsbundleCacheDirPath, bundleFileName);
|
const bundleFilePath = plugins.path.join(tsbundleCacheDirPath, bundleFileName);
|
||||||
|
|
||||||
// lets bundle the test
|
// lets bundle the test
|
||||||
@@ -159,7 +159,7 @@ export class ChromiumRuntimeAdapter extends RuntimeAdapter {
|
|||||||
await this.smartbrowserInstance.start();
|
await this.smartbrowserInstance.start();
|
||||||
|
|
||||||
const evaluatePromise = this.smartbrowserInstance.evaluateOnPage(
|
const evaluatePromise = this.smartbrowserInstance.evaluateOnPage(
|
||||||
`http://localhost:${httpPort}/test?bundleName=${bundleFileName}`,
|
`http://localhost:${httpPort}/test?bundleName=${encodeURIComponent(bundleFileName)}`,
|
||||||
async () => {
|
async () => {
|
||||||
// lets enable real time comms
|
// lets enable real time comms
|
||||||
const ws = new WebSocket(`ws://localhost:${globalThis.wsPort}`);
|
const ws = new WebSocket(`ws://localhost:${globalThis.wsPort}`);
|
||||||
@@ -277,6 +277,9 @@ export class ChromiumRuntimeAdapter extends RuntimeAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
for (const client of wss.clients) {
|
||||||
|
client.terminate();
|
||||||
|
}
|
||||||
wss.close();
|
wss.close();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// WebSocket server might already be closed
|
// WebSocket server might already be closed
|
||||||
|
|||||||
@@ -159,6 +159,13 @@ export class TsTest {
|
|||||||
tapCombinator.evaluate();
|
tapCombinator.evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up all long-lived resources so the Node.js event loop can drain naturally.
|
||||||
|
*/
|
||||||
|
public async cleanup() {
|
||||||
|
this.smartshellInstance.smartexit.deregister();
|
||||||
|
}
|
||||||
|
|
||||||
public async runWatch(ignorePatterns: string[] = []) {
|
public async runWatch(ignorePatterns: string[] = []) {
|
||||||
const smartwatchInstance = new plugins.smartwatch.Smartwatch([this.testDir.cwd]);
|
const smartwatchInstance = new plugins.smartwatch.Smartwatch([this.testDir.cwd]);
|
||||||
|
|
||||||
@@ -386,341 +393,6 @@ export class TsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async runInNode(fileNameArg: string, index: number, total: number): Promise<TapParser> {
|
|
||||||
this.logger.testFileStart(fileNameArg, 'node.js', index, total);
|
|
||||||
const tapParser = new TapParser(fileNameArg + ':node', this.logger);
|
|
||||||
|
|
||||||
// tsrun options
|
|
||||||
let tsrunOptions = '';
|
|
||||||
if (process.argv.includes('--web')) {
|
|
||||||
tsrunOptions += ' --web';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set filter tags as environment variable
|
|
||||||
if (this.filterTags.length > 0) {
|
|
||||||
process.env.TSTEST_FILTER_TAGS = this.filterTags.join(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for 00init.ts file in test directory
|
|
||||||
const testDir = plugins.path.dirname(fileNameArg);
|
|
||||||
const initFile = plugins.path.join(testDir, '00init.ts');
|
|
||||||
let runCommand = `tsrun ${fileNameArg}${tsrunOptions}`;
|
|
||||||
|
|
||||||
const initFileExists = await plugins.smartfsInstance.file(initFile).exists();
|
|
||||||
|
|
||||||
// If 00init.ts exists, run it first
|
|
||||||
if (initFileExists) {
|
|
||||||
// Create a temporary loader file that imports both 00init.ts and the test file
|
|
||||||
const absoluteInitFile = plugins.path.resolve(initFile);
|
|
||||||
const absoluteTestFile = plugins.path.resolve(fileNameArg);
|
|
||||||
const loaderContent = `
|
|
||||||
import '${absoluteInitFile.replace(/\\/g, '/')}';
|
|
||||||
import '${absoluteTestFile.replace(/\\/g, '/')}';
|
|
||||||
`;
|
|
||||||
const loaderPath = plugins.path.join(testDir, `.loader_${plugins.path.basename(fileNameArg)}`);
|
|
||||||
await plugins.smartfsInstance.file(loaderPath).write(loaderContent);
|
|
||||||
runCommand = `tsrun ${loaderPath}${tsrunOptions}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const execResultStreaming = await this.smartshellInstance.execStreamingSilent(runCommand);
|
|
||||||
|
|
||||||
// If we created a loader file, clean it up after test execution
|
|
||||||
if (initFileExists) {
|
|
||||||
const loaderPath = plugins.path.join(testDir, `.loader_${plugins.path.basename(fileNameArg)}`);
|
|
||||||
const cleanup = () => {
|
|
||||||
try {
|
|
||||||
if (plugins.fs.existsSync(loaderPath)) {
|
|
||||||
plugins.fs.rmSync(loaderPath, { force: true });
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// Ignore cleanup errors
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
execResultStreaming.childProcess.on('exit', cleanup);
|
|
||||||
execResultStreaming.childProcess.on('error', cleanup);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start warning timer if no timeout was specified
|
|
||||||
let warningTimer: NodeJS.Timeout | null = null;
|
|
||||||
if (this.timeoutSeconds === null) {
|
|
||||||
warningTimer = setTimeout(() => {
|
|
||||||
console.error('');
|
|
||||||
console.error(cs('⚠️ WARNING: Test file is running for more than 1 minute', 'orange'));
|
|
||||||
console.error(cs(` File: ${fileNameArg}`, 'orange'));
|
|
||||||
console.error(cs(' Consider using --timeout option to set a timeout for test files.', 'orange'));
|
|
||||||
console.error(cs(' Example: tstest test --timeout=300 (for 5 minutes)', 'orange'));
|
|
||||||
console.error('');
|
|
||||||
}, 60000); // 1 minute
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle timeout if specified
|
|
||||||
if (this.timeoutSeconds !== null) {
|
|
||||||
const timeoutMs = this.timeoutSeconds * 1000;
|
|
||||||
let timeoutId: NodeJS.Timeout;
|
|
||||||
|
|
||||||
const timeoutPromise = new Promise<void>((_resolve, reject) => {
|
|
||||||
timeoutId = setTimeout(async () => {
|
|
||||||
// Use smartshell's terminate() to kill entire process tree
|
|
||||||
await execResultStreaming.terminate();
|
|
||||||
reject(new Error(`Test file timed out after ${this.timeoutSeconds} seconds`));
|
|
||||||
}, timeoutMs);
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
await Promise.race([
|
|
||||||
tapParser.handleTapProcess(execResultStreaming.childProcess),
|
|
||||||
timeoutPromise
|
|
||||||
]);
|
|
||||||
// Clear timeout if test completed successfully
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
} catch (error) {
|
|
||||||
// Clear warning timer if it was set
|
|
||||||
if (warningTimer) {
|
|
||||||
clearTimeout(warningTimer);
|
|
||||||
}
|
|
||||||
// Handle timeout error
|
|
||||||
tapParser.handleTimeout(this.timeoutSeconds);
|
|
||||||
// Ensure entire process tree is killed if still running
|
|
||||||
try {
|
|
||||||
await execResultStreaming.kill(); // This kills the entire process tree with SIGKILL
|
|
||||||
} catch (killError) {
|
|
||||||
// Process tree might already be dead
|
|
||||||
}
|
|
||||||
await tapParser.evaluateFinalResult();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await tapParser.handleTapProcess(execResultStreaming.childProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear warning timer if it was set
|
|
||||||
if (warningTimer) {
|
|
||||||
clearTimeout(warningTimer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tapParser;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async findFreePorts(): Promise<{ httpPort: number; wsPort: number }> {
|
|
||||||
const smartnetwork = new plugins.smartnetwork.SmartNetwork();
|
|
||||||
|
|
||||||
// Find random free HTTP port in range 30000-40000 to minimize collision chance
|
|
||||||
const httpPort = await smartnetwork.findFreePort(30000, 40000, { randomize: true });
|
|
||||||
if (!httpPort) {
|
|
||||||
throw new Error('Could not find a free HTTP port in range 30000-40000');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find random free WebSocket port, excluding the HTTP port to ensure they're different
|
|
||||||
const wsPort = await smartnetwork.findFreePort(30000, 40000, {
|
|
||||||
randomize: true,
|
|
||||||
exclude: [httpPort]
|
|
||||||
});
|
|
||||||
if (!wsPort) {
|
|
||||||
throw new Error('Could not find a free WebSocket port in range 30000-40000');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log selected ports for debugging
|
|
||||||
if (!this.logger.options.quiet) {
|
|
||||||
console.log(`Selected ports - HTTP: ${httpPort}, WebSocket: ${wsPort}`);
|
|
||||||
}
|
|
||||||
return { httpPort, wsPort };
|
|
||||||
}
|
|
||||||
|
|
||||||
public async runInChrome(fileNameArg: string, index: number, total: number): Promise<TapParser> {
|
|
||||||
this.logger.testFileStart(fileNameArg, 'chromium', index, total);
|
|
||||||
|
|
||||||
// lets get all our paths sorted
|
|
||||||
const tsbundleCacheDirPath = plugins.path.join(paths.cwd, './.nogit/tstest_cache');
|
|
||||||
const bundleFileName = fileNameArg.replace('/', '__') + '.js';
|
|
||||||
const bundleFilePath = plugins.path.join(tsbundleCacheDirPath, bundleFileName);
|
|
||||||
|
|
||||||
// lets bundle the test
|
|
||||||
try { await plugins.smartfsInstance.directory(tsbundleCacheDirPath).recursive().delete(); } catch (e) { /* may not exist */ }
|
|
||||||
await plugins.smartfsInstance.directory(tsbundleCacheDirPath).recursive().create();
|
|
||||||
await this.tsbundleInstance.build(process.cwd(), fileNameArg, bundleFilePath, {
|
|
||||||
bundler: 'esbuild',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Find free ports for HTTP and WebSocket
|
|
||||||
const { httpPort, wsPort } = await this.findFreePorts();
|
|
||||||
|
|
||||||
// Use SmartServe with setHandler() to bypass global ControllerRegistry
|
|
||||||
const fileServer = new plugins.smartserve.FileServer({ root: tsbundleCacheDirPath });
|
|
||||||
const server = new plugins.smartserve.SmartServe({ port: httpPort });
|
|
||||||
server.setHandler(async (request: Request) => {
|
|
||||||
const url = new URL(request.url);
|
|
||||||
if (url.pathname === '/test') {
|
|
||||||
return new Response(`
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<script>
|
|
||||||
globalThis.testdom = true;
|
|
||||||
globalThis.wsPort = ${wsPort};
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body></body>
|
|
||||||
</html>
|
|
||||||
`, { headers: { 'Content-Type': 'text/html' } });
|
|
||||||
}
|
|
||||||
const staticResponse = await fileServer.serve(request);
|
|
||||||
if (staticResponse) return staticResponse;
|
|
||||||
return new Response('Not Found', { status: 404 });
|
|
||||||
});
|
|
||||||
await server.start();
|
|
||||||
|
|
||||||
// lets handle realtime comms
|
|
||||||
const tapParser = new TapParser(fileNameArg + ':chrome', this.logger);
|
|
||||||
const wss = new plugins.ws.WebSocketServer({ port: wsPort });
|
|
||||||
wss.on('connection', (ws) => {
|
|
||||||
ws.on('message', (message) => {
|
|
||||||
const messageStr = message.toString();
|
|
||||||
if (messageStr.startsWith('console:')) {
|
|
||||||
const [, level, ...messageParts] = messageStr.split(':');
|
|
||||||
this.logger.browserConsole(messageParts.join(':'), level);
|
|
||||||
} else {
|
|
||||||
tapParser.handleTapLog(messageStr);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// lets do the browser bit with timeout handling
|
|
||||||
await this.smartbrowserInstance.start();
|
|
||||||
|
|
||||||
const evaluatePromise = this.smartbrowserInstance.evaluateOnPage(
|
|
||||||
`http://localhost:${httpPort}/test?bundleName=${bundleFileName}`,
|
|
||||||
async () => {
|
|
||||||
// lets enable real time comms
|
|
||||||
const ws = new WebSocket(`ws://localhost:${globalThis.wsPort}`);
|
|
||||||
await new Promise((resolve) => (ws.onopen = resolve));
|
|
||||||
|
|
||||||
// Ensure this function is declared with 'async'
|
|
||||||
const logStore = [];
|
|
||||||
const originalLog = console.log;
|
|
||||||
const originalError = console.error;
|
|
||||||
|
|
||||||
// Override console methods to capture the logs
|
|
||||||
console.log = (...args: any[]) => {
|
|
||||||
logStore.push(args.join(' '));
|
|
||||||
ws.send(args.join(' '));
|
|
||||||
originalLog(...args);
|
|
||||||
};
|
|
||||||
console.error = (...args: any[]) => {
|
|
||||||
logStore.push(args.join(' '));
|
|
||||||
ws.send(args.join(' '));
|
|
||||||
originalError(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
const bundleName = new URLSearchParams(window.location.search).get('bundleName');
|
|
||||||
originalLog(`::TSTEST IN CHROMIUM:: Relevant Script name is: ${bundleName}`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Dynamically import the test module
|
|
||||||
const testModule = await import(`/${bundleName}`);
|
|
||||||
if (testModule && testModule.default && testModule.default instanceof Promise) {
|
|
||||||
// Execute the exported test function
|
|
||||||
await testModule.default;
|
|
||||||
} else if (testModule && testModule.default && typeof testModule.default.then === 'function') {
|
|
||||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
|
||||||
console.log('Test module default export is just promiselike: Something might be messing with your Promise implementation.');
|
|
||||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
|
||||||
await testModule.default;
|
|
||||||
} else if (globalThis.tapPromise && typeof globalThis.tapPromise.then === 'function') {
|
|
||||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
|
||||||
console.log('Using globalThis.tapPromise');
|
|
||||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
|
||||||
await testModule.default;
|
|
||||||
} else {
|
|
||||||
console.error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
|
||||||
console.error('Test module does not export a default promise.');
|
|
||||||
console.error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
|
||||||
console.log(`We got: ${JSON.stringify(testModule)}`);
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
return logStore.join('\n');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Start warning timer if no timeout was specified
|
|
||||||
let warningTimer: NodeJS.Timeout | null = null;
|
|
||||||
if (this.timeoutSeconds === null) {
|
|
||||||
warningTimer = setTimeout(() => {
|
|
||||||
console.error('');
|
|
||||||
console.error(cs('⚠️ WARNING: Test file is running for more than 1 minute', 'orange'));
|
|
||||||
console.error(cs(` File: ${fileNameArg}`, 'orange'));
|
|
||||||
console.error(cs(' Consider using --timeout option to set a timeout for test files.', 'orange'));
|
|
||||||
console.error(cs(' Example: tstest test --timeout=300 (for 5 minutes)', 'orange'));
|
|
||||||
console.error('');
|
|
||||||
}, 60000); // 1 minute
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle timeout if specified
|
|
||||||
if (this.timeoutSeconds !== null) {
|
|
||||||
const timeoutMs = this.timeoutSeconds * 1000;
|
|
||||||
let timeoutId: NodeJS.Timeout;
|
|
||||||
|
|
||||||
const timeoutPromise = new Promise<void>((_resolve, reject) => {
|
|
||||||
timeoutId = setTimeout(() => {
|
|
||||||
reject(new Error(`Test file timed out after ${this.timeoutSeconds} seconds`));
|
|
||||||
}, timeoutMs);
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
await Promise.race([
|
|
||||||
evaluatePromise,
|
|
||||||
timeoutPromise
|
|
||||||
]);
|
|
||||||
// Clear timeout if test completed successfully
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
} catch (error) {
|
|
||||||
// Clear warning timer if it was set
|
|
||||||
if (warningTimer) {
|
|
||||||
clearTimeout(warningTimer);
|
|
||||||
}
|
|
||||||
// Handle timeout error
|
|
||||||
tapParser.handleTimeout(this.timeoutSeconds);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await evaluatePromise;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear warning timer if it was set
|
|
||||||
if (warningTimer) {
|
|
||||||
clearTimeout(warningTimer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always clean up resources, even on timeout
|
|
||||||
try {
|
|
||||||
await this.smartbrowserInstance.stop();
|
|
||||||
} catch (error) {
|
|
||||||
// Browser might already be stopped
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await server.stop();
|
|
||||||
} catch (error) {
|
|
||||||
// Server might already be stopped
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
wss.close();
|
|
||||||
} catch (error) {
|
|
||||||
// WebSocket server might already be closed
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`${cs('=> ', 'blue')} Stopped ${cs(fileNameArg, 'orange')} chromium instance and server.`
|
|
||||||
);
|
|
||||||
// Always evaluate final result (handleTimeout just sets up the test state)
|
|
||||||
await tapParser.evaluateFinalResult();
|
|
||||||
return tapParser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async runInDeno() {}
|
|
||||||
|
|
||||||
private async movePreviousLogFiles() {
|
private async movePreviousLogFiles() {
|
||||||
const logDir = plugins.path.join('.nogit', 'testlogs');
|
const logDir = plugins.path.join('.nogit', 'testlogs');
|
||||||
const previousDir = plugins.path.join('.nogit', 'testlogs', 'previous');
|
const previousDir = plugins.path.join('.nogit', 'testlogs', 'previous');
|
||||||
|
|||||||
@@ -615,7 +615,7 @@ tap.test('should use context', async (tapTools) => {
|
|||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](../LICENSE) file.
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](../license.md) file.
|
||||||
|
|
||||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
|||||||
@@ -586,7 +586,7 @@ No runtime-specific APIs are used, making it truly portable.
|
|||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](../LICENSE) file.
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](../license.md) file.
|
||||||
|
|
||||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ test/mytest.all.ts ❌ Will fail in Deno/Bun/Chromium
|
|||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](../LICENSE) file.
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](../license.md) file.
|
||||||
|
|
||||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"strict": false,
|
||||||
|
"types": ["node"]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist_*/**/*.d.ts"
|
"dist_*/**/*.d.ts"
|
||||||
|
|||||||
Reference in New Issue
Block a user