chore: migrate tests to typescript

This commit is contained in:
Justin Starry
2021-03-15 13:08:10 +08:00
committed by Justin Starry
parent f912c63b22
commit 8ada44456d
27 changed files with 242 additions and 825 deletions

View File

@ -0,0 +1,40 @@
import {expect} from 'chai';
import {AgentManager, DESTROY_TIMEOUT_MS} from '../src/agent-manager';
import {sleep} from '../src/util/sleep';
describe('AgentManager', () => {
it('works', async () => {
const manager = new AgentManager();
const agent = manager._agent;
expect(manager._activeRequests).to.eq(0);
expect(manager._destroyTimeout).to.be.null;
manager.requestStart();
expect(manager._activeRequests).to.eq(1);
expect(manager._destroyTimeout).to.be.null;
manager.requestEnd();
expect(manager._activeRequests).to.eq(0);
expect(manager._destroyTimeout).not.to.be.null;
manager.requestStart();
manager.requestStart();
expect(manager._activeRequests).to.eq(2);
expect(manager._destroyTimeout).to.be.null;
manager.requestEnd();
manager.requestEnd();
expect(manager._activeRequests).to.eq(0);
expect(manager._destroyTimeout).not.to.be.null;
expect(manager._agent).to.eq(agent);
await sleep(DESTROY_TIMEOUT_MS);
expect(manager._agent).not.to.eq(agent);
}).timeout(2 * DESTROY_TIMEOUT_MS);
});