From 9a56ea50e7d11b37c00933f74bd9494299eec977 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 9 Oct 2019 11:22:16 +0200 Subject: [PATCH] fix tests for core plugins --- scm-plugins/scm-git-plugin/package.json | 5 ++-- .../scm-git-plugin/src/main/js/index.js | 2 +- .../scm-git-plugin/src/main/js/index.test.js | 4 +-- scm-plugins/scm-hg-plugin/package.json | 8 ++++- scm-plugins/scm-legacy-plugin/package.json | 8 ++++- scm-plugins/scm-svn-plugin/package.json | 8 ++++- scm-ui/pom.xml | 6 ++-- scm-ui/scripts/babelMonoRepoTransformer.js | 6 ++-- scm-ui/scripts/babelPluginTransformer.js | 16 ++++++++++ scm-ui/scripts/jest-plugin.config.js | 30 +++++++++++++++++++ scm-ui/scripts/jest.config.js | 6 +++- scm-ui/ui-components/package.json | 3 +- scm-ui/ui-webapp/package.json | 3 +- 13 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 scm-ui/scripts/babelPluginTransformer.js create mode 100644 scm-ui/scripts/jest-plugin.config.js diff --git a/scm-plugins/scm-git-plugin/package.json b/scm-plugins/scm-git-plugin/package.json index c34d31d2b4..e2ce5c09e5 100644 --- a/scm-plugins/scm-git-plugin/package.json +++ b/scm-plugins/scm-git-plugin/package.json @@ -3,7 +3,8 @@ "version": "2.0.0-SNAPSHOT", "license": "BSD-3-Clause", "scripts": { - "build": "webpack --mode=development" + "build": "webpack --mode=development", + "test": "jest --config=../../scm-ui/scripts/jest-plugin.config.js" }, "devDependencies": { "flow-bin": "^0.109.0", @@ -11,7 +12,7 @@ }, "jest": { "transform": { - "^.+\\.js$": "../../scm-ui/scripts/babelMonoRepoTransformer.js" + "^.+\\.js$": "../../scm-ui/scripts/babelPluginTransformer.js" } } } diff --git a/scm-plugins/scm-git-plugin/src/main/js/index.js b/scm-plugins/scm-git-plugin/src/main/js/index.js index c4b323342c..db50ce6de1 100644 --- a/scm-plugins/scm-git-plugin/src/main/js/index.js +++ b/scm-plugins/scm-git-plugin/src/main/js/index.js @@ -14,7 +14,7 @@ import RepositoryConfig from "./RepositoryConfig"; // @visibleForTesting export const gitPredicate = (props: Object) => { - return props.repository && props.repository.type === "git"; + return !!(props && props.repository && props.repository.type === "git"); }; binder.bind( diff --git a/scm-plugins/scm-git-plugin/src/main/js/index.test.js b/scm-plugins/scm-git-plugin/src/main/js/index.test.js index 1274c8fe81..514ed33860 100644 --- a/scm-plugins/scm-git-plugin/src/main/js/index.test.js +++ b/scm-plugins/scm-git-plugin/src/main/js/index.test.js @@ -1,7 +1,7 @@ // @flow import { gitPredicate } from "./index"; -describe("test gi predicate", () => { +describe("test git predicate", () => { it("should return false", () => { expect(gitPredicate()).toBe(false); expect(gitPredicate({})).toBe(false); @@ -10,6 +10,6 @@ describe("test gi predicate", () => { }); it("should return true", () => { - expect(gitPredicate({ repository: { type: "fir" } })).toBe(true); + expect(gitPredicate({ repository: { type: "git" } })).toBe(true); }); }); diff --git a/scm-plugins/scm-hg-plugin/package.json b/scm-plugins/scm-hg-plugin/package.json index 13974bf7fd..57d3da7a30 100644 --- a/scm-plugins/scm-hg-plugin/package.json +++ b/scm-plugins/scm-hg-plugin/package.json @@ -4,6 +4,12 @@ "license": "BSD-3-Clause", "main": "src/main/js/index.js", "scripts": { - "build": "webpack --mode=development" + "build": "webpack --mode=development", + "test": "jest --config=../../scm-ui/scripts/jest-plugin.config.js" + }, + "jest": { + "transform": { + "^.+\\.js$": "../../scm-ui/scripts/babelPluginTransformer.js" + } } } diff --git a/scm-plugins/scm-legacy-plugin/package.json b/scm-plugins/scm-legacy-plugin/package.json index f112608858..9ecd93595e 100644 --- a/scm-plugins/scm-legacy-plugin/package.json +++ b/scm-plugins/scm-legacy-plugin/package.json @@ -4,6 +4,12 @@ "license": "BSD-3-Clause", "main": "src/main/js/index.js", "scripts": { - "build": "webpack --mode=development" + "build": "webpack --mode=development", + "test": "jest --config=../../scm-ui/scripts/jest-plugin.config.js" + }, + "jest": { + "transform": { + "^.+\\.js$": "../../scm-ui/scripts/babelPluginTransformer.js" + } } } diff --git a/scm-plugins/scm-svn-plugin/package.json b/scm-plugins/scm-svn-plugin/package.json index 9d3c8f0f0b..fccbe9ac32 100644 --- a/scm-plugins/scm-svn-plugin/package.json +++ b/scm-plugins/scm-svn-plugin/package.json @@ -4,6 +4,12 @@ "version": "2.0.0-SNAPSHOT", "license": "BSD-3-Clause", "scripts": { - "build": "webpack --mode=development" + "build": "webpack --mode=development", + "test": "jest --config=../../scm-ui/scripts/jest-plugin.config.js" + }, + "jest": { + "transform": { + "^.+\\.js$": "../../scm-ui/scripts/babelPluginTransformer.js" + } } } diff --git a/scm-ui/pom.xml b/scm-ui/pom.xml index a13be4d318..a43edec258 100644 --- a/scm-ui/pom.xml +++ b/scm-ui/pom.xml @@ -75,17 +75,17 @@ - + diff --git a/scm-ui/scripts/babelMonoRepoTransformer.js b/scm-ui/scripts/babelMonoRepoTransformer.js index 9bba3a7c9a..6a79bcd98e 100644 --- a/scm-ui/scripts/babelMonoRepoTransformer.js +++ b/scm-ui/scripts/babelMonoRepoTransformer.js @@ -1,11 +1,11 @@ /** * Read and use .babelrc from packages */ -const { join, resolve } = require("path"); +const path = require("path"); const { createTransformer } = require("babel-jest"); -const packagePath = resolve(__dirname, "../"); -const packageGlob = join(packagePath, "*"); +const packagePath = path.resolve(__dirname, "../"); +const packageGlob = path.join(packagePath, "*"); module.exports = createTransformer({ babelrcRoots: packageGlob diff --git a/scm-ui/scripts/babelPluginTransformer.js b/scm-ui/scripts/babelPluginTransformer.js new file mode 100644 index 0000000000..e7fc404434 --- /dev/null +++ b/scm-ui/scripts/babelPluginTransformer.js @@ -0,0 +1,16 @@ +/** + * Read and use .babelrc from packages + */ +const path = require("path"); +const { createTransformer } = require("babel-jest"); + +const packagePath = path.resolve(__dirname, "../"); +const packageGlob = path.join(packagePath, "*"); +const currentDirectory = path.join(process.cwd()); + +module.exports = createTransformer({ + babelrcRoots: [ + packageGlob, + currentDirectory + ] +}); diff --git a/scm-ui/scripts/jest-plugin.config.js b/scm-ui/scripts/jest-plugin.config.js new file mode 100644 index 0000000000..cbebec43e7 --- /dev/null +++ b/scm-ui/scripts/jest-plugin.config.js @@ -0,0 +1,30 @@ +const path = require("path"); +const fs = require("fs"); +const transformer = path.resolve(__dirname, "babelPluginTransformer.js"); +const rootDir = path.resolve(process.cwd()); +const packageJsonPath = path.join(rootDir, "package.json"); +const packageJson = JSON.parse( + fs.readFileSync(packageJsonPath, { encoding: "UTF-8" }) +); + +const reportDirectory = path.join(rootDir, "target", "jest-reports"); + +module.exports = { + rootDir, + transform: { "^.+\\.js$": transformer }, + transformIgnorePatterns: [".*/node_modules/.*"], + collectCoverage: true, + coverageDirectory: path.join(reportDirectory, "coverage"), + coveragePathIgnorePatterns: ["src/main/js/tests/.*"], + reporters: [ + "default", + [ + "jest-junit", + { + suiteName: packageJson.name + " tests", + outputDirectory: reportDirectory, + outputName: "TEST-plugin.xml" + } + ] + ] +}; diff --git a/scm-ui/scripts/jest.config.js b/scm-ui/scripts/jest.config.js index 09d274ea7a..593451c0d9 100644 --- a/scm-ui/scripts/jest.config.js +++ b/scm-ui/scripts/jest.config.js @@ -12,7 +12,11 @@ module.exports = { "default", [ "jest-junit", - { outputDirectory: reportDirectory, outputName: "TEST-all.xml" } + { + suiteName: "SCM-UI Package tests", + outputDirectory: reportDirectory, + outputName: "TEST-scm-ui.xml" + } ] ] }; diff --git a/scm-ui/ui-components/package.json b/scm-ui/ui-components/package.json index 914f1f5869..c868d7c19b 100644 --- a/scm-ui/ui-components/package.json +++ b/scm-ui/ui-components/package.json @@ -12,7 +12,8 @@ "license": "BSD-3-Clause", "scripts": { "update-index": "create-index -r src", - "eslint-fix": "eslint src --fix" + "eslint-fix": "eslint src --fix", + "test": "jest" }, "devDependencies": { "create-index": "^2.3.0", diff --git a/scm-ui/ui-webapp/package.json b/scm-ui/ui-webapp/package.json index 2d6f0caacf..a9d818795d 100644 --- a/scm-ui/ui-webapp/package.json +++ b/scm-ui/ui-webapp/package.json @@ -49,8 +49,7 @@ "build-js": "ui-bundler bundle --mode=production target/scm-ui/scm-ui.bundle.js", "build-vendor": "ui-bundler vendor --mode=production target/scm-ui/vendor.bundle.js", "build": "npm-run-all -s webfonts build-css polyfills build-vendor build-js", - "test": "ui-bundler test", - "test-ci": "ui-bundler test --ci", + "test": "jest", "flow": "flow", "pre-commit": "jest && flow && eslint src" },