Skip to content

Commit

Permalink
refactor: use seconds as base unit for global timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
alexplischke committed Oct 16, 2023
1 parent 2f203ba commit 02cb664
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/testcafe-runner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { spawn } from 'child_process';
import path from 'path';
import fs from 'fs';
import {TestCafeConfig, Suite, CompilerOptions, millisecond} from './type';
import {TestCafeConfig, Suite, CompilerOptions, second} from './type';

import {
getArgs,
Expand Down Expand Up @@ -225,17 +225,17 @@ export function buildCommandLine(suite: Suite|undefined, projectPath: string, as
return cli;
}

async function runTestCafe(tcCommandLine: (string|number)[], projectPath: string, timeout: millisecond) {
async function runTestCafe(tcCommandLine: (string|number)[], projectPath: string, timeout: second) {
const nodeBin = process.argv[0];
const testcafeBin = path.join(__dirname, '..', 'node_modules', 'testcafe', 'lib', 'cli');

const testcafeProc = spawn(nodeBin, [testcafeBin, ...(tcCommandLine as string[])], {stdio: 'inherit', cwd: projectPath, env: process.env});

const timeoutPromise = new Promise<boolean>((resolve) => {
setTimeout(() => {
console.error(`Job timed out after ${timeout/1000} seconds`);
console.error(`Job timed out after ${timeout} seconds`);
resolve(false);
}, timeout);
}, timeout * 1000);
});

const testcafePromise = new Promise<boolean>((resolve) => {
Expand Down Expand Up @@ -274,8 +274,8 @@ async function run(nodeBin: string, runCfgPath: string, suiteName: string) {
const configFile = path.join(projectPath, 'sauce-testcafe-config.cjs');
fs.copyFileSync(path.join(__dirname, 'sauce-testcafe-config.cjs'), configFile);

// saucectl suite.timeout is in nanoseconds
const timeout = (suite.timeout || 0) / 1000000000 || 30 * 60 * 1000; // 30min default
// saucectl suite.timeout is in nanoseconds, convert to seconds
const timeout = (suite.timeout || 0) / 1_000_000_000 || 30 * 60; // 30min default

const tcCommandLine = buildCommandLine(suite, projectPath, assetsPath, configFile);
const passed = await runTestCafe(tcCommandLine, projectPath, timeout);
Expand Down
2 changes: 1 addition & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Region } from '@saucelabs/testcomposer';

export type millisecond = number;
export type second = number;

export type Metadata = {
tags?: string[],
Expand Down

0 comments on commit 02cb664

Please sign in to comment.