-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added test for dwn-server Signed-off-by: captain-Akshay <[email protected]> * added test for process handler Signed-off-by: captain-Akshay <[email protected]> --------- Signed-off-by: captain-Akshay <[email protected]>
- Loading branch information
1 parent
fef5b82
commit eb67a75
Showing
3 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
import { config } from '../src/config.js'; | ||
import { DwnServer } from '../src/dwn-server.js'; | ||
import { clear, dwn } from './test-dwn.js'; | ||
|
||
describe('Process Handlers', function () { | ||
let dwnServer: DwnServer; | ||
const options = { | ||
dwn: dwn, | ||
config: config, | ||
}; | ||
let processExitStub: sinon.SinonStub; | ||
|
||
before(async function () { | ||
dwnServer = new DwnServer(options); | ||
}); | ||
beforeEach(async function () { | ||
await dwnServer.start(); | ||
processExitStub = sinon.stub(process, 'exit'); | ||
}); | ||
afterEach(async function () { | ||
process.removeAllListeners('SIGINT'); | ||
process.removeAllListeners('SIGTERM'); | ||
process.removeAllListeners('uncaughtException'); | ||
await clear(); | ||
processExitStub.restore(); | ||
}); | ||
it('should stop when SIGINT is emitted', async function () { | ||
process.emit('SIGINT'); | ||
expect(dwnServer.httpServer.listening).to.be.false; | ||
expect(processExitStub.called).to.be.false; // Ensure process.exit is not called | ||
}); | ||
|
||
it('should stop when SIGTERM is emitted', async function () { | ||
process.emit('SIGTERM'); | ||
expect(dwnServer.httpServer.listening).to.be.false; | ||
expect(processExitStub.called).to.be.false; // Ensure process.exit is not called | ||
}); | ||
|
||
it('should log an error for an uncaught exception', function () { | ||
const consoleErrorStub = sinon.stub(console, 'error'); // Stub console.error | ||
const errorMessage = 'Test uncaught exception'; | ||
const error = new Error(errorMessage); | ||
process.emit('uncaughtException', error); | ||
// Ensure console.error was called with the expected error message | ||
expect(consoleErrorStub.calledOnce).to.be.true; | ||
|
||
// Restore the original console.error | ||
consoleErrorStub.restore(); | ||
}); | ||
}); |