Skip to content

Commit

Permalink
Add init and shutdown lifecycle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonirap committed Jul 17, 2023
1 parent 1afa4bb commit 8d293f4
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion test/test-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ test('Calls init before the server has started', async t => {
server.close();
});

test('Calls async init before the server has started', async t => {
t.plan(1);
let initCalled = false;
const server = await start({
init: () => {

Check failure on line 33 in test/test-lifecycle.js

View workflow job for this annotation

GitHub Actions / build (16.x, ubuntu-latest)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 33 in test/test-lifecycle.js

View workflow job for this annotation

GitHub Actions / build (18.x, ubuntu-latest)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return new Promise(() => {
initCalled = true;
})

Check failure on line 36 in test/test-lifecycle.js

View workflow job for this annotation

GitHub Actions / build (16.x, ubuntu-latest)

Missing semicolon

Check failure on line 36 in test/test-lifecycle.js

View workflow job for this annotation

GitHub Actions / build (18.x, ubuntu-latest)

Missing semicolon
},
handle: () => {}
}, defaults);
t.ok(initCalled, 'init was called');
server.close();
});

test('Bubbles up any exceptions thrown by init()', t => {
t.plan(1);
start({
Expand Down Expand Up @@ -56,6 +71,26 @@ test('Calls shutdown after the server has stopped', async t => {
});
});

test('Calls async shutdown after the server has stopped', async t => {
t.plan(1);
let shutdownCalled = false;
const server = await start({
handle: () => {},
shutdown: _ => {

Check failure on line 79 in test/test-lifecycle.js

View workflow job for this annotation

GitHub Actions / build (16.x, ubuntu-latest)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 79 in test/test-lifecycle.js

View workflow job for this annotation

GitHub Actions / build (18.x, ubuntu-latest)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return new Promise(_ => {
shutdownCalled = true;
})

Check failure on line 82 in test/test-lifecycle.js

View workflow job for this annotation

GitHub Actions / build (16.x, ubuntu-latest)

Missing semicolon

Check failure on line 82 in test/test-lifecycle.js

View workflow job for this annotation

GitHub Actions / build (18.x, ubuntu-latest)

Missing semicolon
}
}, defaults);
t.ok(!shutdownCalled, 'shutdown was not called before server.close()');
return new Promise(resolve => {
// TODO: It would be nice to check for the shutdown call here
// but it's not clear how to do that if we are only hooking on
// signal interrupts.
server.close(resolve);
});
});

test('Liveness endpoint can be provided', t => {
start({
handle: _ => 'OK',
Expand Down Expand Up @@ -138,4 +173,4 @@ test('Readiness route can be provided', t => {
server.close();
});
});
});
});

0 comments on commit 8d293f4

Please sign in to comment.