Merge pull request #19 from HeinousTugboat/ht/add-mocha
Adds Mocha/Chai/Sinon, basic tests, and basic CI workflow
This commit is contained in:
commit
9e0ec2eb20
10 changed files with 2958 additions and 5 deletions
54
.github/workflows/ci.yml
vendored
Normal file
54
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
# Triggers the workflow on push or pull request events but only for the dev branch
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# lint:
|
||||||
|
# name: Lint
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v2
|
||||||
|
# - name: Use Node.js 16.13.1
|
||||||
|
# uses: actions/setup-node@v2
|
||||||
|
# with:
|
||||||
|
# node-version: 16.13.1
|
||||||
|
# cache: "npm"
|
||||||
|
# - name: Install npm dependencies
|
||||||
|
# run: npm ci
|
||||||
|
# - name: Run linter
|
||||||
|
# run: npm run lint:report
|
||||||
|
# prettier:
|
||||||
|
# name: Prettier
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v2
|
||||||
|
# - name: Use Node.js 16.13.1
|
||||||
|
# uses: actions/setup-node@v2
|
||||||
|
# with:
|
||||||
|
# node-version: 16.13.1
|
||||||
|
# cache: "npm"
|
||||||
|
# - name: Install npm dependencies
|
||||||
|
# run: npm ci
|
||||||
|
# - name: Run prettier check
|
||||||
|
# run: npm run format:report
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Use Node.js 16.13.1
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 16.13.1
|
||||||
|
cache: "npm"
|
||||||
|
- name: Install npm dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Run tests
|
||||||
|
run: npm run test:all
|
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",
|
"bin": "./npx/bitburner-filesync.ts",
|
||||||
"main": "./npx/bitburner-filesync.ts",
|
"main": "./npx/bitburner-filesync.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test:all": "mocha --recursive test",
|
||||||
|
"test:single": "mocha",
|
||||||
"start": "npx/bitburner-filesync.ts"
|
"start": "npx/bitburner-filesync.ts"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -33,8 +34,38 @@
|
||||||
"ws": "^8.8.1"
|
"ws": "^8.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/chai": "^4.3.3",
|
||||||
"@types/convict": "^6.1.1",
|
"@types/convict": "^6.1.1",
|
||||||
|
"@types/expect": "^24.3.0",
|
||||||
|
"@types/mocha": "^10.0.0",
|
||||||
"@types/node": "^18.7.23",
|
"@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": [
|
"include": [
|
||||||
"src/signals.d.ts",
|
"src/signals.d.ts",
|
||||||
"src/**/*"
|
"src/**/*",
|
||||||
|
"test/**/*"
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
|
|
Loading…
Add table
Reference in a new issue