skip to Main Content

I have a react project based on minimal theme
RTL and jest are integrated into this project as well.

Locally running unit tests command is this

 "test:dev": "react-app-rewired test --transformIgnorePatterns 'node_modules/(?!my-library-dir)/'",

This runs the unit tests and gives the expected results. So no issues in local environment.

This is my build pipeline script

- script: |
      npm install --global yarn
      yarn
      NODE_OPTIONS=--max_old_space_size=2048 npm run build
    displayName: 'npm install and build'

I changed it by adding unit tests line like this

 - script: |
      npm install --global yarn
      yarn
      npm run test:ci
      NODE_OPTIONS=--max_old_space_size=2048 npm run build
    displayName: 'npm install and build'

test:ci command is this

"test:ci": "CI=true react-app-rewired test --watchAll --transformIgnorePatterns 'node_modules/(?!my-library-dir)/'"

Now in the azure ci cd console, I see this

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        29.812 s
Ran all test suites.

Which means test cases run successfully. But now the problem is it doesn’t trigger the next line in the pipeline which is

NODE_OPTIONS=--max_old_space_size=2048 npm run build

The pipeline hangs for a long time and timeout.

How can I fix this with Azure DevOps and jest?

2

Answers


  1. The issue can be related to the argument: --watchAll.

    It will watch files for changes and rerun all tests when something changes. It may cause an infinite loop and never exit.

    I can reproduce the same issue when using the --watchAll argument.

    enter image description here

    To solve the issue, you can remove the --watchAll flag or set the --watchAll=false.

    In this case, the jest test will work as expected in Azure DevOps.

    Result:

    enter image description here

    Login or Signup to reply.
  2. I would recommend separating it into three individual steps, which will have better output flow in the Azure DevOps UI, and allow for easier debugging if there is a problem with your syntax:

    - script: |
        npm install --global yarn
        yarn
      displayName: 'Install yarn'
    
    - script: |
        npm run test:ci
      displayName: 'Run tests'
    
    - script: |
        NODE_OPTIONS=--max_old_space_size=2048 npm run build
      displayName: 'Run build'
    

    All three steps will execute one after each other on the same agent (machine).

    If this still does not work, I suspect there may be a problem with your command NODE_OPTIONS=--max_old_space_size=2048 npm run build causing it not to be executed correctly. You can try changing it to node --max_old_space_size=2048 npm run build or setting max_old_space_size as an environment variable instead. If those options do not work, try searching on Stack Overflow or on your search engine. Here is an example question that may help.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search