#๐Ÿ‘‹ Hi all, first time posting here. Anyone familiar with customizing CI/CD jobs for React + Jest?

3 messages ยท Page 1 of 1 (latest)

limber bay
#

My company just migrated to hosted Gitlab and I've been trying to speed up our pipelines - mainly our Unit Test job that runs a Jest test suite.

I'm specifically looking to learn if anyone has tried running a Merge Request job on a subset of test files using the Jest CLI flags like --onlyChanged and --changedSince

Thanks much,
Matt

#
# gitlab.yaml

stages:
  - init
  - jest_changed
  - ...

# jest_changed stage runs after init stage
# init stage caches .npm and node_modules as an artifact
Run Jest Test (Changed):
  stage: jest_changed
  timeout: 20m
  interruptible: true
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PIPELINE_SOURCE != "develop" && $CI_PIPELINE_SOURCE != "main" && $CI_PIPELINE_SOURCE !~ /^release\/.*$/ && $RUN_UNIT_TEST == "TRUE"
    - if: $CI_PIPELINE_SOURCE == "pipeline" && $RUN_UNIT_TEST == "TRUE"
      when: never
  before_script:
    - git fetch --no-tags --depth=1 origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    - git checkout -B $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
  script:
    - git checkout -B $CI_COMMIT_SHA
    - git status
    - JEST_JUNIT_OUTPUT_NAME=junit.xml npm run test:jest-ci -- --changedSince=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
#

Unfortunately, Jest doesnt' seem to find any changed files given this approach despite the MR diff changing over 20 files including several unit tests.