Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): Fix remix E2E test & types #8495

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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