Skip to content

Commit

Permalink
added test for dwn-server
Browse files Browse the repository at this point in the history
Signed-off-by: captain-Akshay <[email protected]>
  • Loading branch information
captain-Akshay authored and finn-block committed Oct 18, 2023
1 parent eb67a75 commit bc20408
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/dwn-server.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { expect } from 'chai';

import { config } from '../src/config.js';
import { DwnServer } from '../src/dwn-server.js';
import { clear, dwn } from './test-dwn.js';

describe('DwnServer', function () {
let dwnServer: DwnServer;
const options = {
dwn: dwn,
config: config,
};
before(function () {
dwnServer = new DwnServer(options);
});
after(async function () {
dwnServer.stop(() => console.log('server stop'));
await clear();
});
it('should create an instance of DwnServer', function () {
expect(dwnServer).to.be.an.instanceOf(DwnServer);
});

it('should start the server and listen on the specified port', async function () {
await dwnServer.start();
const response = await fetch('http://localhost:3000', {
method: 'GET',
});
expect(response.status).to.equal(200);
});
it('should stop the server', async function () {
dwnServer.stop(() => console.log('server Stop'));
// Add an assertion to check that the server has been stopped
expect(dwnServer.httpServer.listening).to.be.false;
});
});

0 comments on commit bc20408

Please sign in to comment.