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

smoke test port #1

Merged
merged 1 commit into from
Dec 5, 2024
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
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('jest').Config} */
export default {
transform: {},
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
testMatch: ['**/src/__tests__/**/*.test.ts'],
testEnvironment: 'node',
// Support for sharding tests across multiple CI jobs
shard: process.env.JEST_SHARD,
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"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",
"smoke-test:precommit": "SMOKE_TEST_PORT=4000 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 @@ -34,7 +35,7 @@
"eslint --max-warnings 0",
"tsc --noEmit --skipLibCheck",
"pnpm test:related",
"pnpm smoke-test"
"pnpm smoke-test:precommit"
],
"*.{json,md}": [
"prettier --write",
Expand Down
30 changes: 30 additions & 0 deletions scripts/run-sharded-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { spawnSync } from 'child_process';

// Get shard info from command line args
const shardArg = process.argv.find(arg => arg.startsWith('--shard='));
if (!shardArg) {
console.error('Missing --shard argument');
process.exit(1);
}

const [currentShard, totalShards] = shardArg.split('=')[1].split('/').map(Number);
if (!currentShard || !totalShards || currentShard > totalShards) {
console.error('Invalid shard format. Use --shard=X/Y where X <= Y');
process.exit(1);
}

// Run Jest with sharding
const result = spawnSync('jest', [
'--detectOpenHandles',
`--shard=${currentShard}/${totalShards}`
], {
stdio: 'inherit',
shell: true,
env: {
...process.env,
NODE_OPTIONS: '--experimental-vm-modules --no-warnings',
JEST_SHARD: `${currentShard}/${totalShards}`
}
});

process.exit(result.status);
17 changes: 10 additions & 7 deletions scripts/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,21 @@ async function killProcessOnPort(port) {
}
}

// Get port from environment variable or use default
const PORT = process.env.SMOKE_TEST_PORT || 3000;

async function main() {
try {
// Ensure port is free before starting
await killProcessOnPort(3000);
await killProcessOnPort(PORT);

// Test development mode
console.log('Testing development mode (pnpm dev)...');
await waitForServer('pnpm', ['dev'], 10000);
console.log(`Testing development mode (pnpm dev) on port ${PORT}...`);
await waitForServer('PORT=' + PORT + ' pnpm', ['dev'], 10000);
console.log('✓ Development server started successfully');

// Kill the development server
await killProcessOnPort(3000);
await killProcessOnPort(PORT);

// Test production mode
console.log('\nTesting production mode (pnpm start)...');
Expand All @@ -100,7 +103,7 @@ async function main() {
});
});

await waitForServer('pnpm', ['start'], 10000);
await waitForServer('PORT=' + PORT + ' pnpm', ['start'], 10000);
console.log('✓ Production server started successfully');

console.log('\n✅ All smoke tests passed!');
Expand All @@ -109,8 +112,8 @@ async function main() {
console.error('\n❌ Smoke tests failed:', error.message);
process.exit(1);
} finally {
// Cleanup: ensure port 3000 is free
await killProcessOnPort(3000);
// Cleanup: ensure port is free
await killProcessOnPort(PORT);
}
}

Expand Down
Loading