test-reporter icon indicating copy to clipboard operation
test-reporter copied to clipboard

Vitest junit - Cannot read property 'time' of undefined

Open snowmead opened this issue 2 years ago • 10 comments

Using Vitest I would specify the following configuration for my reporters:

reporters: ['junit'],
outputFile: './report/integration-tests-results.json',

Failed Output:

Using test report parser 'jest-junit'
Creating test report Integration Tests Report
  Processing test results from ./report/integration-tests-results.xml
Error: Cannot read property 'time' of undefined

snowmead avatar Aug 22 '22 14:08 snowmead

Running into the same problem: https://github.com/IntelliTect/Coalesce/runs/7960417153?check_suite_focus=true

ascott18 avatar Aug 22 '22 20:08 ascott18

The readme is outdated, the following worked for me.

my action yaml file

name: "tests"
on:
  pull_request:
  push:
jobs:
  build-test:
    name: Build & Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: "npm"
      - run: npm ci
      - run: npm run test-ci

      - name: Test Report
        uses: dorny/test-reporter@v1
        if: success() || failure()
        with:
          name: JEST Tests
          path: reports/jest-*.xml
          reporter: jest-junit

my package.json file

{
  // some other stuff...
  "scripts": {
    "test": "jest",
    "test-ci": "jest --ci --reporters=default --reporters=jest-junit"
  },
  "dependencies": {
    "@actions/core": "^1.9.1",
    "@actions/exec": "^1.1.1",
    "@types/command-exists": "^1.2.0",
    "command-exists": "^1.2.9",
    "esbuild": "^0.15.6",
    "string-argv": "^0.3.1"
  },
  "devDependencies": {
    "@types/jest": "^28.0.0",
    "@types/node": "^18.7.9",
    "jest": "^28.0.0",
    "jest-junit": "^14.0.1",
    "jest-junit-reporter": "^1.1.0",
    "ts-jest": "^28.0.0",
    "typescript": "^4.7.4"
  },
  "jest": {
    "preset": "ts-jest",
    "testEnvironment": "node"
  },
  "jest-junit": {
    "outputDirectory": "reports",
    "outputName": "jest-junit.xml",
    "ancestorSeparator": " › ",
    "uniqueOutputName": "false",
    "suiteNameTemplate": "{filepath}",
    "classNameTemplate": "{classname}",
    "titleTemplate": "{title}"
  }
}

SamKirkland avatar Sep 03 '22 22:09 SamKirkland

#137 & #148 see above ^^

SamKirkland avatar Sep 03 '22 22:09 SamKirkland

@SamKirkland this issue is about vitest, not jest.

ascott18 avatar Sep 03 '22 22:09 ascott18

I can't update my process to node 18, is there another solution that uses LTS?

Dottenpixel avatar Sep 27 '22 08:09 Dottenpixel

Has anyone found a solution to this? I'm running into the same issue.

chinapalace avatar Nov 02 '22 22:11 chinapalace

+1 on this

Gentatsu avatar Feb 08 '23 15:02 Gentatsu

+1 on this. I'm guessing this is failing on the root element <testsuites> missing attributes such as time?

Can the reporter please be updated to check for the attribute truthiness to handle the error a bit more gracefully?

richardeschloss avatar Mar 21 '23 15:03 richardeschloss

Yes please! According to the spec these attributes are optional, and vitest does not generate them.

blowsie avatar Apr 13 '23 15:04 blowsie

Looks like Vitest added support for these attributes here. https://github.com/vitest-dev/vitest/commit/d050604f1995b53e1b70b32bee821f01ad3e0797

v0.25.4

blowsie avatar Apr 13 '23 15:04 blowsie