Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Jul 18, 2024
1 parent 8ccc9eb commit 0382a92
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 19 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/plugins_react_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
# We could update the postinstall action for foreman to look for an environment variable for plugin webpack dirs
# before kicking off the ruby script to find them, this would eliminate the ruby dep and running `npm install` in plugins.
- uses: ruby/setup-ruby@v1
- name: "Set up Ruby ${{ matrix.ruby }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Checkout Foreman
uses: actions/checkout@v4
with:
Expand All @@ -68,12 +68,29 @@ jobs:
with:
repository: ${{ matrix.plugin }}
path: ${{ github.workspace }}/projects/plugin
- name: store plugin name
run: echo "PLUGIN_NAME=$(echo ${{ matrix.plugin }} | awk -F'/' '{print $NF}')" >> "${GITHUB_ENV}"
- name: Set up plugin in Foreman
run: |
echo "gemspec name: '$PLUGIN_NAME', path: '${{ github.workspace }}/projects/plugin'" > "bundler.d/$PLUGIN_NAME.local.rb"
if [ -d $PLUGIN_NAME/gemfile.d ] ; then
cat $PLUGIN_NAME/gemfile.d/*.rb >> bundler.d/$PLUGIN_NAME.local.rb
fi
working-directory: ${{ github.workspace }}/projects/foreman
- name: Generate ${{ matrix.plugin }} npm dependencies package-lock
run: npm install --package-lock-only --no-audit --legacy-peer-deps
working-directory: ${{ github.workspace }}/projects/plugin
- name: Install ${{ matrix.plugin }} npm dependencies
run: npm ci --no-audit --legacy-peer-deps
working-directory: ${{ github.workspace }}/projects/plugin
- run: sudo apt-get update
- run: sudo apt-get -qq -y install build-essential libcurl4-openssl-dev zlib1g-dev libpq-dev libvirt-dev
- name: Install gems
run: bundle install
working-directory: ${{ github.workspace }}/projects/foreman
- name: Run plugin webpack dir to test
run: ./script/plugin_webpack_directories.rb
working-directory: ${{ github.workspace }}/projects/foreman
- name: Run ${{ matrix.plugin }} tests
run: npm run test:plugins $(echo ${{ matrix.plugin }} | awk -F'/' '{print $NF}')
working-directory: ${{ github.workspace }}/projects/foreman
14 changes: 9 additions & 5 deletions script/npm_test_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var fs = require('fs');
var path = require('path');
var lodash = require('lodash');
var childProcess = require('child_process');
var { packageJsonDirs } = require('./plugin_webpack_directories');
var { packageJsonDirsObject } = require('./plugin_webpack_directories');

const passedArgs = process.argv.slice(2);
const coreConfigPath = path.resolve(__dirname, '../webpack/jest.config.js');
Expand Down Expand Up @@ -51,7 +51,10 @@ function runChildProcess(args, pluginPath) {
});
}
const runTests = async () => {
var dirs = packageJsonDirs();
// var dirs = packageJsonDirs();
var dirs = packageJsonDirsObject();
var dirsKeys = Object.keys(dirs);
console.log('dirs', dirs);
function pluginDefinesLint(pluginPath) {
var packageHasNodeModules = fs.existsSync(`${pluginPath}/node_modules`); // skip gems
var packageData = JSON.parse(fs.readFileSync(`${pluginPath}/package.json`));
Expand All @@ -61,7 +64,7 @@ const runTests = async () => {
);
}
if (passedArgs[0] && passedArgs[0][0] !== '-') {
dirs = dirs.filter(dir => dir.endsWith(passedArgs[0]));
dirsKeys = dirsKeys.filter(dir => dir.endsWith(passedArgs[0]));
passedArgs.shift();
}
function customizer(objValue, srcValue) {
Expand All @@ -71,7 +74,8 @@ const runTests = async () => {
return undefined;
}
// eslint-disable-next-line no-unused-vars
for (const pluginPath of dirs) {
for (const dirsKey of dirsKeys) {
const pluginPath = dirs[dirsKey];
if (pluginDefinesLint(pluginPath)) {
const testSetupFiles = [
path.resolve(__dirname, '../webpack/global_test_setup.js'),
Expand Down Expand Up @@ -125,7 +129,7 @@ const runTests = async () => {
'--color',
...passedArgs,
];

console.log('args', args);
// eslint-disable-next-line no-await-in-loop
await runChildProcess(args, pluginPath); // Run every plugin test in a separate process
if (fs.existsSync(combinedConfigPath)) {
Expand Down
17 changes: 17 additions & 0 deletions script/plugin_webpack_directories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ var sanitizeWebpackDirs = pluginDirs => {
return splitDirs.length > 2 ? splitDirs[1] : pluginDirs;
};

var pluginPathObject = file => pluginsObj => {
var paths = {};
Object.keys(pluginsObj.plugins).forEach(entryKey => {
if (!entryKey.includes(':')) {
const pluginPath = pluginsObj.plugins[entryKey].root;
if (fs.existsSync(path.join(pluginPath, file))) {
paths[entryKey] = pluginPath;
}
}
});
return paths;
};

// Get paths that have a specific file or folder
var pluginPath = file => pluginsObj => {
var paths = [];
Expand Down Expand Up @@ -53,11 +66,15 @@ var getPluginDirs = stderr =>
var packageJsonDirs = stderr =>
pluginPath('package.json')(getPluginDirs(stderr)).map(path.dirname);

var packageJsonDirsObject = stderr =>
pluginPathObject('package.json')(getPluginDirs(stderr));

module.exports = {
getPluginDirs,
pluginNodeModules: pluginPath('node_modules'),
aliasPlugins,
packageJsonDirs,
packageJsonDirsObject,
sanitizeWebpackDirs,
pluginPath,
};
14 changes: 4 additions & 10 deletions webpack/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ const vendorCorePackageJson = JSON.parse(
fs.readFileSync(vendorCorePackageJsonPath, 'utf8')
);
// const vendorDependencies = Object.keys(vendorCorePackageJson.dependencies);
// const customVendorDependencies = {};
// vendorDependencies.forEach(dep => {
// const customVendorDependencies = vendorDependencies.map(dep => {
// const module = foremanJsModules.find(m => m.name === dep);
// if (module?.hasCustomPath) {
// console.log('module.path', module);
// customVendorDependencies[`^${dep}$`] = path.resolve(
// nodeModules,
// module.path
// );
// } else {
// customVendorDependencies[`^${dep}$`] = path.resolve(nodeModules, dep);
// return { [`^${dep}$`]: module.path };
// }
// return { [`^${dep}$`]: path.resolve(nodeModules, dep) };
// // todo delete resolveNodeModule
// });
// console.log(customVendorDependencies);
Expand All @@ -37,7 +31,7 @@ const dependencies = {
'@apollo/client/testing': '@apollo/client/testing',
}; // Use shared dependencies from foreman node_modules and not plugin node_modules to avoid jest errors due to multiple instances of same package

var moduleNameMapper = {};
const moduleNameMapper = {};
Object.keys(dependencies).forEach(dep => {
moduleNameMapper[`^${dep}$`] = path.resolve(nodeModules, dep);
});
Expand Down
2 changes: 1 addition & 1 deletion webpack/theforeman-test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './theforeman_test_dependencies';
// todo: deprecate
// todo: deprecate

0 comments on commit 0382a92

Please sign in to comment.