Skip to content

Commit

Permalink
Refs #29637 - Updating to dynamically find path
Browse files Browse the repository at this point in the history
  • Loading branch information
John Mitsch committed Apr 30, 2020
1 parent c87a143 commit 9eca1fa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
68 changes: 47 additions & 21 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,64 @@
const path = require('path')
//const foremanReact = path.join(__dirname, "../foreman/webpack/assets/javascripts/react_app")
const foremanReact = "/home/jenkins/workspace/katello-pr-test/foreman/webpack/assets/javascripts/react_app"
const path = require('path');
const fs = require('fs');

// Check for foremanReact files provided by Foreman and make available as module in Jest.
const checkForForemanReact = (foremanLocations, foremanReact) => {
const currentDir = process.cwd();

let foremanReactFullPath;
foremanLocations.forEach((relativeForemanPath) => {
if (fs.existsSync(path.join(currentDir, relativeForemanPath))) {
const fullPath = path.join(currentDir, relativeForemanPath, foremanReact);
if (fs.existsSync(fullPath)) foremanReactFullPath = fullPath;
}
});
return foremanReactFullPath;
};

const foremanReactRelative = 'webpack/assets/javascripts/react_app';
const possibleForemanLocations = ['./foreman', '../foreman', '../../foreman'];
const notFound = 'Foreman directory can not be found! These tests require Foreman to be present ' +
'in either a parent, sibling, child directory relative to Katello and contain the expected ' +
`files in ./${foremanReactRelative}, relative to the Foreman directory.`;

const foremanReactFull = checkForForemanReact(possibleForemanLocations, foremanReactRelative);
if (!foremanReactFull) throw new Error(notFound);

// Jest configuration
module.exports = {
collectCoverage: true,
collectCoverageFrom: [
"webpack/**/*.js",
"!webpack/**/bundle*"
'webpack/**/*.js',
'!webpack/**/bundle*',
],
coverageReporters: [
"lcov"
'lcov',
],
testURL: "http://localhost/",
testURL: 'http://localhost/',
setupFiles: [
"raf/polyfill",
"./webpack/test_setup.js"
'raf/polyfill',
'./webpack/test_setup.js',
],
setupFilesAfterEnv: [
"./webpack/global_test_setup.js"
'./webpack/global_test_setup.js',
],
testPathIgnorePatterns: [
"/node_modules/",
"<rootDir>/foreman/",
"<rootDir>/.+fixtures.+",
"<rootDir>/engines"
'/node_modules/',
'<rootDir>/foreman/',
'<rootDir>/.+fixtures.+',
'<rootDir>/engines',
],
moduleDirectories: [
"node_modules/@theforeman/vendor-core/node_modules",
"node_modules",
"webpack/test-utils"
'node_modules/@theforeman/vendor-core/node_modules',
'node_modules',
'webpack/test-utils',
],
modulePathIgnorePatterns: [
'<rootDir>/foreman/',
],
moduleNameMapper: {
"^.+\\.(css|scss)$": "identity-obj-proxy",
"foremanReact(.*)$": `${foremanReact}$1`
}
}
'^.+\\.(css|scss)$': 'identity-obj-proxy',
'^foremanReact(.*)$': `${foremanReactFull}$1`,
},
};

3 changes: 3 additions & 0 deletions webpack/__mocks__/react-intl/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const addLocaleData = jest.fn();
export const FormattedRelative = jest.fn();
export const intlShape = jest.fn();
1 change: 1 addition & 0 deletions webpack/__mocks__/react-intl/locale-data/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};

0 comments on commit 9eca1fa

Please sign in to comment.