vitest icon indicating copy to clipboard operation
vitest copied to clipboard

fix(vitest): logs in `beforeAll` and `afterAll`

Open fenghan34 opened this issue 1 year ago • 1 comments

Description

  • Closes #3366

  • I think the reason why logs in hooks beforeAll and afterAll are missing from the HTML report is because these logs are not attached to the related tasks they were contained in. https://github.com/vitest-dev/vitest/blob/5bb8b38092f107384b0fbfb091d3d60ab4ea39bd/packages/vitest/src/runtime/console.ts#L88

Here's the comparison between without and with this PR:

import { afterAll, beforeAll, describe, expect, test } from 'vitest'

beforeAll(() => {
  console.log('beforeAll')
})

afterAll(() => {
  console.log('afterAll')
})

describe('suite', () => {
  beforeAll(() => {
    console.log('beforeAll')
  })

  afterAll(() => {
    console.log('afterAll')
  })

  describe('nested suite', () => {
    beforeAll(() => {
      console.log('beforeAll')
    })

    afterAll(() => {
      console.log('afterAll')
    })

    test('test', () => {
      expect(true).toBe(true)
    })
  })
})

Before image image

After image image

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • [x] It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • [x] Ideally, include a test that fails without this PR but passes with it.
  • [x] Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • [x] Run the tests with pnpm test:ci.

Documentation

  • [ ] If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • [x] Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

fenghan34 avatar Feb 24 '24 15:02 fenghan34

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
Latest commit 3fc257c1361037150070f1e37d8784eecc247791
Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65f3f0daeacb3e0008a2088c

netlify[bot] avatar Feb 24 '24 15:02 netlify[bot]

@fenghan34 hey! can you fix merge conflicts when you have time, please? 🙏🏻

sheremet-va avatar Mar 14 '24 14:03 sheremet-va

@fenghan34 hey! can you fix merge conflicts when you have time, please? 🙏🏻

Sure I will do it soon

fenghan34 avatar Mar 15 '24 06:03 fenghan34