mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
Generate code coverage for js test (#302)
* Generate basic test coverage * Use jest in web * Use jest in jslib
This commit is contained in:
parent
5d9662373b
commit
cf62033fe7
16 changed files with 10563 additions and 7146 deletions
4
jslib/jest.config.js
Normal file
4
jslib/jest.config.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
collectCoverageFrom: ['./src/**/*.ts']
|
||||
};
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/* Copyright (C) 2019 Monomax Software Pty Ltd
|
||||
*
|
||||
* This file is part of Dnote.
|
||||
*
|
||||
* Dnote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Dnote is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
module.exports = config => {
|
||||
config.set({
|
||||
frameworks: ['mocha', 'karma-typescript'],
|
||||
reporters: ['mocha', 'karma-typescript'],
|
||||
browsers: ['ChromeHeadlessNoSandbox'],
|
||||
customLaunchers: {
|
||||
ChromeHeadlessNoSandbox: {
|
||||
base: 'ChromeHeadless',
|
||||
// specified because the default user of gitlab ci docker image is root, and chrome does not
|
||||
// support running as root without no-sandbox
|
||||
flags: ['--no-sandbox']
|
||||
}
|
||||
},
|
||||
files: [
|
||||
'./src/**/*.ts'
|
||||
],
|
||||
preprocessors: {
|
||||
'**/*.ts': 'karma-typescript'
|
||||
},
|
||||
karmaTypescriptConfig: {
|
||||
tsconfig: './tsconfig.json',
|
||||
bundlerOptions: {
|
||||
entrypoints: /\_test\.ts$/,
|
||||
sourceMap: true
|
||||
}
|
||||
},
|
||||
mochaReporter: {
|
||||
showDiff: true
|
||||
}
|
||||
});
|
||||
};
|
||||
5974
jslib/package-lock.json
generated
5974
jslib/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -7,8 +7,8 @@
|
|||
"clean": "rm -rf ./dist",
|
||||
"build": "tsc",
|
||||
"build:watch": "tsc --watch",
|
||||
"test": "karma start ./karma.conf.js --single-run",
|
||||
"test:watch": "karma start ./karma.conf.js --watch"
|
||||
"test": "jest --coverage",
|
||||
"test:watch": "jest --watch"
|
||||
},
|
||||
"author": "Monomax Software Pty Ltd",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
|
|
@ -19,15 +19,11 @@
|
|||
"qs": "^6.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.22",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"chai": "^4.2.0",
|
||||
"karma": "^4.4.1",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-mocha-reporter": "^2.2.5",
|
||||
"karma-typescript": "^4.1.1",
|
||||
"mocha": "^6.2.2",
|
||||
"jest": "^24.9.0",
|
||||
"prettier": "^1.18.2",
|
||||
"typescript": "^3.6.4"
|
||||
"ts-jest": "^24.1.0",
|
||||
"typescript": "^3.7.2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
import {
|
||||
validateBookName,
|
||||
checkDuplicate,
|
||||
|
|
@ -112,13 +111,13 @@ describe('books lib', () => {
|
|||
for (let i = 0; i < testCases.length; ++i) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`validates ${tc.input}`, () => {
|
||||
test(`validates ${tc.input}`, () => {
|
||||
const base = expect(() => validateBookName(tc.input));
|
||||
|
||||
if (tc.expectedErr) {
|
||||
base.to.throw(tc.expectedErr);
|
||||
base.toThrow(tc.expectedErr);
|
||||
} else {
|
||||
base.to.not.throw();
|
||||
base.not.toThrow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -175,9 +174,9 @@ describe('books lib', () => {
|
|||
for (let i = 0; i < testCases.length; ++i) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`checks duplicate for the test case ${i}`, () => {
|
||||
test(`checks duplicate for the test case ${i}`, () => {
|
||||
const result = checkDuplicate(tc.books, tc.bookName);
|
||||
expect(result).to.equal(tc.expected);
|
||||
expect(result).toBe(tc.expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
import { TokenKind, tokenize, parse } from './search';
|
||||
|
||||
describe('search.ts', () => {
|
||||
|
|
@ -149,10 +148,10 @@ describe('search.ts', () => {
|
|||
for (let i = 0; i < testCases.length; i++) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`tokenizes ${tc.input}`, () => {
|
||||
test(`tokenizes ${tc.input}`, () => {
|
||||
const result = tokenize(tc.input);
|
||||
|
||||
expect(result).to.eql(tc.tokens);
|
||||
expect(result).toEqual(tc.tokens);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -162,10 +161,10 @@ describe('search.ts', () => {
|
|||
for (let i = 0; i < testCases.length; i++) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`keyword [${tc.keywords}] - parses ${tc.input} `, () => {
|
||||
test(`keyword [${tc.keywords}] - parses ${tc.input} `, () => {
|
||||
const result = parse(tc.input, tc.keywords);
|
||||
|
||||
expect(result).to.eql(tc.result);
|
||||
expect(result).toEqual(tc.result);
|
||||
});
|
||||
}
|
||||
}
|
||||
2
web/.gitignore
vendored
2
web/.gitignore
vendored
|
|
@ -23,3 +23,5 @@ app.zip
|
|||
/public
|
||||
/web
|
||||
/vendor
|
||||
|
||||
/coverage
|
||||
|
|
|
|||
4
web/jest.config.js
Normal file
4
web/jest.config.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
collectCoverageFrom: ['./src/**/*.ts']
|
||||
};
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
/* Copyright (C) 2019 Monomax Software Pty Ltd
|
||||
*
|
||||
* This file is part of Dnote.
|
||||
*
|
||||
* Dnote is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Dnote is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const webpackConf = require('./webpack/rules/javascript');
|
||||
|
||||
module.exports = config => {
|
||||
config.set({
|
||||
frameworks: ['mocha'],
|
||||
reporters: ['mocha'],
|
||||
browsers: ['ChromeHeadlessNoSandbox'],
|
||||
customLaunchers: {
|
||||
ChromeHeadlessNoSandbox: {
|
||||
base: 'ChromeHeadless',
|
||||
// specified because the default user of gitlab ci docker image is root, and chrome does not
|
||||
// support running as root without no-sandbox
|
||||
flags: ['--no-sandbox']
|
||||
}
|
||||
},
|
||||
files: [
|
||||
'node_modules/regenerator-runtime/runtime.js',
|
||||
'./src/**/*_test.ts'
|
||||
],
|
||||
preprocessors: {
|
||||
'./src/**/*.ts': ['webpack']
|
||||
},
|
||||
webpack: {
|
||||
mode: 'none',
|
||||
resolve: {
|
||||
extensions: ['.js', '.ts']
|
||||
},
|
||||
module: {
|
||||
rules: [...webpackConf({ produciton: false, browser: true })]
|
||||
}
|
||||
},
|
||||
mochaReporter: {
|
||||
showDiff: true
|
||||
}
|
||||
});
|
||||
};
|
||||
4134
web/package-lock.json
generated
4134
web/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,8 +5,8 @@
|
|||
"repository": "https://github.com/dnote/dnote",
|
||||
"main": "index",
|
||||
"scripts": {
|
||||
"test": "karma start ./karma.conf.js --single-run",
|
||||
"test:watch": "karma start ./karma.conf.js --watch",
|
||||
"test": "jest --coverage",
|
||||
"test:watch": "jest --watch",
|
||||
"lint": "eslint ./src/**/*.ts ./src/**/*.tsx"
|
||||
},
|
||||
"author": "Monomax Software Pty Ltd",
|
||||
|
|
@ -16,9 +16,10 @@
|
|||
"@babel/plugin-transform-react-constant-elements": "^7.6.3",
|
||||
"@babel/preset-env": "^7.6.3",
|
||||
"@babel/preset-react": "^7.6.3",
|
||||
"@babel/preset-typescript": "^7.7.2",
|
||||
"@babel/register": "^7.6.2",
|
||||
"@hot-loader/react-dom": "^16.10.2",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/jest": "^24.0.22",
|
||||
"@types/react": "^16.9.11",
|
||||
"@types/react-dom": "^16.9.3",
|
||||
"@typescript-eslint/eslint-plugin": "^2.6.0",
|
||||
|
|
@ -26,7 +27,6 @@
|
|||
"autoprefixer": "^9.7.0",
|
||||
"babel-eslint": "^10.0.3",
|
||||
"babel-loader": "^8.0.6",
|
||||
"chai": "^4.2.0",
|
||||
"css-loader": "^3.2.0",
|
||||
"cssnano": "^4.1.10",
|
||||
"eslint": "^6.6.0",
|
||||
|
|
@ -39,14 +39,8 @@
|
|||
"eslint-plugin-react-hooks": "^2.2.0",
|
||||
"fibers": "^4.0.2",
|
||||
"file-loader": "^4.2.0",
|
||||
"karma": "^4.4.1",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-firefox-launcher": "^1.2.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-mocha-reporter": "^2.2.5",
|
||||
"karma-webpack": "^4.0.2",
|
||||
"jest": "^24.9.0",
|
||||
"mini-css-extract-plugin": "^0.8.0",
|
||||
"mocha": "^6.2.2",
|
||||
"node-sass": "^4.13.0",
|
||||
"postcss-loader": "^3.0.0",
|
||||
"prettier": "^1.18.2",
|
||||
|
|
@ -54,6 +48,7 @@
|
|||
"source-map-loader": "^0.2.4",
|
||||
"source-map-support": "^0.5.15",
|
||||
"style-loader": "^1.0.0",
|
||||
"ts-jest": "^24.1.0",
|
||||
"ts-loader": "^6.2.1",
|
||||
"typescript": "^3.6.4",
|
||||
"url-loader": "^2.2.0",
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
|
||||
import formatTime from './format';
|
||||
|
||||
describe('time/format.ts', () => {
|
||||
|
|
@ -49,9 +47,9 @@ describe('time/format.ts', () => {
|
|||
for (let i = 0; i < testCases.length; i++) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`converts the input ${tc.format}`, () => {
|
||||
test(`converts the input ${tc.format}`, () => {
|
||||
const result = formatTime(date, tc.format);
|
||||
expect(result).to.equal(tc.expected);
|
||||
expect(result).toBe(tc.expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -16,8 +16,6 @@
|
|||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { daysToMs } from './index';
|
||||
|
||||
describe('time.ts', () => {
|
||||
|
|
@ -37,9 +35,9 @@ describe('time.ts', () => {
|
|||
for (let i = 0; i < testCases.length; i++) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`converts the input ${tc.input}`, () => {
|
||||
test(`converts the input ${tc.input}`, () => {
|
||||
const result = daysToMs(tc.input);
|
||||
expect(result).to.equal(tc.expected);
|
||||
expect(result).toBe(tc.expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -16,8 +16,6 @@
|
|||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { getEditorSessionkey } from './editor';
|
||||
|
||||
describe('editor.ts', () => {
|
||||
|
|
@ -40,9 +38,9 @@ describe('editor.ts', () => {
|
|||
for (let i = 0; i < testCases.length; i++) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`generates a session key for input: ${tc.noteUUID}`, () => {
|
||||
test(`generates a session key for input: ${tc.noteUUID}`, () => {
|
||||
const result = getEditorSessionkey(tc.noteUUID);
|
||||
expect(result).to.equal;
|
||||
expect(result).toBe;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
import { TokenKind, tokenize, scanToken } from './lexer';
|
||||
|
||||
describe('lexer.ts', () => {
|
||||
|
|
@ -106,10 +105,10 @@ describe('lexer.ts', () => {
|
|||
for (let i = 0; i < testCases.length; i++) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`scans ${tc.input}`, () => {
|
||||
test(`scans ${tc.input}`, () => {
|
||||
const result = scanToken(tc.idx, tc.input);
|
||||
|
||||
expect(result.tok).to.deep.equal(tc.retTok);
|
||||
expect(result.tok).toEqual(tc.retTok);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -212,10 +211,10 @@ describe('lexer.ts', () => {
|
|||
for (let i = 0; i < testCases.length; i++) {
|
||||
const tc = testCases[i];
|
||||
|
||||
it(`tokenizes ${tc.input}`, () => {
|
||||
test(`tokenizes ${tc.input}`, () => {
|
||||
const result = tokenize(tc.input);
|
||||
|
||||
expect(result).to.deep.equal(tc.tokens);
|
||||
expect(result).toEqual(tc.tokens);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -16,8 +16,6 @@
|
|||
* along with Dnote. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { populateParams } from './paths';
|
||||
|
||||
describe('paths.ts', () => {
|
||||
|
|
@ -52,9 +50,9 @@ describe('paths.ts', () => {
|
|||
const tc = testCases[i];
|
||||
|
||||
const stringifiedParams = JSON.stringify(tc.params);
|
||||
it(`populates ${tc.pathDef} with params ${stringifiedParams}`, () => {
|
||||
test(`populates ${tc.pathDef} with params ${stringifiedParams}`, () => {
|
||||
const result = populateParams(tc.pathDef, tc.params);
|
||||
expect(result).to.equal(tc.expected);
|
||||
expect(result).toBe(tc.expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue