Skip to content

Commit

Permalink
migrate to jest fix jhipster/generator-jhipster#15171
Browse files Browse the repository at this point in the history
  • Loading branch information
deepu105 committed May 31, 2021
1 parent 0e2d6ba commit 361cd53
Show file tree
Hide file tree
Showing 22 changed files with 5,974 additions and 4,237 deletions.
6 changes: 4 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
node_modules/
tests/karma.conf.js
webpack.config.js
target/
build/
bundles/
lib/
coverage/
node_modules/
jest.conf.js
node/
postcss.config.js
105 changes: 68 additions & 37 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,79 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"jhipster-react"
"plugin:react/recommended",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier",
"eslint-config-prettier"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"project": "./tsconfig.json"
},
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"@typescript-eslint/explicit-module-boundary-types": [
"warn"
],
"@typescript-eslint/no-unsafe-assignment": [
"warn"
],
"@typescript-eslint/no-unsafe-call": [
"warn"
],
"@typescript-eslint/no-unsafe-member-access": [
"warn"
],
"@typescript-eslint/no-unsafe-return": [
"warn"
],
"no-shadow": [
"warn"
],
"@typescript-eslint/restrict-template-expressions": [
"warn"
],
"@typescript-eslint/restrict-plus-operands": [
"warn"
"@typescript-eslint/member-ordering": [
"error",
{
"default": ["static-field", "instance-field", "constructor", "static-method", "instance-method"]
}
],
"@typescript-eslint/no-parameter-properties": ["warn", { "allows": ["public", "private", "protected"] }],
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/ban-types": [
"warn"
]
},
"overrides": [
{
"files": ["./tests/spec/**/*"],
"rules": {
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off"
"error",
{
"types": {
"Object": "Use {} instead."
}
}
}
]
],
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/array-type": "off",
"@typescript-eslint/no-shadow": "error",
"spaced-comment": ["warn", "always"],
"guard-for-in": "error",
"no-labels": "error",
"no-caller": "error",
"no-bitwise": "error",
"no-console": ["error", { "allow": ["warn", "error"] }],
"no-new-wrappers": "error",
"no-eval": "error",
"no-new": "error",
"no-var": "error",
"radix": "error",
"eqeqeq": ["error", "always", { "null": "ignore" }],
"prefer-const": "error",
"object-shorthand": ["error", "always", { "avoidExplicitReturnArrows": true }],
"default-case": "error",
"complexity": ["error", 40],
"no-invalid-this": "off",
"react/prop-types": "off",
"react/display-name": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ coverage
*.metadata.json
/bundles
/lib/tests
build/

#################
## IDE
Expand Down
53 changes: 53 additions & 0 deletions jest.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const tsconfig = require('./tsconfig.json');

module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testURL: 'http://localhost/',
cacheDirectory: '<rootDir>/build/jest-cache',
coverageDirectory: '<rootDir>/build/test-results/',
testMatch: ['<rootDir>/src/**/@(*.)@(spec.ts?(x))'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
moduleNameMapper: mapTypescriptAliasToJestAlias({
'\\.(css|scss)$': 'identity-obj-proxy',
}),
reporters: ['default', ['jest-junit', { outputDirectory: './build/test-results/', outputName: 'TESTS-results-jest.xml' }]],
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
globals: {
'ts-jest': {
tsconfig: './tsconfig.test.json',
compiler: 'typescript',
diagnostics: false,
},
},
};

function mapTypescriptAliasToJestAlias(alias = {}) {
const jestAliases = { ...alias };
if (!tsconfig.compilerOptions.paths) {
return jestAliases;
}
Object.entries(tsconfig.compilerOptions.paths)
.filter(([key, value]) => {
// use Typescript alias in Jest only if this has value
if (value.length) {
return true;
}
return false;
})
.map(([key, value]) => {
// if Typescript alias ends with /* then in Jest:
// - alias key must end with /(.*)
// - alias value must end with /$1
const regexToReplace = /(.*)\/\*$/;
const aliasKey = key.replace(regexToReplace, '$1/(.*)');
const aliasValue = value[0].replace(regexToReplace, '$1/$$1');
return [aliasKey, `<rootDir>/${aliasValue}`];
})
.reduce((aliases, [key, value]) => {
aliases[key] = value;
return aliases;
}, jestAliases);
return jestAliases;
}
127 changes: 0 additions & 127 deletions karma.conf.js

This file was deleted.

Loading

0 comments on commit 361cd53

Please sign in to comment.