-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.js
More file actions
87 lines (72 loc) · 2.01 KB
/
run-tests.js
File metadata and controls
87 lines (72 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Test runner that starts the server and runs tests
* This ensures the server is running before tests execute
*/
'use strict';
const { spawn } = require('child_process');
async function runTests() {
console.log('Starting test server...');
// Start the server
const server = spawn('node', ['testserver.js'], {
cwd: __dirname,
stdio: ['ignore', 'pipe', 'pipe']
});
// Wait for server to start
await new Promise((resolve, reject) => {
const timeoutId = global.setTimeout(() => {
reject(new Error('Server startup timeout'));
}, 5000);
server.stdout.on('data', (data) => {
const output = data.toString();
if (output.includes('Test server starting')) {
global.clearTimeout(timeoutId);
console.log('✓ Server started successfully\n');
resolve();
}
});
server.stderr.on('data', (data) => {
console.error('Server error:', data.toString());
});
server.on('error', (err) => {
global.clearTimeout(timeoutId);
reject(err);
});
});
// Give the server a moment to fully initialize
await new Promise(resolve => global.setTimeout(resolve, 500));
// Run the tests
console.log('Running tests...\n');
const testProcess = spawn('node', ['test-request.js'], {
cwd: __dirname,
stdio: 'inherit'
});
await new Promise((resolve, reject) => {
testProcess.on('close', (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`Tests failed with code ${code}`));
}
});
testProcess.on('error', reject);
});
// Clean up
console.log('\nShutting down test server...');
server.kill();
// Wait for server to shut down
await new Promise((resolve) => {
server.on('close', () => {
console.log('✓ Test server stopped');
resolve();
});
});
}
runTests()
.then(() => {
console.log('\n✓ All tests passed!');
process.exit(0);
})
.catch((error) => {
console.error('\n✗ Test failed:', error.message);
process.exit(1);
});