From 51a902d04f5765e16f78ee990a54ee42a4ea75fc Mon Sep 17 00:00:00 2001 From: Markus Bucher Date: Wed, 20 Dec 2023 16:37:35 +0100 Subject: [PATCH] Refactor github actions tests --- .github/workflows/javascript_tests.yml | 25 ++++++++++++ .github/workflows/rubocop.yml | 5 +-- .github/workflows/unit_tests.yml | 43 +++++--------------- jest.config.js | 36 +++++++++++++++++ package.json | 54 ++------------------------ 5 files changed, 75 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/javascript_tests.yml create mode 100644 jest.config.js diff --git a/.github/workflows/javascript_tests.yml b/.github/workflows/javascript_tests.yml new file mode 100644 index 00000000..70424bd8 --- /dev/null +++ b/.github/workflows/javascript_tests.yml @@ -0,0 +1,25 @@ +--- +name: React and Javascript tests +on: + pull_request: + push: + branches: + - master + +jobs: + test_js: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node: [14] + steps: + - uses: actions/checkout@v2 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + - run: npm install + - name: Testing + run: npm run test +... diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 07c639fa..a008eb33 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -14,9 +14,6 @@ jobs: with: ruby-version: 2.7 bundler-cache: true - - name: Setup rubocop - run: | - gem install bundler - name: Execute rubocop run: | - bundle exec rubocop + bundle exec rake rubocop diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index ce04e550..023d6c1a 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -24,9 +24,8 @@ jobs: fail-fast: false matrix: foreman-repo: [theforeman/foreman] - foreman-core-branch: [3.3-stable, 3.4-stable, develop] + foreman-core-branch: [3.8-stable, 3.9-stable, develop] ruby-version: [2.7] - node: [14] steps: - run: | sudo apt-get update @@ -38,55 +37,31 @@ jobs: - uses: actions/checkout@v2 with: path: foreman_acd - - name: Setup Bundler + - name: Add ACD to foreman run: | echo "gem 'foreman_acd', path: './foreman_acd'" > bundler.d/foreman_acd.local.rb - - name: Limit REX and tasks version for Foreman 3.3-stable + - name: Limit REX and tasks version for Foreman 3.8-stable working-directory: foreman_acd - if: ${{ matrix.foreman-core-branch == '3.3-stable' }} + if: ${{ matrix.foreman-core-branch == '3.8-stable' }} run: | - sed -i '23,24d' foreman_acd.gemspec - sed -i '23is.add_dependency "foreman-tasks", "~> 6.0"' foreman_acd.gemspec - sed -i '23is.add_dependency "foreman_remote_execution", "~> 7.2"' foreman_acd.gemspec - - name: Limit REX and tasks version for Foreman 3.4-stable - working-directory: foreman_acd - if: ${{ matrix.foreman-core-branch == '3.4-stable' }} - run: | - sed -i '23,24d' foreman_acd.gemspec - sed -i '23is.add_dependency "foreman-tasks", "~> 7.0"' foreman_acd.gemspec - sed -i '23is.add_dependency "foreman_remote_execution", "~> 8.0"' foreman_acd.gemspec - - name: Limit REX and tasks version for Foreman develop - working-directory: foreman_acd - if: ${{ matrix.foreman-core-branch == 'develop' }} - run: | - sed -i '23,24d' foreman_acd.gemspec - sed -i '23is.add_dependency "foreman-tasks", "~> 7.0"' foreman_acd.gemspec - sed -i '23is.add_dependency "foreman_remote_execution", "~> 9.0"' foreman_acd.gemspec + sed -i '/s\.add_dependency .foreman-tasks./s/,[^,]*$/, "~> 8.3"/' foreman_acd.gemspec + sed -i '/s\.add_dependency .foreman_remote_execution./s/,[^,]*$/, "~> 11.1"/' foreman_acd.gemspec + cat foreman_acd.gemspec + - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node }} + - run: bundle list - name: Prepare test env run: | bundle exec rake db:create bundle exec rake db:migrate bundle exec rake db:test:prepare - - name: Prepare webpack - run: | - npm install - bundle exec rake webpack:compile - name: Run plugin tests run: | bundle exec rake test:foreman_acd - - name: Run npm tests - working-directory: ./foreman_acd - run: | - npm test - name: Run access permission test run: | bundle exec rake test TEST="test/unit/foreman/access_permissions_test.rb" diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..0eca6d15 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,36 @@ +module.exports = { + verbose: true, + testMatch: ['**/*.test.js'], + testPathIgnorePatterns: [ + '.local', + '.bundle', + '/node_modules/', + '/foreman/', + ], + moduleDirectories: ['node_modules', 'webpack'], + testURL: 'http://localhost/', + collectCoverage: true, + collectCoverageFrom: [ + 'webpack/**/*.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', + ], +}; diff --git a/package.json b/package.json index 40e70189..57a57a5a 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,6 @@ "version": "0.9.3", "description": "foreman application centric deployment", "main": "index.js", - "directories": { - "test": "test" - }, "peerDependencies": { "@theforeman/vendor": ">= 10.1.0" }, @@ -25,59 +22,16 @@ "table-resolver": "^3.2.0" }, "scripts": { - "test": "node node_modules/.bin/jest --no-cache" + "test": "jest --no-cache" }, "repository": { "type": "git", "url": "git+https://github.com/ATIX-AG/foreman_acd.git" }, - "author": "", + "author": "ATIX AG ", "license": "ISC", "bugs": { - "url": "https://atix.de" + "url": "https://github.com/ATIX-AG/foreman_acd/issues" }, - "homepage": "https://atix.de", - "jest": { - "verbose": true, - "testMatch": [ - "**/*.test.js" - ], - "testPathIgnorePatterns": [ - ".local", - ".bundle", - "/node_modules/", - "/foreman/" - ], - "moduleDirectories": [ - "node_modules", - "webpack" - ], - "testURL": "http://localhost/", - "collectCoverage": true, - "collectCoverageFrom": [ - "webpack/**/*.js", - "!webpack/index.js", - "!webpack/test_setup.js", - "!webpack/**/bundle*", - "!webpack/stories/**", - "!webpack/**/*stories.js" - ], - "coverageReporters": [ - "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" - ] - } + "homepage": "https://atix.de" }