Skip to content

Commit b8af0ec

Browse files
author
Bruno Ribeiro
committed
Await for server to be fully started
1 parent ab659fd commit b8af0ec

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

bin/test_api.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,26 @@ env.PORT = 3001;
3939
const server = cp.spawn('node', ['demo/start'], {
4040
cwd: path.resolve(__dirname, '..'),
4141
env,
42-
stdio: 'inherit'
42+
stdio: 'pipe'
4343
})
4444

45-
const run = cp.spawnSync(
46-
npmBinScript('mocha'),
47-
[...testFiles, ...flagArgs],
48-
{
49-
cwd: path.resolve(__dirname, '..'),
50-
env,
51-
stdio: 'inherit'
52-
}
53-
);
45+
server.stdout.on('data', (data) => {
46+
// await for the server to fully start
47+
if (data.indexOf("successfully") !== -1) {
48+
const run = cp.spawnSync(
49+
npmBinScript('mocha'),
50+
[...testFiles, ...flagArgs], {
51+
cwd: path.resolve(__dirname, '..'),
52+
env,
53+
stdio: 'inherit'
54+
}
55+
);
5456

55-
function npmBinScript(script) {
56-
return path.resolve(__dirname, `../node_modules/.bin/` + (process.platform === 'win32' ? `${script}.cmd` : script));
57-
}
57+
function npmBinScript(script) {
58+
return path.resolve(__dirname, `../node_modules/.bin/` + (process.platform === 'win32' ?
59+
`${script}.cmd` : script));
60+
}
5861

59-
process.exit(run.status);
62+
process.exit(run.status);
63+
}
64+
});

0 commit comments

Comments
 (0)