Skip to content

Commit 225a4bb

Browse files
authored
test: CLI execution tests fail on Node 22 due to late stderr callback (parse-community#10376)
1 parent 537c2af commit 225a4bb

File tree

1 file changed

+18
-46
lines changed

1 file changed

+18
-46
lines changed

spec/CLI.spec.js

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -213,37 +213,20 @@ describe('LiveQuery definitions', () => {
213213
describe('execution', () => {
214214
const binPath = path.resolve(__dirname, '../bin/parse-server');
215215
let childProcess;
216-
let aggregatedData;
217216

218-
function handleStdout(childProcess, done, aggregatedData, requiredData) {
219-
childProcess.stdout.on('data', data => {
220-
data = data.toString();
221-
aggregatedData.push(data);
222-
if (requiredData.every(required => aggregatedData.some(aggregated => aggregated.includes(required)))) {
223-
done();
224-
}
225-
});
226-
}
227-
228-
function handleStderr(childProcess, done) {
229-
childProcess.stderr.on('data', data => {
230-
data = data.toString();
231-
if (!data.includes('[DEP0040] DeprecationWarning')) {
232-
done.fail(data);
233-
}
234-
});
235-
}
236-
237-
function handleError(childProcess, done) {
238-
childProcess.on('error', err => {
239-
done.fail(err);
217+
function waitForStartup(cp, requiredOutput) {
218+
return new Promise((resolve, reject) => {
219+
const aggregated = [];
220+
cp.stdout.on('data', data => {
221+
aggregated.push(data.toString());
222+
if (requiredOutput.every(r => aggregated.some(a => a.includes(r)))) {
223+
resolve();
224+
}
225+
});
226+
cp.on('error', reject);
240227
});
241228
}
242229

243-
beforeEach(() => {
244-
aggregatedData = [];
245-
});
246-
247230
afterEach(done => {
248231
if (childProcess) {
249232
childProcess.on('close', () => {
@@ -254,20 +237,18 @@ describe('execution', () => {
254237
}
255238
});
256239

257-
it_id('a0ab74b4-f805-4e03-b31d-b5cd59e64495')(it)('should start Parse Server', done => {
240+
it_id('a0ab74b4-f805-4e03-b31d-b5cd59e64495')(it)('should start Parse Server', async () => {
258241
const env = { ...process.env };
259242
env.NODE_OPTIONS = '--dns-result-order=ipv4first --trace-deprecation';
260243
childProcess = spawn(
261244
binPath,
262245
['--appId', 'test', '--masterKey', 'test', '--databaseURI', databaseURI, '--port', '1339'],
263246
{ env }
264247
);
265-
handleStdout(childProcess, done, aggregatedData, ['parse-server running on']);
266-
handleStderr(childProcess, done);
267-
handleError(childProcess, done);
248+
await waitForStartup(childProcess, ['parse-server running on']);
268249
});
269250

270-
it_id('d7165081-b133-4cba-901b-19128ce41301')(it)('should start Parse Server with GraphQL', async done => {
251+
it_id('d7165081-b133-4cba-901b-19128ce41301')(it)('should start Parse Server with GraphQL', async () => {
271252
const env = { ...process.env };
272253
env.NODE_OPTIONS = '--dns-result-order=ipv4first --trace-deprecation';
273254
childProcess = spawn(
@@ -285,15 +266,10 @@ describe('execution', () => {
285266
],
286267
{ env }
287268
);
288-
handleStdout(childProcess, done, aggregatedData, [
289-
'parse-server running on',
290-
'GraphQL running on',
291-
]);
292-
handleStderr(childProcess, done);
293-
handleError(childProcess, done);
269+
await waitForStartup(childProcess, ['parse-server running on', 'GraphQL running on']);
294270
});
295271

296-
it_id('2769cdb4-ce8a-484d-8a91-635b5894ba7e')(it)('should start Parse Server with GraphQL and Playground', async done => {
272+
it_id('2769cdb4-ce8a-484d-8a91-635b5894ba7e')(it)('should start Parse Server with GraphQL and Playground', async () => {
297273
const env = { ...process.env };
298274
env.NODE_OPTIONS = '--dns-result-order=ipv4first --trace-deprecation';
299275
childProcess = spawn(
@@ -312,25 +288,21 @@ describe('execution', () => {
312288
],
313289
{ env }
314290
);
315-
handleStdout(childProcess, done, aggregatedData, [
291+
await waitForStartup(childProcess, [
316292
'parse-server running on',
317293
'Playground running on',
318294
'GraphQL running on',
319295
]);
320-
handleStderr(childProcess, done);
321-
handleError(childProcess, done);
322296
});
323297

324-
it_id('23caddd7-bfea-4869-8bd4-0f2cd283c8bd')(it)('can start Parse Server with auth via CLI', done => {
298+
it_id('23caddd7-bfea-4869-8bd4-0f2cd283c8bd')(it)('can start Parse Server with auth via CLI', async () => {
325299
const env = { ...process.env };
326300
env.NODE_OPTIONS = '--dns-result-order=ipv4first --trace-deprecation';
327301
childProcess = spawn(
328302
binPath,
329303
['--databaseURI', databaseURI, './spec/configs/CLIConfigAuth.json'],
330304
{ env }
331305
);
332-
handleStdout(childProcess, done, aggregatedData, ['parse-server running on']);
333-
handleStderr(childProcess, done);
334-
handleError(childProcess, done);
306+
await waitForStartup(childProcess, ['parse-server running on']);
335307
});
336308
});

0 commit comments

Comments
 (0)