From bced26ae3a6cd851bcaeb9add40883c8a6c7e83a Mon Sep 17 00:00:00 2001 From: dvvanessastoiber Date: Fri, 27 Mar 2020 11:30:13 +0100 Subject: [PATCH 1/2] add testing dependencies --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index b70a03e..16301c3 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "@types/d3-brush": "^1.0.8", "@types/d3-drag": "^1.2.1", "@types/d3-format": "^1.3.0", + "@types/jest": "25.1.4", "@types/d3-polygon": "^1.0.6", "cache-loader": "^1.2.2", "css-loader": "^1.0.0", @@ -89,7 +90,10 @@ "extract-text-webpack-plugin": "^4.0.0-beta.0", "file-loader": "^1.1.11", "fork-ts-checker-webpack-plugin": "^0.4.4", + "jest": "25.1.0", + "jest-raw-loader": "1.0.1", "json-loader": "^0.5.7", + "identity-obj-proxy": "^3.0.0", "mkdirp": "^0.5.1", "node-sass": "^4.12.0", "raw-loader": "^1.0.0-beta.0", @@ -104,6 +108,7 @@ "tslint": "^5.11.0", "tslint-consistent-codestyle": "^1.13.3", "tslint-eslint-rules": "^5.3.1", + "ts-jest": "25.2.1", "typedoc": "^0.11.1", "typedoc-plugin-as-member-of": "^1.0.2", "typescript": "^3.0.1", From bfb96843d18783066978bb179e1249befc64bf03 Mon Sep 17 00:00:00 2001 From: dvvanessastoiber Date: Fri, 27 Mar 2020 11:30:19 +0100 Subject: [PATCH 2/2] add jest config --- jest.config.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 jest.config.js diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..65bbf39 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,55 @@ +// test dependencies that require transformation +let pluginsToTransform = [ + 'tdp_*', + 'phovea_*', + 'lineupjs' +].join('|'); + +if(pluginsToTransform.length > 0) { + /** Attention: Negative Lookahead! This regex adds the specified repos to a whitelist that holds plugins that are excluded from the transformIgnorePatterns. + * This means that pluginsToTransform should contain all repos that export ts files. They can only be handled by the transformation. */ + pluginsToTransform = `(?!${pluginsToTransform})`; +} + +/** + * TODO check if we can process inline webpack loaders (e.g. as found in https://github.com/phovea/phovea_ui/blob/master/src/_bootstrap.ts) + * see also https://jestjs.io/docs/en/webpack#mocking-css-modules + */ +module.exports = { + transform: { + "^.+\\.tsx?$": "ts-jest", + "\\.xml$": "jest-raw-loader" + }, + testRegex: "(.*(test|spec))\\.(tsx?)$", + moduleFileExtensions: [ + "ts", + "tsx", + "js", + "jsx", + "json", + "node" + ], + modulePaths: [ + "src", + "../node_modules", + "../" + ], + transformIgnorePatterns: [`../node_modules/${pluginsToTransform}`, `node_modules/${pluginsToTransform}`], + globals: { + "__VERSION__": "TEST_VERSION", + "__APP_CONTEXT__": "TEST_CONTEXT", + 'ts-jest': { + // has to be set to true, otherwise i18n import fails + "tsConfig": { + "esModuleInterop": true, + } + } + }, + moduleNameMapper: { + "^.+\\.(css|less|scss|sass|png|jpg|gif)$": "identity-obj-proxy", + "imports-loader?.*": "imports-loader", + "raw-loader?.*": "raw-loader", + "file-loader?.*": "file-loader", + "script-loader?.*": "script-loader" + } +}