Adds Mocha, Chai and Sinon testing utilities, as well as basic specs
Closes #9
This commit is contained in:
parent
999780a612
commit
9fabda9386
9 changed files with 2904 additions and 5 deletions
2760
package-lock.json
generated
2760
package-lock.json
generated
File diff suppressed because it is too large
Load diff
35
package.json
35
package.json
|
@ -6,7 +6,8 @@
|
|||
"bin": "./npx/bitburner-filesync.ts",
|
||||
"main": "./npx/bitburner-filesync.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test:all": "mocha --recursive test",
|
||||
"test:single": "mocha",
|
||||
"start": "npx/bitburner-filesync.ts"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -33,8 +34,38 @@
|
|||
"ws": "^8.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.3.3",
|
||||
"@types/convict": "^6.1.1",
|
||||
"@types/expect": "^24.3.0",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/node": "^18.7.23",
|
||||
"@types/ws": "^8.5.3"
|
||||
"@types/sinon": "^10.0.13",
|
||||
"@types/sinon-chai": "^3.2.8",
|
||||
"@types/ws": "^8.5.3",
|
||||
"chai": "^4.3.6",
|
||||
"mocha": "^10.0.0",
|
||||
"sinon": "^14.0.0",
|
||||
"sinon-chai": "^3.7.0"
|
||||
},
|
||||
"mocha": {
|
||||
"bail": false,
|
||||
"delay": false,
|
||||
"diff": true,
|
||||
"extension": [
|
||||
"ts"
|
||||
],
|
||||
"node-option": "loader=ts-node/esm",
|
||||
"parallel": true,
|
||||
"reporter": "spec",
|
||||
"require": [
|
||||
"./test/setup-tests.ts"
|
||||
],
|
||||
"slow": "75",
|
||||
"timeout": "2000",
|
||||
"ui": "bdd",
|
||||
"watch-files": [
|
||||
"test/**/*.ts"
|
||||
],
|
||||
"watch-ignore": []
|
||||
}
|
||||
}
|
||||
|
|
29
test/fileWatch.spec.ts
Normal file
29
test/fileWatch.spec.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { setupWatch } from '../src/fileWatch';
|
||||
import { expect } from 'chai';
|
||||
import { stub, createStubInstance } from 'sinon';
|
||||
import CheapWatch from 'cheap-watch';
|
||||
import signal from 'signal-js';
|
||||
|
||||
describe('fileWatch', () => {
|
||||
describe('setupWatch', () => {
|
||||
it('should exist', () => {
|
||||
expect(setupWatch).to.exist;
|
||||
});
|
||||
|
||||
it('should instantiate and initialize CheapWatch', async () => {
|
||||
const consoleStub = stub(console, 'log');
|
||||
const watchInstance = createStubInstance(CheapWatch);
|
||||
const watchConstructorStub = stub().returns(watchInstance);
|
||||
Object.setPrototypeOf(CheapWatch, watchConstructorStub);
|
||||
|
||||
const result = await setupWatch(signal);
|
||||
|
||||
expect(result).to.eq(watchInstance);
|
||||
expect(watchConstructorStub).to.have.been.called;
|
||||
expect(watchInstance.init).to.have.been.called;
|
||||
expect(watchInstance.on).to.have.been.calledTwice;
|
||||
|
||||
consoleStub.restore();
|
||||
});
|
||||
});
|
||||
});
|
28
test/networking/messageGenerators.spec.ts
Normal file
28
test/networking/messageGenerators.spec.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { expect } from 'chai';
|
||||
import { fileChangeEventToMsg, fileRemovalEventToMsg, requestDefinitionFile, requestFilenames } from '../../src/networking/messageGenerators';
|
||||
|
||||
describe('messageGenerators', () => {
|
||||
describe('fileChangeEventToMsg', () => {
|
||||
it('should exist', () => {
|
||||
expect(fileChangeEventToMsg).to.exist;
|
||||
});
|
||||
});
|
||||
|
||||
describe('fileRemovalEventToMsg', () => {
|
||||
it('should exist', () => {
|
||||
expect(fileRemovalEventToMsg).to.exist;
|
||||
});
|
||||
});
|
||||
|
||||
describe('requestDefinitionFile', () => {
|
||||
it('should exist', () => {
|
||||
expect(requestDefinitionFile).to.exist;
|
||||
});
|
||||
});
|
||||
|
||||
describe('requestFilenames', () => {
|
||||
it('should exist', () => {
|
||||
expect(requestFilenames).to.exist;
|
||||
});
|
||||
});
|
||||
});
|
8
test/networking/messageHandler.spec.ts
Normal file
8
test/networking/messageHandler.spec.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { expect } from 'chai';
|
||||
import { messageHandler } from '../../src/networking/messageHandler';
|
||||
|
||||
describe('messageHandler', () => {
|
||||
it('should exist', () => {
|
||||
expect(messageHandler).to.exist;
|
||||
});
|
||||
});
|
8
test/networking/messageTracker.spec.ts
Normal file
8
test/networking/messageTracker.spec.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { expect } from 'chai';
|
||||
import { messageTracker } from '../../src/networking/messageTracker';
|
||||
|
||||
describe('messageTracker', () => {
|
||||
it('should exist', () => {
|
||||
expect(messageTracker).to.exist;
|
||||
});
|
||||
});
|
7
test/networking/webSocket.spec.ts
Normal file
7
test/networking/webSocket.spec.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
describe('webSocket', () => {
|
||||
it('should run test', () => {
|
||||
expect(true).to.eq(true)
|
||||
})
|
||||
});
|
31
test/setup-tests.ts
Normal file
31
test/setup-tests.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import chai from 'chai';
|
||||
import { createSandbox, stub } from 'sinon';
|
||||
import sinonChai from 'sinon-chai';
|
||||
|
||||
export async function mochaGlobalSetup() {
|
||||
// initial global setup
|
||||
// runs once for all threads
|
||||
}
|
||||
|
||||
export const mochaHooks: Mocha.RootHookObject = {
|
||||
// runs once at the beginning of each thread
|
||||
beforeAll(done: () => void) {
|
||||
done();
|
||||
},
|
||||
// runs once at the end of each thread
|
||||
afterAll(done: () => void) {
|
||||
done();
|
||||
},
|
||||
// runs once before each test
|
||||
beforeEach(done: () => void) {
|
||||
chai.should();
|
||||
chai.use(sinonChai);
|
||||
this.sandbox = createSandbox();
|
||||
done();
|
||||
},
|
||||
// runs once after each test
|
||||
afterEach(done: () => void) {
|
||||
this.sandbox.restore();
|
||||
done();
|
||||
}
|
||||
}
|
|
@ -6,7 +6,8 @@
|
|||
},
|
||||
"include": [
|
||||
"src/signals.d.ts",
|
||||
"src/**/*"
|
||||
"src/**/*",
|
||||
"test/**/*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
|
|
Loading…
Add table
Reference in a new issue