Skip to content

Commit

Permalink
Add theforeman github actions for JS tests
Browse files Browse the repository at this point in the history
* Adapt jest.config.js for JS test suite
* Fix webpack/lib katello tests
* Upgrade @testing-library/react to 14.2.2
* Add preliminary test for StatusPropertiesLabel
  • Loading branch information
bastian-src committed Mar 27, 2024
1 parent ad430ce commit 483d16d
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 157 deletions.
26 changes: 10 additions & 16 deletions .github/workflows/js_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ on:
- 'package.json'
- 'package-lock.json'
- '.github/workflows/js_tests.yml'

concurrency:
group: ${{ github.ref_name }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
test_js:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [12, 14]
steps:
- uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Npm install
run: npm install
- name: Run plugin linter
run: npm run lint
test:
name: JavaScript
uses: theforeman/actions/.github/workflows/foreman_plugin_js.yml@v0
with:
plugin: foreman_resource_quota
57 changes: 26 additions & 31 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
const { foremanLocation, foremanRelativePath } = require('@theforeman/find-foreman')
const tfmConfig = require('@theforeman/test/src/pluginConfig');
const {
foremanRelativePath,
foremanLocation,
} = require('@theforeman/find-foreman');

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

// Jest configuration
module.exports = {
testURL: 'http://localhost/',
setupFiles: [
'./webpack/test_setup.js',
],
setupFilesAfterEnv: [
'./webpack/global_test_setup.js',
'@testing-library/jest-dom'
],
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/foreman/',
'<rootDir>/.+fixtures.+',
'<rootDir>/engines',
],
moduleDirectories: [
`${foremanFull}/node_modules`,
`${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`,
'node_modules',
'webpack/test-utils',
],
modulePathIgnorePatterns: [
'<rootDir>/foreman/',
],
moduleNameMapper: {
'^.+\\.(css|scss)$': 'identity-obj-proxy',
'^foremanReact(.*)$': `${foremanReactFull}/$1`,
},
};
// 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;
Loading

0 comments on commit 483d16d

Please sign in to comment.