mirror of
https://github.com/zkitter/ui.git
synced 2026-01-09 13:18:00 -05:00
fix unit tests
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
module.exports = {
|
||||
import type { JestConfigWithTsJest } from 'ts-jest';
|
||||
import { pathsToModuleNameMapper } from 'ts-jest';
|
||||
|
||||
import { compilerOptions } from './tsconfig.json';
|
||||
|
||||
const jestConfig: JestConfigWithTsJest = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'jsdom',
|
||||
collectCoverage: true,
|
||||
@@ -13,14 +17,16 @@ module.exports = {
|
||||
'/src/util/message.ts',
|
||||
'/src/util/svc.ts',
|
||||
],
|
||||
rootDir: '.',
|
||||
roots: ['<rootDir>/src'],
|
||||
verbose: true,
|
||||
moduleNameMapper: {
|
||||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
||||
'<rootDir>/__mocks__/fileMock.js',
|
||||
'\\.(css|less|scss)$': '<rootDir>/__mocks__/styleMock.js',
|
||||
...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>' }),
|
||||
},
|
||||
setupFiles: ['fake-indexeddb/auto', 'jsdom-worker','<rootDir>/src/util/mocks.js'],
|
||||
setupFiles: ['fake-indexeddb/auto', 'jsdom-worker', '<rootDir>/src/util/mocks.ts'],
|
||||
testEnvironmentOptions: {
|
||||
html: `
|
||||
<!DOCTYPE html>
|
||||
@@ -53,3 +59,5 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default jestConfig
|
||||
19
package.json
19
package.json
@@ -9,7 +9,7 @@
|
||||
"dev": "NODE_ENV=development concurrently --kill-others-on-fail npm:dev-ui",
|
||||
"build": "NODE_ENV=production npm run build-ui",
|
||||
"build:ci": "NODE_ENV=development npm run build-ui",
|
||||
"test": "NODE_ENV=test jest --coverage=false --silent",
|
||||
"test": "NODE_ENV=test jest --config jest.config.ts --coverage=false --silent",
|
||||
"test:ci": "NODE_ENV=test jest --silent --coverage=false --reporters=jest-silent-reporter",
|
||||
"test:coverage": "NODE_ENV=test jest --coverage",
|
||||
"format:check": "prettier --check 'src'",
|
||||
@@ -87,26 +87,26 @@
|
||||
"@types/redux-logger": "^3.0.9",
|
||||
"@types/sinon": "^10.0.13",
|
||||
"@types/webtorrent": "^0.109.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
||||
"@typescript-eslint/parser": "^5.43.0",
|
||||
"assert": "^2.0.0",
|
||||
"browserify": "^17.0.0",
|
||||
"concurrently": "^7.6.0",
|
||||
"constants-browserify": "^1.0.0",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"css-loader": "^6.7.2",
|
||||
"fake-indexeddb": "^4.0.0",
|
||||
"file-loader": "^6.2.0",
|
||||
"html-entities": "^2.3.3",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"https-browserify": "^1.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
||||
"@typescript-eslint/parser": "^5.43.0",
|
||||
"constants-browserify": "^1.0.0",
|
||||
"eslint": "^5.16.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-import-resolver-typescript": "^3.5.2",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-n": "^15.5.1",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"fake-indexeddb": "^4.0.0",
|
||||
"file-loader": "^6.2.0",
|
||||
"html-entities": "^2.3.3",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"https-browserify": "^1.0.0",
|
||||
"husky": "^8.0.2",
|
||||
"image-webpack-loader": "^8.1.0",
|
||||
"jest": "^29.3.1",
|
||||
@@ -125,6 +125,7 @@
|
||||
"style-loader": "^3.3.1",
|
||||
"ts-jest": "^29.0.3",
|
||||
"ts-loader": "^9.4.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.9.3",
|
||||
"webpack": "^5.75.0",
|
||||
"webpack-cli": "^5.0.0",
|
||||
|
||||
1323
pnpm-lock.yaml
generated
1323
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
const crypto = require('crypto');
|
||||
import crypto, { BinaryToTextEncoding } from 'crypto'
|
||||
|
||||
window.matchMedia =
|
||||
window.matchMedia ||
|
||||
@@ -10,8 +10,10 @@ window.matchMedia =
|
||||
};
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
global.EventSource = class EventSource {
|
||||
constructor(str) {}
|
||||
private str: any
|
||||
constructor(str: any) {this.str = str}
|
||||
|
||||
onmessage = () => {};
|
||||
onopen = () => {};
|
||||
@@ -20,9 +22,9 @@ global.EventSource = class EventSource {
|
||||
Object.defineProperty(global, 'crypto', {
|
||||
value: {
|
||||
subtle: {
|
||||
digest: async (type, data) =>
|
||||
crypto.createHash(type.replace('-', '').toLowerCase()).digest(data),
|
||||
digest: async (type: string, data: string) =>
|
||||
crypto.createHash(type.replace('-', '').toLowerCase()).digest(<BinaryToTextEncoding>data),
|
||||
},
|
||||
getRandomValues: arr => crypto.randomBytes(arr.length),
|
||||
getRandomValues: (arr: string | any[]) => crypto.randomBytes(arr.length),
|
||||
},
|
||||
});
|
||||
@@ -18,21 +18,7 @@ import * as swUtilsModules from '../serviceWorkers/util';
|
||||
global.TextEncoder = TextEncoder;
|
||||
// @ts-ignore
|
||||
global.TextDecoder = TextDecoder;
|
||||
// @ts-ignore
|
||||
global.crypto = {
|
||||
subtle: {
|
||||
// @ts-ignore
|
||||
digest: async (type: string, data) => {
|
||||
return crypto.createHash(type.replace('-', '').toLowerCase()).digest(data);
|
||||
},
|
||||
},
|
||||
getRandomValues: (arr: any) => crypto.randomBytes(arr.length),
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
global.TextEncoder = TextEncoder;
|
||||
// @ts-ignore
|
||||
global.TextDecoder = TextDecoder;
|
||||
|
||||
export const pushReduxActionStub = sinon.stub(swUtilsModules, 'pushReduxAction');
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"include": [
|
||||
"src",
|
||||
"jest.config"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"target": "es5",
|
||||
@@ -37,8 +41,5 @@
|
||||
"static/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user