Skip to content

Commit

Permalink
Switch to tfm-test
Browse files Browse the repository at this point in the history
  • Loading branch information
dosas committed May 15, 2024
1 parent 3c76c59 commit c468077
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
67 changes: 30 additions & 37 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
module.exports = {
verbose: true,
testMatch: ['**/*.test.js'],
testPathIgnorePatterns: [
'.local',
'.bundle',
'/node_modules/',
'<rootDir>/foreman/',
],
moduleDirectories: ['node_modules', 'webpack'],
testURL: 'http://localhost/',
collectCoverage: true,
collectCoverageFrom: [
'webpack/**/*.js',
'!webpack/js-yaml.js',
'!webpack/index.js',
'!webpack/test_setup.js',
'!webpack/**/bundle*',
'!webpack/stories/**',
'!webpack/**/*stories.js',
],
coverageReporters: ['text', 'lcov'],
moduleNameMapper: {
'^.+\\.(png|gif|css|scss)$': 'identity-obj-proxy',
},
globals: {
__testing__: true,
},
transform: {
'^.+\\.js$': 'babel-jest',
},
setupFiles: [
'raf/polyfill',
'jest-prop-type-error',
'./webpack/test_setup.js',
],
};
const tfmConfig = require('@theforeman/test/src/pluginConfig');
const {
foremanRelativePath,
foremanLocation,
} = require('@theforeman/find-foreman');

Check failure on line 5 in jest.config.js

View workflow job for this annotation

GitHub Actions / test_js (14)

'@theforeman/find-foreman' should be listed in the project's dependencies. Run 'npm i -S @theforeman/find-foreman' to add it

const foremanReactRelative = 'webpack/assets/javascripts/react_app';
const foremanFull = foremanLocation();
const foremanReactFull = foremanRelativePath(foremanReactRelative);

// Find correct path to foremanReact so we do not have to mock it in tests
tfmConfig.moduleNameMapper['^foremanReact(.*)$'] = `${foremanReactFull}/$1`;

tfmConfig.setupFiles = ['./webpack/test_setup.js'];
tfmConfig.setupFilesAfterEnv = [
'./webpack/global_test_setup.js',
'@testing-library/jest-dom',
];

// Do not use default resolver
tfmConfig.resolver = null;
// Specify module dirs instead
tfmConfig.moduleDirectories = [
`${foremanFull}/node_modules`,
`${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`,
'node_modules',
'webpack/test-utils',
];

module.exports = tfmConfig;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint-fix": "eslint --fix *.js webpack",
"stylelint": "stylelint webpack/**/*.scss",
"stylelint-fix": "stylelint webpack/**/*.scss --fix",
"test": "jest --no-cache webpack"
"test": "tfm-test --plugin --config jest.config.js"
},
"repository": {
"type": "git",
Expand Down
11 changes: 11 additions & 0 deletions webpack/global_test_setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// runs before each test to make sure console.error output will
// fail a test (i.e. default PropType missing). Check the error
// output and traceback for actual error.
global.console.error = (error, stack) => {
/* eslint-disable-next-line no-console */
if (stack) console.log(stack); // Prints out original stack trace
throw new Error(error);
};

// Increase jest timeout as some tests using multiple http mocks can time out on CI systems.
jest.setTimeout(10000);

0 comments on commit c468077

Please sign in to comment.