jest-coverage-report-action: Dont work test-script with jest --changedSince

Describe a bug

The test-script command does not work with this example.

yarn jest --changedSince=origin/master

Because it can’t work with this command. Could you help me with this, what would be the best solution. Thank you so much

Expected behavior

For it to work with this type of command, the expected behavior is to perform the tests only for specific files.

Details

  • Action version:

  • OS, where your action is running (windows, linux):

  • action.yml file
    ```yml
    # Insert your action.yml file here. Don't forget to remove all sensitive information (e.g. tokens)
    ```
    
  • Screenshots
    <!-- If you encounter an incorrect coverage comment display, replace this comment with screenshot -->
    
    <!-- If your action unexpectedly fails, please replace this comment with a screenshot of your console  -->
    

Additional context

Captura de Pantalla 2023-03-07 a la(s) 10 29 10 a m Captura de Pantalla 2023-03-07 a la(s) 10 29 40 a m

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

Thank you very much if it works, I’ll keep testing. Really thank you very much for the help. @ArtiomTr

Thanks for your help, I did it with the first step that you showed and it worked for me, although it does coverage with more files, it worked for me that way.

Thank you for taking the time to help me and offer some alternatives as soon as I code. 😃

Thank you very much for the help, really thanks for taking the time to analyze the code and find improvements. This interests me a lot since I am implementing your action and I found it very interesting. Thank you very much for the help.

@CarlFMateus try this workflow:

name: Unit Tests
run-name: ${{ github.actor }} is execute test coverage 😎
on:
  pull_request:
    branches:
      - "master"
    types: [opened, reopened, synchronize]

jobs:
  tests:
    if: startsWith(github.head_ref, 'feature')
    runs-on: ubuntu-latest

    permissions:
      id-token: write
      contents: read
      checks: write
      pull-requests: write

    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - run: |
          git fetch --no-tags --depth=1 origin master
          git checkout -b master
          git checkout ${{ github.event.pull_request.head.sha }}

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{matrix.node-version}}
          cache: "yarn"
      - name: Install dependencies
        run: yarn install --frozen-lockfile
      - name: Do you have a unit test?
        uses: actions/github-script@v6
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            const number = await context.payload.pull_request.number
            const files = await github.rest.pulls.listFiles({
              owner: context.repo.owner,
              repo: context.repo.repo,
              pull_number: number
            })

            const regex = /.*(spec|test).(ts|js|tsx)$/
            const isShow = files.data.some(file => regex.test(file.filename) )

            if(!isShow){
              await github.rest.checks.create({
                owner: context.repo.owner,
                repo: context.repo.repo,
                status: 'completed',
                name: 'Failed Validation',
                head_sha: context.payload.pull_request.head.sha || context.sha,
                conclusion: 'failure',
                output: {
                  title: 'Failed Validation',
                  text: 'Fallo porque no cumplio con las validación minima',
                  summary: 'Debe contener al menos una prueba'
                }
              })
              
              core.setFailed('Debe contener al menos una prueba')
            }

            await github.rest.checks.create({
              owner: context.repo.owner,
              repo: context.repo.repo,
              status: 'completed',
              name: 'Successful Validation',
              head_sha: context.payload.pull_request.head.sha || context.sha,
              conclusion: 'success',
              output: {
                title: 'Successful Validation',
                text: 'Contiene al menos una prueba unitaria',
                summary: 'Debe contener al menos una prueba'
              }
            })
      - name: Run tests
        run: yarn jest --changedSince=origin/master --ci --json --coverage --testLocationInResults --outputFile=report.json
      - name: Coverage Report
        uses: ArtiomTr/jest-coverage-report-action@v2
        with:
          coverage-file: report.json
          base-coverage-file: report.json
          annotations: failed-tests