Skip to content

Commit

Permalink
test(e2e): Fix remix E2E test & types (#8495)
Browse files Browse the repository at this point in the history
Improves the types for the E2E tests, as well as checking that they are
all good.
Fixes the remix E2E test which never timed out - for whatever reason
this was ever working...?
  • Loading branch information
mydea authored Jul 11, 2023
1 parent 99a0864 commit 81baae6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/e2e-tests/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ export interface RecipeTestResult extends RecipeInstance {
tests: TestResult[];
}

export type Env = Record<string, string | string>;
export type Env = Record<string, string | undefined>;
58 changes: 37 additions & 21 deletions packages/e2e-tests/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,50 @@ interface SpawnAsync {
status: number | null;
}

export function spawnAsync(
cmd: string,
options?:
| childProcess.SpawnOptionsWithoutStdio
| childProcess.SpawnOptionsWithStdioTuple<childProcess.StdioPipe, childProcess.StdioPipe, childProcess.StdioPipe>,
input?: string,
): Promise<SpawnAsync> {
const start = Date.now();
interface SpawnOptions {
timeout?: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
env?: any;
cwd?: string;
}

export function spawnAsync(cmd: string, options?: SpawnOptions, input?: string): Promise<SpawnAsync> {
const timeoutMs = options?.timeout || 60_000 * 5;

return new Promise<SpawnAsync>(resolve => {
const cp = childProcess.spawn(cmd, { shell: true, ...options });

// Ensure we properly time out after max. 5 min per command
let timeout: ReturnType<typeof setTimeout> | undefined = setTimeout(() => {
console.log(`Command "${cmd}" timed out after 5 minutes.`);
cp.kill();
end(null, `ETDIMEDOUT: Process timed out after ${timeoutMs} ms.`);
}, timeoutMs);

const stderr: unknown[] = [];
const stdout: string[] = [];
let error: Error | undefined;

function end(status: number | null, errorMessage?: string): void {
// This means we already ended
if (!timeout) {
return;
}

if (!error && errorMessage) {
error = new Error(errorMessage);
}

clearTimeout(timeout);
timeout = undefined;
resolve({
stdout: stdout.join(''),
stderr: stderr.join(''),
error: error || (status !== 0 ? new Error(`Process exited with status ${status}`) : undefined),
status,
});
}

cp.stdout.on('data', data => {
stdout.push(data ? (data as object).toString() : '');
});
Expand All @@ -46,19 +74,7 @@ export function spawnAsync(
});

cp.on('close', status => {
const end = Date.now();

// We manually mark this as timed out if the process takes too long
if (!error && status === 1 && options?.timeout && end >= start + options.timeout) {
error = new Error(`ETDIMEDOUT: Process timed out after ${options.timeout} ms.`);
}

resolve({
stdout: stdout.join(''),
stderr: stderr.join(''),
error: error || (status !== 0 ? new Error(`Process exited with status ${status}`) : undefined),
status,
});
end(status);
});

if (input) {
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"fix": "run-s fix:eslint fix:prettier",
"fix:eslint": "eslint . --format stylish --fix",
"fix:prettier": "prettier --config ../../.prettierrc.json --write . ",
"lint": "run-s lint:prettier lint:eslint",
"lint": "run-s lint:prettier lint:eslint lint:ts",
"lint:eslint": "eslint . --format stylish",
"lint:prettier": "prettier --config ../../.prettierrc.json --check .",
"lint:ts": "tsc --noEmit",
"test:e2e": "run-s test:validate-configuration test:validate-test-app-setups test:run",
"test:run": "ts-node run.ts",
"test:validate-configuration": "ts-node validate-verdaccio-configuration.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "../../test-recipe-schema.json",
"testApplicationName": "create-remix-app",
"buildCommand": "# disabling build test because it is causing timeouts: https://github.com/getsentry/sentry-javascript/pull/8486 pnpm install && pnpm build && pnpm start",
"buildCommand": "pnpm install && pnpm build",
"tests": []
}
1 change: 1 addition & 0 deletions packages/e2e-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "../../tsconfig.json",
"exclude": ["node_modules", "test-applications"],
"compilerOptions": {
"types": ["node"]
}
Expand Down

0 comments on commit 81baae6

Please sign in to comment.