Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8435c45b4b | |||
| 18904d18e8 | |||
| a048c5a4d0 | |||
| 5563154fd9 | |||
| 8e53e5143e | |||
| cf4e5c33e8 | |||
| bc39793682 | |||
| edce15b20a |
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"fileMatch": ["/.smartconfig.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
30
changelog.md
30
changelog.md
@@ -1,5 +1,35 @@
|
||||
# Changelog
|
||||
|
||||
## 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)
|
||||
handle expected exitCode rejection after terminating timed out test processes
|
||||
|
||||
- swallow the child process exitCode rejection triggered by timeout termination
|
||||
- reduce unhandled rejection noise when test files exceed the configured timeout
|
||||
|
||||
## 2026-03-19 - 3.5.0 - feat(tstest)
|
||||
add support for package.json before scripts during test execution
|
||||
|
||||
- load test:before or test:before:once once per test run from package.json scripts
|
||||
- run test:before:testfile before each test file execution and pass TSTEST_FILE and TSTEST_RUNTIME environment variables
|
||||
- log before-script lifecycle events and abort or skip execution when setup scripts fail
|
||||
|
||||
## 2026-03-18 - 3.4.0 - feat(tapbundle,deno)
|
||||
replace smarts3 test tooling with smartstorage and pre-resolve Deno test dependencies
|
||||
|
||||
- switch TapNodeTools storage helper from @push.rocks/smarts3 to @push.rocks/smartstorage and rename createSmarts3() to createSmartStorage()
|
||||
- update node tests and tapbundle server-side documentation to use the new smartstorage helper
|
||||
- run `deno install --entrypoint` before executing Deno tests to resolve dependencies up front
|
||||
- bump supporting development dependencies including @types/node and @push.rocks/smartshell
|
||||
|
||||
## 2026-03-09 - 3.3.2 - fix(deps)
|
||||
bump dependency versions and reorder smartserve in package.json
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
"target": "ES2022"
|
||||
},
|
||||
"nodeModulesDir": true,
|
||||
"version": "3.3.2"
|
||||
"version": "3.6.0"
|
||||
}
|
||||
|
||||
20
package.json
20
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@git.zone/tstest",
|
||||
"version": "3.3.2",
|
||||
"version": "3.6.0",
|
||||
"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.",
|
||||
"exports": {
|
||||
@@ -25,11 +25,11 @@
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^4.3.0",
|
||||
"@types/node": "^25.3.5"
|
||||
"@git.zone/tsbuild": "^4.4.0",
|
||||
"@types/node": "^25.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@git.zone/tsbundle": "^2.9.1",
|
||||
"@git.zone/tsbundle": "^2.10.0",
|
||||
"@git.zone/tsrun": "^2.0.1",
|
||||
"@push.rocks/consolecolor": "^2.0.3",
|
||||
"@push.rocks/qenv": "^6.1.3",
|
||||
@@ -47,14 +47,14 @@
|
||||
"@push.rocks/smartpath": "^6.0.0",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smartrequest": "^5.0.1",
|
||||
"@push.rocks/smarts3": "^5.3.0",
|
||||
"@push.rocks/smartserve": "^2.0.1",
|
||||
"@push.rocks/smartshell": "^3.3.7",
|
||||
"@push.rocks/smartserve": "^2.0.3",
|
||||
"@push.rocks/smartshell": "^3.3.8",
|
||||
"@push.rocks/smartstorage": "^6.3.2",
|
||||
"@push.rocks/smarttime": "^4.2.3",
|
||||
"@push.rocks/smartwatch": "^6.3.0",
|
||||
"@push.rocks/smartwatch": "^6.4.0",
|
||||
"@types/ws": "^8.18.1",
|
||||
"figures": "^6.1.0",
|
||||
"ws": "^8.19.0"
|
||||
"ws": "^8.20.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@@ -65,7 +65,7 @@
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
".smartconfig.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
|
||||
1078
pnpm-lock.yaml
generated
1078
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
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ tap.test('should create a smartmongo instance', async () => {
|
||||
await smartmongo.stop();
|
||||
});
|
||||
|
||||
tap.test('should create a smarts3 instance', async () => {
|
||||
const smarts3 = await tapNodeTools.createSmarts3();
|
||||
await smarts3.stop();
|
||||
tap.test('should create a smartstorage instance', async () => {
|
||||
const smartstorage = await tapNodeTools.createSmartStorage();
|
||||
await smartstorage.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tstest',
|
||||
version: '3.3.2',
|
||||
version: '3.6.0',
|
||||
description: 'A powerful, modern test runner for TypeScript with multi-runtime support (Node.js, Deno, Bun, Chromium) and a batteries-included test framework.'
|
||||
}
|
||||
|
||||
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.
|
||||
86
ts/tstest.classes.beforescripts.ts
Normal file
86
ts/tstest.classes.beforescripts.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import * as plugins from './tstest.plugins.js';
|
||||
import type { TsTestLogger } from './tstest.logging.js';
|
||||
import type { Smartshell } from '@push.rocks/smartshell';
|
||||
|
||||
export interface IBeforeScripts {
|
||||
/** The "test:before" or "test:before:once" script command, or null if not defined */
|
||||
beforeOnce: string | null;
|
||||
/** The "test:before:testfile" script command, or null if not defined */
|
||||
beforeTestfile: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load before-script commands from the project's package.json scripts section.
|
||||
*/
|
||||
export function loadBeforeScripts(cwd: string): IBeforeScripts {
|
||||
const result: IBeforeScripts = { beforeOnce: null, beforeTestfile: null };
|
||||
|
||||
try {
|
||||
const packageJsonPath = plugins.path.join(cwd, 'package.json');
|
||||
const packageJson = JSON.parse(plugins.fs.readFileSync(packageJsonPath, 'utf8'));
|
||||
const scripts = packageJson?.scripts;
|
||||
if (!scripts) return result;
|
||||
|
||||
// test:before takes precedence over test:before:once (they are aliases)
|
||||
if (scripts['test:before']) {
|
||||
result.beforeOnce = scripts['test:before'];
|
||||
if (scripts['test:before:once']) {
|
||||
console.warn('Warning: Both "test:before" and "test:before:once" are defined. Using "test:before".');
|
||||
}
|
||||
} else if (scripts['test:before:once']) {
|
||||
result.beforeOnce = scripts['test:before:once'];
|
||||
}
|
||||
|
||||
if (scripts['test:before:testfile']) {
|
||||
result.beforeTestfile = scripts['test:before:testfile'];
|
||||
}
|
||||
} catch {
|
||||
// No package.json or parse error — return defaults
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a before-script command and return whether it succeeded.
|
||||
*/
|
||||
export async function runBeforeScript(
|
||||
smartshellInstance: Smartshell,
|
||||
command: string,
|
||||
label: string,
|
||||
logger: TsTestLogger,
|
||||
env?: { TSTEST_FILE?: string; TSTEST_RUNTIME?: string },
|
||||
): Promise<boolean> {
|
||||
logger.beforeScriptStart(label, command);
|
||||
const startTime = Date.now();
|
||||
|
||||
// Set environment variables if provided
|
||||
const envKeysSet: string[] = [];
|
||||
if (env) {
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
if (value !== undefined) {
|
||||
process.env[key] = value;
|
||||
envKeysSet.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const execResult = await smartshellInstance.execStreaming(command);
|
||||
const result = await execResult.finalPromise;
|
||||
const durationMs = Date.now() - startTime;
|
||||
const success = result.exitCode === 0;
|
||||
|
||||
logger.beforeScriptEnd(label, success, durationMs);
|
||||
return success;
|
||||
} catch {
|
||||
const durationMs = Date.now() - startTime;
|
||||
logger.beforeScriptEnd(label, false, durationMs);
|
||||
return false;
|
||||
} finally {
|
||||
// Clean up environment variables
|
||||
for (const key of envKeysSet) {
|
||||
delete process.env[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,6 +190,17 @@ import '${absoluteTestFile.replace(/\\/g, '/')}';
|
||||
runCommand = `${loaderCommand.command} ${loaderCommand.args.join(' ')}`;
|
||||
}
|
||||
|
||||
// Pre-resolve dependencies for the Deno test entrypoint
|
||||
const installTarget = loaderPath || testFile;
|
||||
const installArgs = ['install', '--entrypoint', installTarget];
|
||||
if (mergedOptions.configPath) {
|
||||
installArgs.push('--config', mergedOptions.configPath);
|
||||
}
|
||||
const installCommand = `deno ${installArgs.join(' ')}`;
|
||||
console.log(cs(` ⏳ Resolving Deno dependencies for ${plugins.path.basename(testFile)}...`, 'blue'));
|
||||
await this.smartshellInstance.execSilent(installCommand, { cwd: process.cwd() });
|
||||
console.log(cs(` ✓ Deno dependencies resolved`, 'green'));
|
||||
|
||||
const execResultStreaming = await this.smartshellInstance.execStreamingSilent(runCommand);
|
||||
|
||||
// If we created a loader file, clean it up after test execution
|
||||
|
||||
@@ -184,6 +184,8 @@ import '${absoluteTestFile.replace(/\\/g, '/')}';
|
||||
timeoutId = setTimeout(async () => {
|
||||
// Use tsrun's terminate() to gracefully kill the process
|
||||
await tsrunProcess.terminate();
|
||||
// Swallow the expected rejection from the killed child process
|
||||
tsrunProcess.exitCode.catch(() => {});
|
||||
reject(new Error(`Test file timed out after ${this.timeoutSeconds} seconds`));
|
||||
}, timeoutMs);
|
||||
});
|
||||
|
||||
@@ -27,6 +27,9 @@ import {
|
||||
hasDirectives,
|
||||
} from './tstest.classes.testfile.directives.js';
|
||||
|
||||
// Before-script support
|
||||
import { loadBeforeScripts, runBeforeScript, type IBeforeScripts } from './tstest.classes.beforescripts.js';
|
||||
|
||||
export class TsTest {
|
||||
public testDir: TestDirectory;
|
||||
public executionMode: TestExecutionMode;
|
||||
@@ -48,6 +51,8 @@ export class TsTest {
|
||||
public runtimeRegistry = new RuntimeAdapterRegistry();
|
||||
public dockerAdapter: DockerRuntimeAdapter | null = null;
|
||||
|
||||
private beforeScripts: IBeforeScripts | null = null;
|
||||
|
||||
constructor(cwdArg: string, testPathArg: string, executionModeArg: TestExecutionMode, logOptions: LogOptions = {}, tags: string[] = [], startFromFile: number | null = null, stopAtFile: number | null = null, timeoutSeconds: number | null = null) {
|
||||
this.executionMode = executionModeArg;
|
||||
this.testDir = new TestDirectory(cwdArg, testPathArg, executionModeArg);
|
||||
@@ -98,6 +103,21 @@ export class TsTest {
|
||||
await this.movePreviousLogFiles();
|
||||
}
|
||||
|
||||
// Load and execute test:before script (runs once per test run)
|
||||
this.beforeScripts = loadBeforeScripts(this.testDir.cwd);
|
||||
if (this.beforeScripts.beforeOnce) {
|
||||
const success = await runBeforeScript(
|
||||
this.smartshellInstance,
|
||||
this.beforeScripts.beforeOnce,
|
||||
'test:before',
|
||||
this.logger,
|
||||
);
|
||||
if (!success) {
|
||||
this.logger.error('test:before script failed. Aborting test run.');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const testGroups = await this.testDir.getTestFileGroups();
|
||||
const allFiles = [...testGroups.serial, ...Object.values(testGroups.parallelGroups).flat()];
|
||||
|
||||
@@ -280,6 +300,22 @@ export class TsTest {
|
||||
if (adapters.length === 1) {
|
||||
// Single runtime - no sections needed
|
||||
const adapter = adapters[0];
|
||||
|
||||
// Run test:before:testfile if defined
|
||||
if (this.beforeScripts?.beforeTestfile) {
|
||||
const success = await runBeforeScript(
|
||||
this.smartshellInstance,
|
||||
this.beforeScripts.beforeTestfile,
|
||||
`test:before:testfile (${fileName})`,
|
||||
this.logger,
|
||||
{ TSTEST_FILE: fileNameArg, TSTEST_RUNTIME: adapter.id },
|
||||
);
|
||||
if (!success) {
|
||||
this.logger.error(`test:before:testfile failed for ${fileName}. Skipping test file.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const options = hasDirectives(directives) ? directivesToRuntimeOptions(directives, adapter.id) : undefined;
|
||||
const tapParser = await adapter.run(fileNameArg, fileIndex, totalFiles, options);
|
||||
tapCombinator.addTapParser(tapParser);
|
||||
@@ -288,6 +324,23 @@ export class TsTest {
|
||||
for (let i = 0; i < adapters.length; i++) {
|
||||
const adapter = adapters[i];
|
||||
this.logger.sectionStart(`Part ${i + 1}: ${adapter.displayName}`);
|
||||
|
||||
// Run test:before:testfile if defined (runs before each runtime)
|
||||
if (this.beforeScripts?.beforeTestfile) {
|
||||
const success = await runBeforeScript(
|
||||
this.smartshellInstance,
|
||||
this.beforeScripts.beforeTestfile,
|
||||
`test:before:testfile (${fileName} on ${adapter.displayName})`,
|
||||
this.logger,
|
||||
{ TSTEST_FILE: fileNameArg, TSTEST_RUNTIME: adapter.id },
|
||||
);
|
||||
if (!success) {
|
||||
this.logger.error(`test:before:testfile failed for ${fileName} on ${adapter.displayName}. Skipping.`);
|
||||
this.logger.sectionEnd();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const options = hasDirectives(directives) ? directivesToRuntimeOptions(directives, adapter.id) : undefined;
|
||||
const tapParser = await adapter.run(fileNameArg, fileIndex, totalFiles, options);
|
||||
tapCombinator.addTapParser(tapParser);
|
||||
@@ -310,6 +363,21 @@ export class TsTest {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run test:before:testfile if defined
|
||||
if (this.beforeScripts?.beforeTestfile) {
|
||||
const success = await runBeforeScript(
|
||||
this.smartshellInstance,
|
||||
this.beforeScripts.beforeTestfile,
|
||||
`test:before:testfile (${fileNameArg} on Docker)`,
|
||||
this.logger,
|
||||
{ TSTEST_FILE: fileNameArg, TSTEST_RUNTIME: 'docker' },
|
||||
);
|
||||
if (!success) {
|
||||
this.logger.error(`test:before:testfile failed for ${fileNameArg}. Skipping.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const tapParser = await this.dockerAdapter.run(fileNameArg, fileIndex, totalFiles);
|
||||
tapCombinator.addTapParser(tapParser);
|
||||
|
||||
@@ -122,6 +122,40 @@ export class TsTestLogger {
|
||||
this.log(this.format(`[${'█'.repeat(filled)}${'░'.repeat(empty)}] ${message}`, 'dim'));
|
||||
}
|
||||
|
||||
// Before-script lifecycle hooks
|
||||
beforeScriptStart(label: string, command: string) {
|
||||
if (this.options.json) {
|
||||
this.logJson({ event: 'beforeScript', label, command });
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.options.quiet) {
|
||||
this.log(`Running ${label}...`);
|
||||
} else {
|
||||
this.log(this.format(`\n🔧 Running ${label}...`, 'cyan'));
|
||||
this.log(this.format(` Command: ${command}`, 'dim'));
|
||||
}
|
||||
}
|
||||
|
||||
beforeScriptEnd(label: string, success: boolean, durationMs: number) {
|
||||
const durationStr = durationMs >= 1000 ? `${(durationMs / 1000).toFixed(1)}s` : `${durationMs}ms`;
|
||||
|
||||
if (this.options.json) {
|
||||
this.logJson({ event: 'beforeScriptEnd', label, success, durationMs });
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.options.quiet) {
|
||||
this.log(success ? `${label} done (${durationStr})` : `${label} FAILED`);
|
||||
} else {
|
||||
if (success) {
|
||||
this.log(this.format(` ✓ ${label} completed (${durationStr})`, 'green'));
|
||||
} else {
|
||||
this.log(this.format(` ✗ ${label} failed (${durationStr})`, 'red'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test discovery
|
||||
testDiscovery(count: number, pattern: string, executionMode: string) {
|
||||
if (this.options.json) {
|
||||
|
||||
@@ -615,7 +615,7 @@ tap.test('should use context', async (tapTools) => {
|
||||
|
||||
## 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.
|
||||
|
||||
|
||||
@@ -586,7 +586,7 @@ No runtime-specific APIs are used, making it truly portable.
|
||||
|
||||
## 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.
|
||||
|
||||
|
||||
@@ -83,16 +83,15 @@ class TapNodeTools {
|
||||
}
|
||||
|
||||
/**
|
||||
* create and return a smarts3 instance
|
||||
* create and return a smartstorage instance
|
||||
*/
|
||||
public async createSmarts3() {
|
||||
const smarts3Mod = await import('@push.rocks/smarts3');
|
||||
const smarts3Instance = new smarts3Mod.Smarts3({
|
||||
public async createSmartStorage() {
|
||||
const smartstorageMod = await import('@push.rocks/smartstorage');
|
||||
const smartstorageInstance = await smartstorageMod.SmartStorage.createAndStart({
|
||||
server: { port: 3003 },
|
||||
storage: { cleanSlate: true },
|
||||
});
|
||||
await smarts3Instance.start();
|
||||
return smarts3Instance;
|
||||
return smartstorageInstance;
|
||||
}
|
||||
|
||||
// ============
|
||||
|
||||
@@ -207,12 +207,12 @@ Uses [@push.rocks/smartmongo](https://code.foss.global/push.rocks/smartmongo).
|
||||
Create a local S3-compatible storage instance for testing.
|
||||
|
||||
```typescript
|
||||
const s3 = await tapNodeTools.createSmarts3();
|
||||
const s3 = await tapNodeTools.createSmartStorage();
|
||||
// ... run storage tests ...
|
||||
await s3.stop();
|
||||
```
|
||||
|
||||
Default config: port 3003, clean slate enabled. Uses [@push.rocks/smarts3](https://code.foss.global/push.rocks/smarts3).
|
||||
Default config: port 3003, clean slate enabled. Uses [@push.rocks/smartstorage](https://code.foss.global/push.rocks/smartstorage).
|
||||
|
||||
---
|
||||
|
||||
@@ -244,13 +244,13 @@ test/mytest.all.ts ❌ Will fail in Deno/Bun/Chromium
|
||||
- [@push.rocks/smartshell](https://code.foss.global/push.rocks/smartshell) — Shell command execution
|
||||
- [@push.rocks/smartcrypto](https://code.foss.global/push.rocks/smartcrypto) — Certificate generation
|
||||
- [@push.rocks/smartmongo](https://code.foss.global/push.rocks/smartmongo) — MongoDB testing
|
||||
- [@push.rocks/smarts3](https://code.foss.global/push.rocks/smarts3) — S3 storage testing
|
||||
- [@push.rocks/smartstorage](https://code.foss.global/push.rocks/smartstorage) — S3 storage testing
|
||||
- [@push.rocks/smartfile](https://code.foss.global/push.rocks/smartfile) — File operations
|
||||
- [@push.rocks/smartrequest](https://code.foss.global/push.rocks/smartrequest) — HTTP requests
|
||||
|
||||
## 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.
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
"verbatimModuleSyntax": true,
|
||||
"strict": false,
|
||||
"types": ["node"]
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
|
||||
Reference in New Issue
Block a user