Commit fc55cc04 authored by Albert Salim's avatar Albert Salim

Introduce jest minimal jobs

jest minimal jobs runs jest with --findRelatedTests
on the files that changed in the merge request

The jobs generally will run before an MR approval, except
when the MR contains the following changes:

  - "{package.json,yarn.lock}"
  - "babel.config.js"
  - "jest.config.{base,integration,unit}.js"
  - "vendor/assets/javascripts/**/*"
  - "{,ee}/app/assets/**/*.graphql"
  - "config/helpers/**/*.js"

The full jest pipeline could also be triggered
using a MR label pipeline:run-all-jest
parent 12d7c00f
...@@ -188,13 +188,14 @@ eslint-as-if-foss: ...@@ -188,13 +188,14 @@ eslint-as-if-foss:
.jest-base: .jest-base:
extends: .frontend-test-base extends: .frontend-test-base
script: script:
- run_timed_command "yarn jest --ci --coverage --testSequencer ./scripts/frontend/parallel_ci_sequencer.js" - run_timed_command "yarn jest:ci"
jest: jest:
extends: extends:
- .jest-base - .jest-base
- .frontend:rules:default-frontend-jobs - .frontend:rules:jest
needs: needs:
- job: "detect-tests"
- job: "rspec frontend_fixture" - job: "rspec frontend_fixture"
- job: "rspec-ee frontend_fixture" - job: "rspec-ee frontend_fixture"
optional: true optional: true
...@@ -210,6 +211,13 @@ jest: ...@@ -210,6 +211,13 @@ jest:
junit: junit_jest.xml junit: junit_jest.xml
parallel: 5 parallel: 5
jest minimal:
extends:
- jest
- .frontend:rules:jest:minimal
script:
- run_timed_command "yarn jest:ci:minimal"
jest-integration: jest-integration:
extends: extends:
- .frontend-test-base - .frontend-test-base
...@@ -235,7 +243,11 @@ coverage-frontend: ...@@ -235,7 +243,11 @@ coverage-frontend:
- .default-retry - .default-retry
- .yarn-cache - .yarn-cache
- .frontend:rules:ee-mr-and-default-branch-only - .frontend:rules:ee-mr-and-default-branch-only
needs: ["jest"] needs:
- job: "jest"
optional: true
- job: "jest minimal"
optional: true
stage: post-test stage: post-test
before_script: before_script:
- *yarn-install - *yarn-install
......
...@@ -46,6 +46,9 @@ ...@@ -46,6 +46,9 @@
.if-merge-request-title-run-all-rspec: &if-merge-request-title-run-all-rspec .if-merge-request-title-run-all-rspec: &if-merge-request-title-run-all-rspec
if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:run-all-rspec/' if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:run-all-rspec/'
.if-merge-request-title-run-all-jest: &if-merge-request-title-run-all-jest
if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:run-all-jest/'
.if-merge-request-run-decomposed: &if-merge-request-run-decomposed .if-merge-request-run-decomposed: &if-merge-request-run-decomposed
if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:run-decomposed/' if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:run-decomposed/'
...@@ -365,6 +368,14 @@ ...@@ -365,6 +368,14 @@
- "danger/**/*" - "danger/**/*"
- "tooling/danger/**/*" - "tooling/danger/**/*"
.core-frontend-patterns: &core-frontend-patterns
- "{package.json,yarn.lock}"
- "babel.config.js"
- "jest.config.{base,integration,unit}.js"
- "config/helpers/**/*.js"
- "vendor/assets/javascripts/**/*"
- "{,ee}/app/assets/**/*.graphql"
################ ################
# Shared rules # # Shared rules #
################ ################
...@@ -525,6 +536,37 @@ ...@@ -525,6 +536,37 @@
- <<: *if-merge-request - <<: *if-merge-request
changes: *ci-patterns changes: *ci-patterns
.frontend:rules:jest:
rules:
- <<: *if-merge-request-title-run-all-jest
- <<: *if-default-refs
changes: *core-frontend-patterns
- <<: *if-merge-request
changes: *ci-patterns
- <<: *if-automated-merge-request
changes: *code-backstage-patterns
- <<: *if-merge-request-not-approved
when: never
- <<: *if-default-refs
changes: *code-backstage-patterns
.frontend:rules:jest:minimal:
rules:
- <<: *if-merge-request-approved
when: never
- <<: *if-automated-merge-request
when: never
- <<: *if-merge-request-title-run-all-jest
when: never
- <<: *if-default-refs
changes: *core-frontend-patterns
when: never
- <<: *if-merge-request
changes: *ci-patterns
when: never
- <<: *if-merge-request
changes: *code-backstage-patterns
.frontend:rules:eslint-as-if-foss: .frontend:rules:eslint-as-if-foss:
rules: rules:
- <<: *if-not-ee - <<: *if-not-ee
......
...@@ -70,9 +70,12 @@ verify-tests-yml: ...@@ -70,9 +70,12 @@ verify-tests-yml:
- install_gitlab_gem - install_gitlab_gem
- install_tff_gem - install_tff_gem
- retrieve_tests_mapping - retrieve_tests_mapping
- 'if [ -n "$CI_MERGE_REQUEST_IID" ]; then tooling/bin/find_changes ${CHANGES_FILE}; fi' - |
- 'if [ -n "$CI_MERGE_REQUEST_IID" ]; then tooling/bin/find_tests ${CHANGES_FILE} ${MATCHED_TESTS_FILE}; fi' if [ -n "$CI_MERGE_REQUEST_IID" ]; then
- 'if [ -n "$CI_MERGE_REQUEST_IID" ]; then echo "related rspec tests: $(cat $MATCHED_TESTS_FILE)"; fi' tooling/bin/find_changes ${CHANGES_FILE};
tooling/bin/find_tests ${CHANGES_FILE} ${MATCHED_TESTS_FILE};
echo "related rspec tests: $(cat $MATCHED_TESTS_FILE)";
fi
artifacts: artifacts:
expire_in: 7d expire_in: 7d
paths: paths:
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
"prejest": "yarn check-dependencies", "prejest": "yarn check-dependencies",
"jest": "jest --config jest.config.js", "jest": "jest --config jest.config.js",
"jest-debug": "node --inspect-brk node_modules/.bin/jest --runInBand", "jest-debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
"jest:ci": "jest --config jest.config.js --ci --coverage --testSequencer ./scripts/frontend/parallel_ci_sequencer.js",
"jest:ci:minimal": "jest --config jest.config.js --ci --coverage --findRelatedTests $(cat tmp/changed_files.txt) --passWithNoTests --testSequencer ./scripts/frontend/parallel_ci_sequencer.js",
"jest:integration": "jest --config jest.config.integration.js", "jest:integration": "jest --config jest.config.integration.js",
"jsdoc": "jsdoc -c config/jsdocs.config.js", "jsdoc": "jsdoc -c config/jsdocs.config.js",
"lint:eslint": "yarn run internal:eslint", "lint:eslint": "yarn run internal:eslint",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment