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

feat: Add cross-platform sleep utility for e2e preparation #523

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 5 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"db:format": "pnpm dlx prisma format --schema=src/prisma/schema.prisma",
"db:reset": "pnpm dlx dotenv-cli -e ../../.env -- pnpm dlx prisma migrate reset --force --schema=src/prisma/schema.prisma",
"sourcemaps": "sentry-cli sourcemaps inject ./dist && sentry-cli sourcemaps upload ./dist || echo 'Failed to upload source maps to Sentry'",
"e2e:prepare": "cd ../../ && docker compose down && docker compose -f docker-compose-test.yml up -d && sleep 3 && cd apps/api && pnpm db:generate-types && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"e2e:prepare": "cd ../../ && docker compose down && docker compose -f docker-compose-test.yml up -d && cd apps/api && node --loader ts-node/esm src/common/cross-platform-sleep.ts && pnpm db:generate-types && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"e2e": "pnpm run e2e:prepare && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' jest --runInBand --config=jest.e2e-config.ts && pnpm run e2e:teardown",
"e2e:teardown": "cd ../../ && docker compose -f docker-compose-test.yml down",
"unit": "pnpm db:generate-types && jest --config=jest.config.ts"
Expand Down Expand Up @@ -59,6 +59,7 @@
"@types/eccrypto": "^1.1.6",
"@types/express": "^4.17.17",
"@types/multer": "^1.4.11",
"@types/node": "^20.14.10",
"@types/supertest": "^6.0.0",
"@types/uuid": "^9.0.8",
"ajv": "^7",
Expand All @@ -71,7 +72,9 @@
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3"
"ts-loader": "^9.4.3",
"ts-node": "^10.9.2",
"tsx": "^4.16.2"
},
"jest": {
"moduleFileExtensions": [
Expand Down
22 changes: 22 additions & 0 deletions apps/api/src/common/cross-platform-sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { execSync } from 'child_process';
import { platform } from 'os';

const seconds = 3;
const os = platform();

let command: string;
if (os === 'win32') {
command = `powershell -command "Start-Sleep -s ${seconds}"`;
Allan2000-Git marked this conversation as resolved.
Show resolved Hide resolved
} else if (os === 'darwin' || os === 'linux') {
command = `sleep ${seconds}`;
} else {
console.error('Unsupported operating system');
Allan2000-Git marked this conversation as resolved.
Show resolved Hide resolved
process.exit(1);
}

try {
execSync(command);
} catch (error) {
console.error(`Error executing sleep command: ${error}`);
process.exit(1);
}
Loading
Loading