Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Use Jest for testing #58

Merged
2 commits merged into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -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"
}
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down