diff --git a/babel.config.js b/babel.config.js index 9f0a9263d..74afe92cd 100644 --- a/babel.config.js +++ b/babel.config.js @@ -16,6 +16,7 @@ module.exports = { ], babelrcRoots: ["./platform/*", "./extensions/*"], plugins: [ + "inline-react-svg", "@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-object-rest-spread", "@babel/plugin-syntax-dynamic-import", diff --git a/jest.config.base.js b/jest.config.base.js new file mode 100644 index 000000000..fda185bae --- /dev/null +++ b/jest.config.base.js @@ -0,0 +1,30 @@ +const path = require("path"); + +module.exports = { + verbose: true, + roots: ["/src"], + transform: { + "^.+\\.js$": "babel-jest" + }, + testMatch: ["/src/**/*.test.js"], + testPathIgnorePatterns: ["/node_modules/"], + moduleFileExtensions: ["js", "jsx"], + moduleNameMapper: { + "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": + "/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: [ + "/src/**/*.{js,jsx}", + // Not + "!/src/**/*.test.js", + "!**/node_modules/**", + "!**/__tests__/**", + "!/dist/**" + ] +}; diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..549f14da8 --- /dev/null +++ b/jest.config.js @@ -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: [ + // "/extensions/*/jest.config.js", + "/platform/*/jest.config.js" + ], + coverageDirectory: "/coverage/" +}; diff --git a/package.json b/package.json index 7258d72f1..502b8cb2c 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,10 @@ "yarn": "^1.16.0" }, "scripts": { + "cm": "npx git-cz", "start": "lerna run lerna:start --parallel", "build": "lerna run lerna:build --parallel", + "test": "jest --ci --runInBand --collectCoverage", "test:unit": "lerna run lerna:test:unit --parallel", "new-version": "lerna version --conventional-commits --yes", "build:pwa:ci": "" @@ -27,6 +29,7 @@ "@babel/preset-react": "^7.0.0", "babel-eslint": "^10.0.2", "babel-loader": "^8.0.6", + "babel-plugin-inline-react-svg": "1.1.0", "babel-plugin-module-resolver": "^3.2.0", "copy-webpack-plugin": "^5.0.3", "cross-env": "^5.2.0", diff --git a/platform/core/jest.config.js b/platform/core/jest.config.js index 59879cbd5..9055db5b5 100644 --- a/platform/core/jest.config.js +++ b/platform/core/jest.config.js @@ -1,13 +1,13 @@ +const base = require('../../jest.config.base.js'); +const pkg = require('./package'); + module.exports = { - verbose: true, - testPathIgnorePatterns: ["/node_modules/"], - testMatch: ["/src/**/*.test.js"], - // - collectCoverage: false, - collectCoverageFrom: [ - "**/*.{js,jsx}", - "!**/node_modules/**", - "!/dist/**" - ], - reporters: ["default", "jest-junit"] + ...base, + name: pkg.name, + displayName: pkg.name, + // rootDir: "../.." + // testMatch: [ + // //`/platform/${pack.name}/**/*.spec.js` + // "/platform/viewer/**/*.test.js" + // ] }; diff --git a/platform/ui/.editorconfig b/platform/ui/.editorconfig deleted file mode 100644 index 9d08a1a82..000000000 --- a/platform/ui/.editorconfig +++ /dev/null @@ -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 diff --git a/platform/ui/.nvmrc b/platform/ui/.nvmrc deleted file mode 100644 index d16c3a34a..000000000 --- a/platform/ui/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -10.15.3 \ No newline at end of file diff --git a/platform/ui/.prettierrc b/platform/ui/.prettierrc deleted file mode 100644 index 12348ec6a..000000000 --- a/platform/ui/.prettierrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "trailingComma": "es5", - "printWidth": 80, - "proseWrap": "always", - "tabWidth": 2, - "semi": true, - "singleQuote": true, - "endOfLine": "lf" -} diff --git a/platform/ui/jest.config.js b/platform/ui/jest.config.js new file mode 100644 index 000000000..78c435aa3 --- /dev/null +++ b/platform/ui/jest.config.js @@ -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 +}; diff --git a/platform/ui/package.json b/platform/ui/package.json index c884baa56..04b815dfe 100644 --- a/platform/ui/package.json +++ b/platform/ui/package.json @@ -15,14 +15,12 @@ "dist" ], "scripts": { - "cm": "npx git-cz", + "lerna:test:unit": "jest --ci --runInBand --collectCoverage && codecov -F ui", "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)/\"", "lerna:build": "webpack --config config/webpack.prod.js -w -d", "build": "rollup -c", "start": "rollup -c -w", - "lint": "eslint -c .eslintrc --fix src && prettier --single-quote --write src/**/*.{js,jsx,json,css}", "prepare": "yarn build", "prepublishOnly": "yarn build", "generateStaticSite": "docz build", @@ -57,10 +55,7 @@ "@mdx-js/tag": "^0.20.3", "all-contributors-cli": "6.7.0", "autoprefixer": "^9.6.0", - "babel-plugin-inline-react-svg": "1.1.0", "commitizen": "3.0.7", - "cpx": "1.5.0", - "cross-env": "^5.2.0", "cz-conventional-changelog": "2.1.0", "docz": "1.2.0", "docz-core": "1.2.0", diff --git a/platform/ui/src/test.js b/platform/ui/src/test.js deleted file mode 100644 index ce27ab1cb..000000000 --- a/platform/ui/src/test.js +++ /dev/null @@ -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); - }); -}); diff --git a/platform/viewer/config/webpack.dev.js b/platform/viewer/config/webpack.dev.js index b1d3cc228..84186b594 100644 --- a/platform/viewer/config/webpack.dev.js +++ b/platform/viewer/config/webpack.dev.js @@ -1,22 +1,22 @@ -const webpack = require('webpack'); -const merge = require('webpack-merge'); -const path = require('path'); -const common = require('./webpack.common'); +const webpack = require("webpack"); +const merge = require("webpack-merge"); +const path = require("path"); +const common = require("./webpack.common"); -const SRC_DIR = path.join(__dirname, '../src'); -const DIST_DIR = path.join(__dirname, '../dist'); -const INDEX = path.join(DIST_DIR, 'index.html'); +const SRC_DIR = path.join(__dirname, "../src"); +const DIST_DIR = path.join(__dirname, "../dist"); +const INDEX = path.join(DIST_DIR, "index.html"); module.exports = (env, argv) => { const commonConfig = common(env, argv); return merge(commonConfig, { - mode: 'development', - devtool: 'cheap-module-source-map', + mode: "development", + devtool: "cheap-module-source-map", output: { path: DIST_DIR, - publicPath: '/', - filename: '[name].bundle.js', + publicPath: "/", + filename: "[name].bundle.js" }, module: { rules: [ @@ -24,26 +24,26 @@ module.exports = (env, argv) => { test: /\.(gif|jp?g|png|svg|ico)$/i, use: [ { - loader: 'file-loader', + loader: "file-loader", options: { - name: '[path][name].[ext]', - context: SRC_DIR, - }, - }, - ], + name: "[path][name].[ext]", + context: SRC_DIR + } + } + ] }, { test: /\.(ttf|eot|woff|woff2)$/i, use: [ { - loader: 'file-loader', + loader: "file-loader", options: { - name: '[name].[ext]', - }, - }, - ], - }, - ], + name: "[name].[ext]" + } + } + ] + } + ] }, plugins: [new webpack.HotModuleReplacementPlugin()], devServer: { @@ -52,11 +52,12 @@ module.exports = (env, argv) => { compress: false, // contentBase: DIST_DIR, open: true, - port: 3001, + port: 3000, writeToDisk: true, - historyApiFallback: { - index: '/', - }, - }, + historyApiFallback: true + // { + // index: '/', + // }, + } }); }; diff --git a/platform/viewer/jest.config.js b/platform/viewer/jest.config.js index 9109eb528..3289d648c 100644 --- a/platform/viewer/jest.config.js +++ b/platform/viewer/jest.config.js @@ -1,26 +1,14 @@ -const path = require("path"); +const base = require("../../jest.config.base.js"); +const pkg = require("./package"); module.exports = { - verbose: true, - testMatch: ["/src/**/*.test.js"], - // - collectCoverage: false, - collectCoverageFrom: [ - "/src/**/*.{js,jsx}", - "!/src/**/*.test.js", - "!**/node_modules/**", - "!**/__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)$": - "/src/__mocks__/fileMock.js", - "\\.(css|less)$": "identity-obj-proxy" - }, - setupFiles: ["../../node_modules/jest-canvas-mock/lib/index.js"], - setupTestFrameworkScriptFile: "/src/__tests__/globalSetup.js" + ...base, + name: pkg.name, + displayName: pkg.name, + setupFilesAfterEnv: ["/src/__tests__/globalSetup.js"] + // rootDir: "../.." + // testMatch: [ + // //`/platform/${pack.name}/**/*.spec.js` + // "/platform/viewer/**/*.test.js" + // ] }; diff --git a/platform/viewer/package.json b/platform/viewer/package.json index 69d59b54d..088ded6fe 100644 --- a/platform/viewer/package.json +++ b/platform/viewer/package.json @@ -14,15 +14,13 @@ "proxy": "http://localhost:8042", "scripts": { "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", - "cm": "npx git-cz", + "lerna:test:unit": "jest --ci --runInBand --collectCoverage && codecov -F viewer", "dev": "yarn run preBuild && 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: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: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:e2e:ci": "start-server-and-test start http://localhost:5000 cy:run:ci", "start": "yarn run dev",