Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot convert undefined or null to object #343

Closed
dagadbm opened this issue Feb 3, 2023 · 11 comments · Fixed by #344
Closed

TypeError: Cannot convert undefined or null to object #343

dagadbm opened this issue Feb 3, 2023 · 11 comments · Fixed by #344
Assignees
Labels
bug Something isn't working

Comments

@dagadbm
Copy link

dagadbm commented Feb 3, 2023

I have already looked through the two other issues regarding this problem but I honestly am at a loss on how to fix this.

Here is the log:

Run ArtiomTr/jest-coverage-report-action@v2
Run $GITHUB_ACTION_PATH/run.sh
Running using node v[12](https://github.com/x/x/actions/runs/4083315085/jobs/7038692568#step:9:13).22.12
Begin initialization stage...
Initialization stage ended
Begin stages.parsethreshold...
stages.parseThreshold ended
Begin head coverage collection...
Begin installing dependencies...
Installing dependencies skipped
Installing dependencies ended
Begin running tests...
Running tests skipped
Running tests ended
Begin collecting coverage...
Loading code coverage from file: client-coverage-report.json
Collecting coverage ended
Begin parsing coverage...
Parsing coverage ended
Head coverage collection ended
Begin switching to base branch...
Switching to base branch skipped
Switching to base branch ended
Begin base coverage collection...
Begin installing dependencies...
Installing dependencies skipped
Installing dependencies ended
Begin running tests...
Running tests skipped
Running tests ended
Begin collecting coverage...
Loading code coverage from file: client-coverage-report.json
Collecting coverage ended
Begin parsing coverage...
Parsing coverage ended
Base coverage collection ended
Begin switching back to original branch...
Switching back to original branch skipped
Switching back to original branch ended
Begin stages.checkthreshold...
stages.checkThreshold failed
Error: TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:2679
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:3260
    at Array.reduce (<anonymous>)
    at Ad (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:3212)
    at X9 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:3592)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:22[30](https://github.com/x/x/actions/runs/4083315085/jobs/7038692568#step:9:32):15072
    at ci (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2221:164)
    at jD (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2230:15026)
stages.checkThreshold ended
Begin generating report...
Generating report failed
Error: TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:2679
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:5017
    at Array.reduce (<anonymous>)
    at Qu (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:5001)
    at q1 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:51[33](https://github.com/x/x/actions/runs/4083315085/jobs/7038692568#step:9:35))
    at X1 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2206:27)
    at PT (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2218:261)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2230:15153
    at ci (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2221:164)
Generating report ended
Begin report publish...
Report publish skipped
Report publish ended
Begin setting outputs...
Setting outputs skipped
Setting outputs ended
Begin failed tests' annotations publication...
Failed tests' annotations publication skipped
Failed tests' annotations publication ended
Begin coverage annotations publication...
Coverage annotations publication failed
Error: TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2192:60649
    at Array.forEach (<anonymous>)
    at c4 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2192:60585)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2230:15846
    at ci (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2221:164)
    at jD (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2230:157[42]

This is the config:

name: Frontend build and test CI

on:
  pull_request:
    branches: [ "master", "dev" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js 12
      uses: actions/setup-node@v3
      with:
        node-version: '12'
        cache: 'npm'
    - run: npm ci
    - run: npm run graphql:generate
    - run: npm run lint
    - run: npm run build:old-node-version --if-present
    # run tests and collect coverage reports to send to jest-coverage-report-action
    - run: npm test -- --ci --coverage --json --testLocationInResults --outputFile=client-coverage-report.json
    - uses: ArtiomTr/jest-coverage-report-action@v2
      id: coverage
      with:
        output: report-markdown
        coverage-file: client-coverage-report.json
        base-coverage-file: client-coverage-report.json
    - uses: marocchino/sticky-pull-request-comment@v2
      with:
        message: ${{ steps.coverage.outputs.report }}

I also ran the npm test command locally on my machine that is using node 12 and I got the expected result:

{
  "numFailedTestSuites": 0,
  "numFailedTests": 0,
  "numPassedTestSuites": 13,
  "numPassedTests": 118,
  "numPendingTestSuites": 0,
  "numPendingTests": 0,
  "numRuntimeErrorTestSuites": 0,
  "numTodoTests": 0,
  "numTotalTestSuites": 13,
  "numTotalTests": 118,
  "openHandles": [],
  "snapshot": {
    "added": 0,
    "didUpdate": false,
    "failure": false,
    "filesAdded": 0,
    "filesRemoved": 0,
    "filesRemovedList": [],
    "filesUnmatched": 0,
    "filesUpdated": 0,
    "matched": 0,
    "total": 0,
    "unchecked": 0,
    "uncheckedKeysByFile": [],
    "unmatched": 0,
    "updated": 0
  },
  "startTime": 1675420255044,
  "success": true,
  "testResults": [
    { //... }
  "wasInterrupted": false,
  "coverageMap": {
     //... 
}

and here is my jest.config.js

module.exports = {
  preset: "ts-jest",
  setupFilesAfterEnv: ["<rootDir>/test-utils/jest-setup.ts"],
  testEnvironment: "jsdom",
  resolver: "jest-webpack-resolver",
  roots: ["<rootDir>"],
  moduleDirectories: ["node_modules", "<rootDir>/", "<rootDir>/test-utils"],
  moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"],
  modulePaths: ["node_modules", "<rootDir>"],
  moduleNameMapper: {
    "^@/(.*)": "<rootDir>/src/$1",
    "test-utils/(.*)": "<rootDir>/test-utils/$1",
    "test-utils": "<rootDir>/test-utils/index.tsx",
    "^.+\\.(css|less)$": "identity-obj-proxy"
  },
  transform: {
    "\\.[t]sx?$": "ts-jest",
    "\\.[j]sx?$": "esbuild-jest",
    "\\.svg$": "<rootDir>/test-utils/fileTransformer.js"
  },
  globals: {
    ["ts-jest"]: {
      compiler: "ttypescript"
    }
  },
  // coverage
  // coverage disabled by default. Enabled per each jest call
  collectCoverage: false,
  collectCoverageFrom: [
    "<rootDir>/**/*.{ts,tsx,js,jsx}",
  ],
  coverageReporters: ["text", "text-summary"],

  coverageThreshold: {
    global: {
      // our goal is to increase this value until 80%
      statements: 5,
    },
  },
};
@dagadbm dagadbm added the bug Something isn't working label Feb 3, 2023
@dagadbm
Copy link
Author

dagadbm commented Feb 3, 2023

I also noticed that I am using a resolver for jest which is needed because I am using typescript.

Could this be the reason? I tried commenting it out and running locally the tests all passed but I am not comfortable disabling this.

Also, I noticed the generated report is pretty much the same as the other one.

I also did a push with this change just to check if the result is different but it still failed.

Here are the logs:

Run ArtiomTr/jest-coverage-report-action@v2
  with:
    output: report-markdown
    coverage-file: client-coverage-report.json
    base-coverage-file: client-coverage-report.json
    github-token: ***
    test-script: npx jest
    icons: emoji
    annotations: all
    package-manager: npm
    skip-step: none
  
Run $GITHUB_ACTION_PATH/run.sh
  $GITHUB_ACTION_PATH/run.sh
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    INPUT_GITHUB-TOKEN: ***
    INPUT_TEST-SCRIPT: npx jest
    INPUT_THRESHOLD: 
    INPUT_WORKING-DIRECTORY: 
    INPUT_ICONS: emoji
    INPUT_ANNOTATIONS: all
    INPUT_PACKAGE-MANAGER: npm
    INPUT_SKIP-STEP: none
    INPUT_CUSTOM-TITLE: 
    INPUT_COVERAGE-FILE: client-coverage-report.json
    INPUT_BASE-COVERAGE-FILE: client-coverage-report.json
    INPUT_PRNUMBER: 
    INPUT_OUTPUT: report-markdown
Running using node v1[2](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:2).22.12
Begin initialization stage...
Initialization stage ended
Begin stages.parsethreshold...
stages.parseThreshold ended
Begin head coverage collection...
Begin installing dependencies...
Installing dependencies skipped
Installing dependencies ended
Begin running tests...
Running tests skipped
Running tests ended
Begin collecting coverage...
Loading code coverage from file: client-coverage-report.json
Collecting coverage ended
Begin parsing coverage...
Parsing coverage ended
Head coverage collection ended
Begin switching to base branch...
Switching to base branch skipped
Switching to base branch ended
Begin base coverage collection...
Begin installing dependencies...
Installing dependencies skipped
Installing dependencies ended
Begin running tests...
Running tests skipped
Running tests ended
Begin collecting coverage...
Loading code coverage from file: client-coverage-report.json
Collecting coverage ended
Begin parsing coverage...
Parsing coverage ended
Base coverage collection ended
Begin switching back to original branch...
Switching back to original branch skipped
Switching back to original branch ended
Begin stages.checkthreshold...
stages.checkThreshold failed
Error: TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:2679
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:[3](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:3)260
    at Array.reduce (<anonymous>)
    at Ad (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:3212)
    at X9 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:3592)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2230:15072
    at ci (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2221:16[4](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:4))
    at jD (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2230:1[5](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:5)02[6](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:6))
stages.checkThreshold ended
Begin generating report...
Generating report failed
Error: TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:219[7](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:7):2679
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:5017
    at Array.reduce (<anonymous>)
    at Qu (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:5001)
    at q1 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2197:5133)
    at X1 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2206:27)
    at PT (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:221[8](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:8):261)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2230:15153
    at ci (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2221:164)
Generating report ended
Begin report publish...
Report publish skipped
Report publish ended
Begin setting outputs...
Setting outputs skipped
Setting outputs ended
Begin failed tests' annotations publication...
Failed tests' annotations publication skipped
Failed tests' annotations publication ended
Begin coverage annotations publication...
Coverage annotations publication failed
Error: TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:21[9](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:9)2:60649
    at Array.forEach (<anonymous>)
    at c4 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2192:60585)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2230:[15](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:16)846
    at ci (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:2221:[16](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:17)4)
    at jD (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:[22](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:23)[30](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:32):157[42](https://github.com/x/x/actions/runs/4083486212/jobs/7039070699#step:9:44))
Coverage annotations publication ended
Error: Jest coverage report action failed
Error: Process completed with exit code 1.

@ArtiomTr
Copy link
Owner

ArtiomTr commented Feb 3, 2023

Hello @dagadbm 👋,

Looks like an error is being thrown on this here:

) => Object.values(value[key]).length;

That's a function that is counting how many total statements/functions are in your coverage map. So, in order to clearly understand where is an issue, I need to see full coverage maps. To do this, add logging into your action.yaml file:

name: Frontend build and test CI

on:
  pull_request:
    branches: [ "master", "dev" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js 12
      uses: actions/setup-node@v3
      with:
        node-version: '12'
        cache: 'npm'
    - run: npm ci
    - run: npm run graphql:generate
    - run: npm run lint
    - run: npm run build:old-node-version --if-present
    # run tests and collect coverage reports to send to jest-coverage-report-action
    - run: npm test -- --ci --coverage --json --testLocationInResults --outputFile=client-coverage-report.json
    - run: cat client-coverage-report.json # <------------- add this line to log coverage map
    - uses: ArtiomTr/jest-coverage-report-action@v2
      id: coverage
      with:
        output: report-markdown
        coverage-file: client-coverage-report.json
        base-coverage-file: client-coverage-report.json
    - uses: marocchino/sticky-pull-request-comment@v2
      with:
        message: ${{ steps.coverage.outputs.report }}

Then run the action one more time and send me a JSON, that is being logged.

@dagadbm
Copy link
Author

dagadbm commented Feb 3, 2023

the file is so huge (25MB) I had to send it as a zip. i even tried to use pastebin but couldnt 😅

@dagadbm
Copy link
Author

dagadbm commented Feb 3, 2023

let me know when I can delete it from the issue.

@ArtiomTr
Copy link
Owner

ArtiomTr commented Feb 3, 2023

Well, that's a really interesting case - some files have non-standard coverage maps. For instance, file /home/runner/work/code/code/client/app/services/location.js.

By default, report object looks like:

{
    coverageMap: {
        ['/filename']: {
            statementMap: { /* information about statements */ }
        }
    }
}

However, yours looks like:

{
    coverageMap: {
        ['/filename']: {
+           data: {
                statementMap: { /* information about statements */ }
+           }
        }
    }
}

So, the action tries to read non-existing property and fails. Fortunately, that will be an easy fix 😄

@ArtiomTr
Copy link
Owner

ArtiomTr commented Feb 4, 2023

@dagadbm, the fix is now available under v2.1.3 (v2) tag

@dagadbm
Copy link
Author

dagadbm commented Feb 4, 2023 via email

@dagadbm
Copy link
Author

dagadbm commented Feb 4, 2023 via email

@ArtiomTr
Copy link
Owner

ArtiomTr commented Feb 4, 2023

Yeah, sticky comments are implemented in this action, actually, that's the default behaviour:

output:
required: false
description: What output should action produce? `comment` - add comment to PR, `report-markdown` - report markdown text in "outputs.report".
default: comment

I changed the default example because I was thinking that would fix an issue with permissions on public repos (#313). However, that not worked 😞

So I decided to leave the example as is and change it when this issue will be fixed.

If you don't want to use third-party action for comments, you can change your workflow file to use built-in functionality:

name: Frontend build and test CI

on:
  pull_request:
    branches: [ "master", "dev" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js 12
      uses: actions/setup-node@v3
      with:
        node-version: '12'
        cache: 'npm'
    - run: npm ci
    - run: npm run graphql:generate
    - run: npm run lint
    - run: npm run build:old-node-version --if-present
    # run tests and collect coverage reports to send to jest-coverage-report-action
    - run: npm test -- --ci --coverage --json --testLocationInResults --outputFile=client-coverage-report.json
    - uses: ArtiomTr/jest-coverage-report-action@v2
-     id: coverage
      with:
-       output: report-markdown
        coverage-file: client-coverage-report.json
        base-coverage-file: client-coverage-report.json
-   - uses: marocchino/sticky-pull-request-comment@v2
-     with:
-       message: ${{ steps.coverage.outputs.report }}

@dagadbm
Copy link
Author

dagadbm commented Feb 4, 2023 via email

@ArtiomTr
Copy link
Owner

ArtiomTr commented Feb 4, 2023

Yeah, details are omitted if the report size exceeds the limits (Github limits comment size to 65535 symbols).

However, I think we could improve the algorithm and show as many details as possible.

I will create a separate issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants