fix tests for core plugins

This commit is contained in:
Sebastian Sdorra
2019-10-09 11:22:16 +02:00
parent d7e62fadb0
commit 9a56ea50e7
13 changed files with 87 additions and 18 deletions

View File

@@ -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"
}
}
}

View File

@@ -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(

View File

@@ -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);
});
});

View File

@@ -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"
}
}
}

View File

@@ -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"
}
}
}

View File

@@ -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"
}
}
}

View File

@@ -75,17 +75,17 @@
<script>build</script>
</configuration>
</execution>
<!--execution>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<script>test-ci</script>
<script>test</script>
<skip>${skipTests}</skip>
</configuration>
</execution-->
</execution>
</executions>
</plugin>

View File

@@ -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

View File

@@ -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
]
});

View File

@@ -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"
}
]
]
};

View File

@@ -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"
}
]
]
};

View File

@@ -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",

View File

@@ -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"
},