Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e53e5143e | |||
| cf4e5c33e8 | |||
| bc39793682 | |||
| edce15b20a | |||
| 9d34a3511a | |||
| 300e03628c |
22
changelog.md
22
changelog.md
@@ -1,5 +1,27 @@
|
||||
# Changelog
|
||||
|
||||
## 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
|
||||
|
||||
- bump @push.rocks/smartbrowser from ^2.0.10 to ^2.0.11
|
||||
- bump @push.rocks/smartfs from ^1.4.0 to ^1.5.0
|
||||
- move @push.rocks/smartserve to later position in dependencies (version unchanged: ^2.0.1)
|
||||
|
||||
## 2026-03-09 - 3.3.1 - fix(serve)
|
||||
migrate test HTTP server to @push.rocks/smartserve and update related dependencies
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
"target": "ES2022"
|
||||
},
|
||||
"nodeModulesDir": true,
|
||||
"version": "3.3.1"
|
||||
"version": "3.5.0"
|
||||
}
|
||||
|
||||
14
package.json
14
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@git.zone/tstest",
|
||||
"version": "3.3.1",
|
||||
"version": "3.5.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": {
|
||||
@@ -26,21 +26,20 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^4.3.0",
|
||||
"@types/node": "^25.3.5"
|
||||
"@types/node": "^25.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/smartserve": "^2.0.1",
|
||||
"@git.zone/tsbundle": "^2.9.1",
|
||||
"@git.zone/tsrun": "^2.0.1",
|
||||
"@push.rocks/consolecolor": "^2.0.3",
|
||||
"@push.rocks/qenv": "^6.1.3",
|
||||
"@push.rocks/smartbrowser": "^2.0.10",
|
||||
"@push.rocks/smartbrowser": "^2.0.11",
|
||||
"@push.rocks/smartcrypto": "^2.0.4",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartenv": "^6.0.0",
|
||||
"@push.rocks/smartexpect": "^2.5.0",
|
||||
"@push.rocks/smartfile": "^13.1.2",
|
||||
"@push.rocks/smartfs": "^1.4.0",
|
||||
"@push.rocks/smartfs": "^1.5.0",
|
||||
"@push.rocks/smartjson": "^6.0.0",
|
||||
"@push.rocks/smartlog": "^3.2.1",
|
||||
"@push.rocks/smartmongo": "^5.1.0",
|
||||
@@ -48,8 +47,9 @@
|
||||
"@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/smartshell": "^3.3.7",
|
||||
"@push.rocks/smartserve": "^2.0.1",
|
||||
"@push.rocks/smartshell": "^3.3.8",
|
||||
"@push.rocks/smartstorage": "^6.0.1",
|
||||
"@push.rocks/smarttime": "^4.2.3",
|
||||
"@push.rocks/smartwatch": "^6.3.0",
|
||||
"@types/ws": "^8.18.1",
|
||||
|
||||
1860
pnpm-lock.yaml
generated
1860
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -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.1',
|
||||
version: '3.5.0',
|
||||
description: 'A powerful, modern test runner for TypeScript with multi-runtime support (Node.js, Deno, Bun, Chromium) and a batteries-included test framework.'
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
@@ -97,7 +102,22 @@ export class TsTest {
|
||||
if (this.logger.options.logFile) {
|
||||
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) {
|
||||
|
||||
@@ -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,7 +244,7 @@ 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user