Skip to content

Commit

Permalink
Add one more test, clarify readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Sep 6, 2020
1 parent f0bcb0f commit 2ae75c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-graceful-shutdown",
"version": "1.0.3",
"version": "1.0.4",
"description": "Gracefully shutdown your modular NodeJS application",
"main": "index.js",
"engines": {
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"homepage": "https://github.com/ZitRos/node-graceful-shutdown#readme",
"devDependencies": {
"esm": "^3.0.83",
"ava": "^0.25.0"
"ava": "^3.12.1",
"esm": "^3.2.25"
}
}
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Gracefully handle your modular NodeJS application's shutdown (termination), using dependencies.

Process signals captured: `SIGINT`, `SIGTERM`, `SIGQUIT`.

Example
-------

Expand Down Expand Up @@ -44,12 +46,12 @@ This library, along existing ones, allow your application to be **modular**. You
in the same module, where initialization happens. In addition, it allows specifying the order

Recommendations:
1. Please, do not use this module in libraries (modules, packages). Use for the end application only.
1. Please, **do not use this module in libraries** (modules, packages). It is intended for end applications only (see why in `5.`).
2. Once imported, `onShutdown` is application-wide (in terms of a single process), so the callbacks and their dependencies will see each other when imported from multiple files.
3. Circular shutdown handler dependencies will throw an error immediately once declared.
4. There's also an `onShutdownError` export which takes an error as an argument when any of assigned shutdown handlers throw an error (added for very-very prudent programmers only).
5. Importing this module deletes existing handlers (`SIGINT`, `SIGTERM`, `SIGQUIT`) if there are any (normally, there should be no other handlers).
6. You may also consider defining constants
5. Importing this module **deletes** existing handlers (`SIGINT`, `SIGTERM`, `SIGQUIT`) if there are any. This is intended as other custom handlers can exit the process at any time.
6. You may also consider defining constants in your application, instead of string arguments (names).

Licence
-------
Expand Down
23 changes: 22 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ const tests = [

assert.equal(callTable["a"], 1);

}],
// Keep this test at the end.
["Removes other shutdown handlers", async () => {

process.addListener('SIGINT', () => {
console.log('\n\nSIGINT is handled by the custom code, but is expected to be handled by the library.\n');
process.exit(101);
});

const pkg = await testModule();
const callTable = { "a": 0 };

pkg.onShutdown("a", async function () {
callTable["a"] = 1;
});

process.emit("SIGINT");
await delay();

assert.equal(callTable["a"], 1);

}]
];

Expand Down Expand Up @@ -229,7 +250,7 @@ async function test () {
}

test().then(() => {
console.log("It works indeed!");
console.log("\nIt works indeed!");
}).catch((e) => {
console.log("\n\nTEST FAILED");
console.error(e);
Expand Down

0 comments on commit 2ae75c0

Please sign in to comment.