mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 17:56:17 +01:00
fix collecting coverage for jest tests
This commit is contained in:
9
lerna.json
Normal file
9
lerna.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
"scm-ui/*",
|
||||||
|
"scm-plugins/*"
|
||||||
|
],
|
||||||
|
"npmClient": "yarn",
|
||||||
|
"useWorkspaces": true,
|
||||||
|
"version": "2.0.0-SNAPSHOT"
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack --mode=production --config=scm-ui/scripts/webpack.config.js",
|
"build": "webpack --mode=production --config=scm-ui/scripts/webpack.config.js",
|
||||||
"build:dev": "webpack --mode=development --config=scm-ui/scripts/webpack.config.js",
|
"build:dev": "webpack --mode=development --config=scm-ui/scripts/webpack.config.js",
|
||||||
"test": "jest",
|
"test": "lerna run --scope '@scm-manager/ui-*' test",
|
||||||
"serve": "webpack-dev-server --mode=development --config=scm-ui/scripts/webpack.config.js"
|
"serve": "webpack-dev-server --mode=development --config=scm-ui/scripts/webpack.config.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
"flow-mono-cli": "^1.5.0",
|
"flow-mono-cli": "^1.5.0",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"jest-junit": "^8.0.0",
|
"jest-junit": "^8.0.0",
|
||||||
|
"lerna": "^3.17.0",
|
||||||
"mustache": "^3.1.0",
|
"mustache": "^3.1.0",
|
||||||
"node-sass": "^4.12.0",
|
"node-sass": "^4.12.0",
|
||||||
"prettier": "^1.18.2",
|
"prettier": "^1.18.2",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const rootDir = path.resolve(__dirname, "..");
|
|
||||||
const reportDirectory = path.join(rootDir, "target", "jest-reports");
|
|
||||||
const mockDirectory = path.resolve(__dirname, "src", "__mocks__");
|
const mockDirectory = path.resolve(__dirname, "src", "__mocks__");
|
||||||
|
const findName = require("./src/findName");
|
||||||
|
const findTarget = require("./src/findTarget");
|
||||||
|
|
||||||
// Set timezone for tests, this is required to get same date values
|
// Set timezone for tests, this is required to get same date values
|
||||||
// accross diferent machines such ci-server and dev box.
|
// accross diferent machines such ci-server and dev box.
|
||||||
@@ -10,11 +10,25 @@ const mockDirectory = path.resolve(__dirname, "src", "__mocks__");
|
|||||||
// @see https://stackoverflow.com/questions/56261381/how-do-i-set-a-timezone-in-my-jest-config
|
// @see https://stackoverflow.com/questions/56261381/how-do-i-set-a-timezone-in-my-jest-config
|
||||||
process.env.TZ = "Europe/Berlin";
|
process.env.TZ = "Europe/Berlin";
|
||||||
|
|
||||||
|
const root = process.cwd();
|
||||||
|
const name = findName(root);
|
||||||
|
const target = findTarget(root);
|
||||||
|
const reportDirectory = path.join(target, "jest-reports");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
rootDir,
|
rootDir: root,
|
||||||
|
roots: [
|
||||||
|
root
|
||||||
|
],
|
||||||
|
testPathDirs: [
|
||||||
|
path.join(root, "src")
|
||||||
|
],
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.js$": "@scm-manager/jest-preset"
|
"^.+\\.js$": "@scm-manager/jest-preset"
|
||||||
},
|
},
|
||||||
|
transformIgnorePatterns: [
|
||||||
|
"node_modules/(?!(@scm-manager)/)"
|
||||||
|
],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
"\\.(png|svg|jpg|gif|woff2?|eot|ttf)$": path.join(
|
"\\.(png|svg|jpg|gif|woff2?|eot|ttf)$": path.join(
|
||||||
mockDirectory,
|
mockDirectory,
|
||||||
@@ -24,16 +38,22 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
setupFiles: [path.resolve(__dirname, "src", "setup.js")],
|
setupFiles: [path.resolve(__dirname, "src", "setup.js")],
|
||||||
collectCoverage: true,
|
collectCoverage: true,
|
||||||
coverageDirectory: path.join(reportDirectory, "coverage"),
|
collectCoverageFrom: [
|
||||||
coveragePathIgnorePatterns: ["src/tests/.*"],
|
"src/**/*.{js,jsx}"
|
||||||
|
],
|
||||||
|
coverageDirectory: path.join(reportDirectory, "coverage-" + name),
|
||||||
|
coveragePathIgnorePatterns: [
|
||||||
|
"src/tests/.*",
|
||||||
|
"src/testing/.*"
|
||||||
|
],
|
||||||
reporters: [
|
reporters: [
|
||||||
"default",
|
"default",
|
||||||
[
|
[
|
||||||
"jest-junit",
|
"jest-junit",
|
||||||
{
|
{
|
||||||
suiteName: "SCM-UI Package tests",
|
suiteName: name + " tests",
|
||||||
outputDirectory: reportDirectory,
|
outputDirectory: reportDirectory,
|
||||||
outputName: "TEST-scm-ui.xml"
|
outputName: "TEST-" + name + ".xml"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|||||||
15
scm-ui/jest-preset/src/findName.js
Normal file
15
scm-ui/jest-preset/src/findName.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
function findName(directory) {
|
||||||
|
const packageJSON = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), {encoding: "UTF-8"}));
|
||||||
|
|
||||||
|
let name = packageJSON.name;
|
||||||
|
const orgaIndex = name.indexOf("/");
|
||||||
|
if (orgaIndex > 0) {
|
||||||
|
return name.substring(orgaIndex + 1);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = findName;
|
||||||
16
scm-ui/jest-preset/src/findTarget.js
Normal file
16
scm-ui/jest-preset/src/findTarget.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
function findMavenModuleRoot(directory) {
|
||||||
|
if (fs.existsSync(path.join(directory, "pom.xml"))) {
|
||||||
|
return directory;
|
||||||
|
}
|
||||||
|
return findMavenModuleRoot(path.resolve(directory, ".."));
|
||||||
|
}
|
||||||
|
|
||||||
|
function findTarget(directory) {
|
||||||
|
const moduleRoot = findMavenModuleRoot(directory);
|
||||||
|
return path.join(moduleRoot, "target");
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = findTarget;
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
const { createTransformer } = require("babel-jest");
|
const babelJest = require("babel-jest");
|
||||||
const transformer = createTransformer({
|
const transformer = babelJest.createTransformer({
|
||||||
presets: ["@scm-manager/babel-preset"],
|
presets: ["@scm-manager/babel-preset"],
|
||||||
plugins: ["require-context-hook"]
|
plugins: ["require-context-hook"],
|
||||||
|
babelrc: false,
|
||||||
|
configFile: false
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
...transformer,
|
||||||
process(src, filename) {
|
process(src, filename) {
|
||||||
if (
|
if (
|
||||||
!filename.includes("node_modules") ||
|
!filename.includes("node_modules") ||
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
<sonar.test.exclusions>**/*.test.js,src/tests/**</sonar.test.exclusions>
|
<sonar.test.exclusions>**/*.test.js,src/tests/**</sonar.test.exclusions>
|
||||||
<sonar.coverage.exclusions>**/*.test.js,src/tests/**</sonar.coverage.exclusions>
|
<sonar.coverage.exclusions>**/*.test.js,src/tests/**</sonar.coverage.exclusions>
|
||||||
<sonar.javascript.jstest.reportsPath>target/jest-reports</sonar.javascript.jstest.reportsPath>
|
<sonar.javascript.jstest.reportsPath>target/jest-reports</sonar.javascript.jstest.reportsPath>
|
||||||
<sonar.javascript.lcov.reportPaths>target/jest-reports/coverage/lcov.info</sonar.javascript.lcov.reportPaths>
|
<sonar.javascript.lcov.reportPaths>target/jest-reports/coverage-*/lcov.info</sonar.javascript.lcov.reportPaths>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"private": false,
|
"private": false,
|
||||||
"author": "Sebastian Sdorra <sebastian.sdorra@cloudogu.com>",
|
"author": "Sebastian Sdorra <sebastian.sdorra@cloudogu.com>",
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^16.10.2"
|
"react": "^16.10.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"private": false,
|
"private": false,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"babel-plugin-istanbul": "^5.2.0",
|
||||||
"enzyme": "^3.10.0",
|
"enzyme": "^3.10.0",
|
||||||
"enzyme-adapter-react-16": "^1.15.0",
|
"enzyme-adapter-react-16": "^1.15.0",
|
||||||
"enzyme-context": "^1.1.2",
|
"enzyme-context": "^1.1.2",
|
||||||
|
|||||||
Reference in New Issue
Block a user