Get all platform unit tests to run

This commit is contained in:
dannyrb 2019-07-17 14:57:50 -04:00
parent 5544c57c37
commit b8baae7c25
14 changed files with 114 additions and 137 deletions

View File

@ -16,6 +16,7 @@ module.exports = {
], ],
babelrcRoots: ["./platform/*", "./extensions/*"], babelrcRoots: ["./platform/*", "./extensions/*"],
plugins: [ plugins: [
"inline-react-svg",
"@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread", "@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-syntax-dynamic-import", "@babel/plugin-syntax-dynamic-import",

30
jest.config.base.js Normal file
View File

@ -0,0 +1,30 @@
const path = require("path");
module.exports = {
verbose: true,
roots: ["<rootDir>/src"],
transform: {
"^.+\\.js$": "babel-jest"
},
testMatch: ["<rootDir>/src/**/*.test.js"],
testPathIgnorePatterns: ["<rootDir>/node_modules/"],
moduleFileExtensions: ["js", "jsx"],
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/src/__mocks__/fileMock.js",
"\\.(css|less)$": "identity-obj-proxy"
},
// Setup
// setupFiles: ["jest-canvas-mock/lib/index.js"],
// Coverage
reporters: ["default", "jest-junit"],
collectCoverage: false,
collectCoverageFrom: [
"<rootDir>/src/**/*.{js,jsx}",
// Not
"!<rootDir>/src/**/*.test.js",
"!**/node_modules/**",
"!**/__tests__/**",
"!<rootDir>/dist/**"
]
};

16
jest.config.js Normal file
View File

@ -0,0 +1,16 @@
// Initiate all tests from root, but allow tests from each package root.
// Share as much config as possible to reduce duplication.
//
// Borrowing from here:
// https://github.com/facebook/jest/issues/3112#issuecomment-398581705
const base = require("./jest.config.base.js");
module.exports = {
...base,
// https://jestjs.io/docs/en/configuration#projects-array-string-projectconfig
projects: [
// "<rootDir>/extensions/*/jest.config.js",
"<rootDir>/platform/*/jest.config.js"
],
coverageDirectory: "<rootDir>/coverage/"
};

View File

@ -11,8 +11,10 @@
"yarn": "^1.16.0" "yarn": "^1.16.0"
}, },
"scripts": { "scripts": {
"cm": "npx git-cz",
"start": "lerna run lerna:start --parallel", "start": "lerna run lerna:start --parallel",
"build": "lerna run lerna:build --parallel", "build": "lerna run lerna:build --parallel",
"test": "jest --ci --runInBand --collectCoverage",
"test:unit": "lerna run lerna:test:unit --parallel", "test:unit": "lerna run lerna:test:unit --parallel",
"new-version": "lerna version --conventional-commits --yes", "new-version": "lerna version --conventional-commits --yes",
"build:pwa:ci": "" "build:pwa:ci": ""
@ -27,6 +29,7 @@
"@babel/preset-react": "^7.0.0", "@babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.2", "babel-eslint": "^10.0.2",
"babel-loader": "^8.0.6", "babel-loader": "^8.0.6",
"babel-plugin-inline-react-svg": "1.1.0",
"babel-plugin-module-resolver": "^3.2.0", "babel-plugin-module-resolver": "^3.2.0",
"copy-webpack-plugin": "^5.0.3", "copy-webpack-plugin": "^5.0.3",
"cross-env": "^5.2.0", "cross-env": "^5.2.0",

View File

@ -1,13 +1,13 @@
const base = require('../../jest.config.base.js');
const pkg = require('./package');
module.exports = { module.exports = {
verbose: true, ...base,
testPathIgnorePatterns: ["<rootDir>/node_modules/"], name: pkg.name,
testMatch: ["<rootDir>/src/**/*.test.js"], displayName: pkg.name,
// // rootDir: "../.."
collectCoverage: false, // testMatch: [
collectCoverageFrom: [ // //`<rootDir>/platform/${pack.name}/**/*.spec.js`
"**/*.{js,jsx}", // "<rootDir>/platform/viewer/**/*.test.js"
"!**/node_modules/**", // ]
"!<rootDir>/dist/**"
],
reporters: ["default", "jest-junit"]
}; };

View File

@ -1,9 +0,0 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

View File

@ -1 +0,0 @@
10.15.3

View File

@ -1,9 +0,0 @@
{
"trailingComma": "es5",
"printWidth": 80,
"proseWrap": "always",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"endOfLine": "lf"
}

View File

@ -0,0 +1,10 @@
const base = require("../../jest.config.base.js");
const pkg = require("./package");
const esModules = ["react-dnd"];
module.exports = {
...base,
name: pkg.name,
displayName: pkg.name
};

View File

@ -15,14 +15,12 @@
"dist" "dist"
], ],
"scripts": { "scripts": {
"cm": "npx git-cz", "lerna:test:unit": "jest --ci --runInBand --collectCoverage && codecov -F ui",
"dev": "docz dev", "dev": "docz dev",
"test": "cross-env CI=1 react-scripts test --env=jsdom --transformIgnorePatterns \"node_modules/(?!react-dnd)/\"",
"test:watch": "react-scripts test --env=jsdom --transformIgnorePatterns \"node_modules/(?!react-dnd)/\"", "test:watch": "react-scripts test --env=jsdom --transformIgnorePatterns \"node_modules/(?!react-dnd)/\"",
"lerna:build": "webpack --config config/webpack.prod.js -w -d", "lerna:build": "webpack --config config/webpack.prod.js -w -d",
"build": "rollup -c", "build": "rollup -c",
"start": "rollup -c -w", "start": "rollup -c -w",
"lint": "eslint -c .eslintrc --fix src && prettier --single-quote --write src/**/*.{js,jsx,json,css}",
"prepare": "yarn build", "prepare": "yarn build",
"prepublishOnly": "yarn build", "prepublishOnly": "yarn build",
"generateStaticSite": "docz build", "generateStaticSite": "docz build",
@ -57,10 +55,7 @@
"@mdx-js/tag": "^0.20.3", "@mdx-js/tag": "^0.20.3",
"all-contributors-cli": "6.7.0", "all-contributors-cli": "6.7.0",
"autoprefixer": "^9.6.0", "autoprefixer": "^9.6.0",
"babel-plugin-inline-react-svg": "1.1.0",
"commitizen": "3.0.7", "commitizen": "3.0.7",
"cpx": "1.5.0",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "2.1.0", "cz-conventional-changelog": "2.1.0",
"docz": "1.2.0", "docz": "1.2.0",
"docz-core": "1.2.0", "docz-core": "1.2.0",

View File

@ -1,46 +0,0 @@
import * as ReactViewerbase from './index.js';
describe('Top level exports', () => {
test('have not changed', () => {
const expectedExports = [
'ICONS',
//
'CineDialog',
'Dropdown',
'ExpandableToolMenu',
'ExampleDropTarget',
'Icon',
'LayoutButton',
'LayoutChooser',
'LayoutManager',
'LayoutPanelDropTarget',
'MeasurementTable',
'MeasurementTableItem',
'Overlay',
'OverlayTrigger',
'PlayClipButton',
'QuickSwitch',
'RoundedButtonGroup',
'ScrollableArea',
'SelectTree',
'SimpleDialog',
'StudyBrowser',
'StudyList',
'TableList',
'TableListItem',
'ThumbnailEntry',
'Toolbar',
'ToolbarButton',
'ToolbarSection',
'Tooltip',
'AboutModal',
'UserPreferences',
'UserPreferencesModal',
'ViewerbaseDragDropContext',
].sort();
const exports = Object.keys(ReactViewerbase).sort();
expect(exports).toEqual(expectedExports);
});
});

View File

@ -1,22 +1,22 @@
const webpack = require('webpack'); const webpack = require("webpack");
const merge = require('webpack-merge'); const merge = require("webpack-merge");
const path = require('path'); const path = require("path");
const common = require('./webpack.common'); const common = require("./webpack.common");
const SRC_DIR = path.join(__dirname, '../src'); const SRC_DIR = path.join(__dirname, "../src");
const DIST_DIR = path.join(__dirname, '../dist'); const DIST_DIR = path.join(__dirname, "../dist");
const INDEX = path.join(DIST_DIR, 'index.html'); const INDEX = path.join(DIST_DIR, "index.html");
module.exports = (env, argv) => { module.exports = (env, argv) => {
const commonConfig = common(env, argv); const commonConfig = common(env, argv);
return merge(commonConfig, { return merge(commonConfig, {
mode: 'development', mode: "development",
devtool: 'cheap-module-source-map', devtool: "cheap-module-source-map",
output: { output: {
path: DIST_DIR, path: DIST_DIR,
publicPath: '/', publicPath: "/",
filename: '[name].bundle.js', filename: "[name].bundle.js"
}, },
module: { module: {
rules: [ rules: [
@ -24,26 +24,26 @@ module.exports = (env, argv) => {
test: /\.(gif|jp?g|png|svg|ico)$/i, test: /\.(gif|jp?g|png|svg|ico)$/i,
use: [ use: [
{ {
loader: 'file-loader', loader: "file-loader",
options: { options: {
name: '[path][name].[ext]', name: "[path][name].[ext]",
context: SRC_DIR, context: SRC_DIR
}, }
}, }
], ]
}, },
{ {
test: /\.(ttf|eot|woff|woff2)$/i, test: /\.(ttf|eot|woff|woff2)$/i,
use: [ use: [
{ {
loader: 'file-loader', loader: "file-loader",
options: { options: {
name: '[name].[ext]', name: "[name].[ext]"
}, }
}, }
], ]
}, }
], ]
}, },
plugins: [new webpack.HotModuleReplacementPlugin()], plugins: [new webpack.HotModuleReplacementPlugin()],
devServer: { devServer: {
@ -52,11 +52,12 @@ module.exports = (env, argv) => {
compress: false, compress: false,
// contentBase: DIST_DIR, // contentBase: DIST_DIR,
open: true, open: true,
port: 3001, port: 3000,
writeToDisk: true, writeToDisk: true,
historyApiFallback: { historyApiFallback: true
index: '/', // {
}, // index: '/',
}, // },
}
}); });
}; };

View File

@ -1,26 +1,14 @@
const path = require("path"); const base = require("../../jest.config.base.js");
const pkg = require("./package");
module.exports = { module.exports = {
verbose: true, ...base,
testMatch: ["<rootDir>/src/**/*.test.js"], name: pkg.name,
// displayName: pkg.name,
collectCoverage: false, setupFilesAfterEnv: ["<rootDir>/src/__tests__/globalSetup.js"]
collectCoverageFrom: [ // rootDir: "../.."
"<rootDir>/src/**/*.{js,jsx}", // testMatch: [
"!<rootDir>/src/**/*.test.js", // //`<rootDir>/platform/${pack.name}/**/*.spec.js`
"!**/node_modules/**", // "<rootDir>/platform/viewer/**/*.test.js"
"!**/__tests__/**" // ]
],
reporters: ["default", "jest-junit"],
//
transform: {
"^.+\\.js$": path.resolve(__dirname, "./jestBabelTransform.js")
},
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/src/__mocks__/fileMock.js",
"\\.(css|less)$": "identity-obj-proxy"
},
setupFiles: ["<rootDir>../../node_modules/jest-canvas-mock/lib/index.js"],
setupTestFrameworkScriptFile: "<rootDir>/src/__tests__/globalSetup.js"
}; };

View File

@ -14,15 +14,13 @@
"proxy": "http://localhost:8042", "proxy": "http://localhost:8042",
"scripts": { "scripts": {
"lerna:start": "cross-env NODE_ENV=development webpack-dev-server --config config/webpack.dev.js --mode development -w -d", "lerna:start": "cross-env NODE_ENV=development webpack-dev-server --config config/webpack.dev.js --mode development -w -d",
"lerna:test:unit": "jest --ci --runInBand --collectCoverage --reporters=default --reporters=jest-junit && codecov", "lerna:test:unit": "jest --ci --runInBand --collectCoverage && codecov -F viewer",
"cm": "npx git-cz",
"dev": "yarn run preBuild && react-scripts start", "dev": "yarn run preBuild && react-scripts start",
"dev:debug": "react-scripts start", "dev:debug": "react-scripts start",
"build:package": "yarn run preBuild && node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c", "build:package": "yarn run preBuild && node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c",
"build:package:ci": "yarn run preBuild && node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c", "build:package:ci": "yarn run preBuild && node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c",
"build:web": "yarn run preBuild && react-scripts --max_old_space_size=4096 build", "build:web": "yarn run preBuild && react-scripts --max_old_space_size=4096 build",
"build:demo:ci": "yarn run preBuild && cross-env PUBLIC_URL=/ REACT_APP_CONFIG=config/demo.js react-scripts --max_old_space_size=4096 build", "build:demo:ci": "yarn run preBuild && cross-env PUBLIC_URL=/ REACT_APP_CONFIG=config/demo.js react-scripts --max_old_space_size=4096 build",
"lint": "eslint -c .eslintrc --fix src && prettier --single-quote --write src/**/*.{js,jsx,json,css}",
"test:unit": "jest", "test:unit": "jest",
"test:e2e:ci": "start-server-and-test start http://localhost:5000 cy:run:ci", "test:e2e:ci": "start-server-and-test start http://localhost:5000 cy:run:ci",
"start": "yarn run dev", "start": "yarn run dev",