Skip to content

Commit

Permalink
feat: add smoke tests for dev and start commands
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Dec 5, 2024
1 parent cdaf8d6 commit c714c10
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ jobs:
run: |
mkdir -p test-data
pnpm test
- name: Run smoke tests
env:
NODE_OPTIONS: '--experimental-vm-modules --no-warnings'
SIGNING_ADDRESS: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
ALLOCATOR_ADDRESS: '0x2345678901234567890123456789012345678901'
PRIVATE_KEY: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
DOMAIN: 'smallocator.example'
BASE_URL: 'https://smallocator.example'
DATABASE_URL: 'sqlite::memory:'
SKIP_SIGNING_VERIFICATION: 'true'
NODE_ENV: 'test'
run: pnpm smoke-test
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --sourcemap --packages=external && cp .env dist/ 2>/dev/null || true",
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --detectOpenHandles",
"test:related": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --bail --findRelatedTests src/__tests__/*.test.ts",
"smoke-test": "node scripts/smoke-test.js",
"lint": "eslint .",
"type-check": "tsc --noEmit -p tsconfig.lint.json",
"type-check:staged": "tsc --noEmit --skipLibCheck --skipDefaultLibCheck --target ES2022 --module ESNext --moduleResolution bundler --strict --esModuleInterop --forceConsistentCasingInFileNames --baseUrl . --paths viem:['./src/types/viem.d.ts'] --paths webauthn-p256:['./src/types/webauthn-p256.d.ts'] src/types/fastify.d.ts",
Expand All @@ -32,7 +33,8 @@
"prettier --check",
"eslint --max-warnings 0",
"tsc --noEmit --skipLibCheck",
"pnpm test:related"
"pnpm test:related",
"pnpm smoke-test"
],
"*.{json,md}": [
"prettier --write",
Expand Down
61 changes: 61 additions & 0 deletions scripts/smoke-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { spawn } from 'child_process';

// Utility to run a command and wait for a specific time
function runWithTimeout(command, args, timeoutMs) {
return new Promise((resolve, reject) => {
const process = spawn(command, args, {
stdio: 'inherit',
shell: true
});

let killed = false;

// Set timeout to kill the process
const timeout = setTimeout(() => {
killed = true;
process.kill();
resolve(); // Process started successfully if it ran for the timeout duration
}, timeoutMs);

process.on('error', (error) => {
clearTimeout(timeout);
reject(error);
});

process.on('exit', (code) => {
if (!killed && code !== 0) {
clearTimeout(timeout);
reject(new Error(`Process exited with code ${code}`));
}
});
});
}

async function main() {
try {
// Test development mode
console.log('Testing development mode (pnpm dev)...');
await runWithTimeout('pnpm', ['dev'], 5000);

// Test production mode
console.log('Testing production mode (pnpm start)...');
// First build
const buildProcess = spawn('pnpm', ['build'], { stdio: 'inherit', shell: true });
await new Promise((resolve, reject) => {
buildProcess.on('exit', (code) => {
if (code === 0) resolve();
else reject(new Error(`Build failed with code ${code}`));
});
});

await runWithTimeout('pnpm', ['start'], 5000);

console.log('✅ Smoke tests passed!');
process.exit(0);
} catch (error) {
console.error('❌ Smoke tests failed:', error.message);
process.exit(1);
}
}

main();

0 comments on commit c714c10

Please sign in to comment.