From 33c2f9de6ff31cf02919cca56a80bf808ba9b71a Mon Sep 17 00:00:00 2001 From: Xymorot Date: Thu, 10 Oct 2019 23:47:13 +0200 Subject: [PATCH] test: remove split between integration and unit tests, use tags instead --- .mocharc.yml | 1 + README.md | 10 ++++++++-- package.json | 7 +++---- tests/{integration => main}/main.spec.ts | 2 +- tests/{unit => }/main/services/web-crawler.spec.ts | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) rename tests/{integration => main}/main.spec.ts (93%) rename tests/{unit => }/main/services/web-crawler.spec.ts (94%) diff --git a/.mocharc.yml b/.mocharc.yml index 1f601b1..ef5dd2b 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -1 +1,2 @@ # https://github.com/mochajs/mocha/blob/master/example/config +spec: 'tests/**/*spec.js' diff --git a/README.md b/README.md index c2a0b76..c6d9960 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,12 @@ To run migrations: `node_modules/.bin/typeorm migration:run -c ` This is also pre-defined in the npm script `typeorm:migrate`. -## Testing +### Testing -`npm run test` +The testing framework of choice is [Mocha](https://mochajs.org/). Call `npm run test` to run all tests. Tests are written in typescript and need to be transpiled before testing. + +#### Tagging + +Mocha does [not have a seperate tagging feature](https://github.com/mochajs/mocha/wiki/Tagging), but it can filter via title. Us the following tags in your test titles: + +- `@slow` when the test is particularly slow diff --git a/package.json b/package.json index 47d94c4..1c6796f 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,8 @@ "typeorm:migrate:library": "typeorm migration:run -c library", "watch": "gulp build --watch --dev", "build": "gulp build", - "test:integration": "mocha --spec tests/integration/**/*.spec.js", - "test:unit": "mocha --spec tests/unit/**/*.spec.js", - "test": "mocha --spec tests/**/*.spec.js", + "test:fast": "mocha --grep @slow --invert", + "test": "mocha", "lint": "npm run eslint && npm run tslint", "eslint-check": "eslint --print-config gulpfile.js | eslint-config-prettier-check", "eslint": "eslint .", @@ -26,7 +25,7 @@ "forge:start": "electron-forge start", "forge:make": "electron-forge --platform win32 --arch x64 make", "forge": "npm run build && npm run forge:make", - "precommit": "npm run test:unit && npm run prettier:write && npm run eslint-check && npm run tslint-check && npm run lint", + "precommit": "npm run prettier:write && npm run eslint-check && npm run tslint-check && npm run lint && npm run test:fast", "prepush": "npm run test" }, "dependencies": { diff --git a/tests/integration/main.spec.ts b/tests/main/main.spec.ts similarity index 93% rename from tests/integration/main.spec.ts rename to tests/main/main.spec.ts index 4d54376..8fc2746 100644 --- a/tests/integration/main.spec.ts +++ b/tests/main/main.spec.ts @@ -22,7 +22,7 @@ describe('Application', function(): void { } }); - it('shows an initial window', function(): any { + it('shows an initial window @slow', function(): any { return this.app.client.getWindowCount().then((count: number) => { expect(count).to.be.gte(1); }); diff --git a/tests/unit/main/services/web-crawler.spec.ts b/tests/main/services/web-crawler.spec.ts similarity index 94% rename from tests/unit/main/services/web-crawler.spec.ts rename to tests/main/services/web-crawler.spec.ts index 308965a..a685d9b 100644 --- a/tests/unit/main/services/web-crawler.spec.ts +++ b/tests/main/services/web-crawler.spec.ts @@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, it } from 'mocha'; import nock from 'nock'; import { Response } from 'node-fetch'; import sinon from 'sinon'; -import { fetch } from '../../../../src/main/services/web-crawler'; +import { fetch } from '../../../src/main/services/web-crawler'; describe('Web Crawler', function(): void { this.timeout('2s');