feat(docker): add Docker test file support and runtime adapter
This commit is contained in:
@@ -11,12 +11,13 @@ import { TsTestLogger } from './tstest.logging.js';
|
||||
import type { LogOptions } from './tstest.logging.js';
|
||||
|
||||
// Runtime adapters
|
||||
import { parseTestFilename } from './tstest.classes.runtime.parser.js';
|
||||
import { parseTestFilename, isDockerTestFile, parseDockerTestFilename } from './tstest.classes.runtime.parser.js';
|
||||
import { RuntimeAdapterRegistry } from './tstest.classes.runtime.adapter.js';
|
||||
import { NodeRuntimeAdapter } from './tstest.classes.runtime.node.js';
|
||||
import { ChromiumRuntimeAdapter } from './tstest.classes.runtime.chromium.js';
|
||||
import { DenoRuntimeAdapter } from './tstest.classes.runtime.deno.js';
|
||||
import { BunRuntimeAdapter } from './tstest.classes.runtime.bun.js';
|
||||
import { DockerRuntimeAdapter } from './tstest.classes.runtime.docker.js';
|
||||
|
||||
export class TsTest {
|
||||
public testDir: TestDirectory;
|
||||
@@ -37,6 +38,7 @@ export class TsTest {
|
||||
public tsbundleInstance = new plugins.tsbundle.TsBundle();
|
||||
|
||||
public runtimeRegistry = new RuntimeAdapterRegistry();
|
||||
public dockerAdapter: DockerRuntimeAdapter | 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;
|
||||
@@ -60,6 +62,14 @@ export class TsTest {
|
||||
this.runtimeRegistry.register(
|
||||
new BunRuntimeAdapter(this.logger, this.smartshellInstance, this.timeoutSeconds, this.filterTags)
|
||||
);
|
||||
|
||||
// Initialize Docker adapter
|
||||
this.dockerAdapter = new DockerRuntimeAdapter(
|
||||
this.logger,
|
||||
this.smartshellInstance,
|
||||
this.timeoutSeconds,
|
||||
cwdArg
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,8 +221,14 @@ export class TsTest {
|
||||
}
|
||||
|
||||
private async runSingleTest(fileNameArg: string, fileIndex: number, totalFiles: number, tapCombinator: TapCombinator) {
|
||||
// Parse the filename to determine runtimes and modifiers
|
||||
const fileName = plugins.path.basename(fileNameArg);
|
||||
|
||||
// Check if this is a Docker test file
|
||||
if (isDockerTestFile(fileName)) {
|
||||
return await this.runDockerTest(fileNameArg, fileIndex, totalFiles, tapCombinator);
|
||||
}
|
||||
|
||||
// Parse the filename to determine runtimes and modifiers (for TypeScript tests)
|
||||
const parsed = parseTestFilename(fileName, { strictUnknownRuntime: false });
|
||||
|
||||
// Check for nonci modifier in CI environment
|
||||
@@ -258,6 +274,28 @@ export class TsTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a Docker test file
|
||||
*/
|
||||
private async runDockerTest(
|
||||
fileNameArg: string,
|
||||
fileIndex: number,
|
||||
totalFiles: number,
|
||||
tapCombinator: TapCombinator
|
||||
): Promise<void> {
|
||||
if (!this.dockerAdapter) {
|
||||
this.logger.tapOutput(cs('❌ Docker adapter not initialized', 'red'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const tapParser = await this.dockerAdapter.run(fileNameArg, fileIndex, totalFiles);
|
||||
tapCombinator.addTapParser(tapParser);
|
||||
} catch (error) {
|
||||
this.logger.tapOutput(cs(`❌ Docker test failed: ${error.message}`, 'red'));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user