From d4fa610356c488e971ad921828d11561bf6d3e3d Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 26 Nov 2024 15:54:36 +0100 Subject: [PATCH] Fix esm only import from vitest --- code/addons/test/src/node/reporter.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/code/addons/test/src/node/reporter.ts b/code/addons/test/src/node/reporter.ts index 51d2dc010cff..c89457f4c9a3 100644 --- a/code/addons/test/src/node/reporter.ts +++ b/code/addons/test/src/node/reporter.ts @@ -10,11 +10,6 @@ import type { import type { API_StatusUpdate } from '@storybook/types'; import type { Suite } from '@vitest/runner'; -// TODO -// We can theoretically avoid the `@vitest/runner` dependency by copying over the necessary -// functions from the `@vitest/runner` package. It is not complex and does not have -// any significant dependencies. -import { getTests } from '@vitest/runner/utils'; import { throttle } from 'es-toolkit'; import { TEST_PROVIDER_ID } from '../constants'; @@ -73,7 +68,13 @@ export class StorybookReporter implements Reporter { this.start = Date.now(); } - getProgressReport(finishedAt?: number) { + async getProgressReport(finishedAt?: number) { + // TODO + // We can theoretically avoid the `@vitest/runner` dependency by copying over the necessary + // functions from the `@vitest/runner` package. It is not complex and does not have + // any significant dependencies. + const { getTests } = await import('@vitest/runner/utils'); + const files = this.ctx.state.getFiles(); const fileTests = getTests(files).filter((t) => t.mode === 'run' || t.mode === 'only'); @@ -160,7 +161,7 @@ export class StorybookReporter implements Reporter { this.sendReport({ providerId: TEST_PROVIDER_ID, status: 'pending', - ...this.getProgressReport(), + ...(await this.getProgressReport()), }); } catch (e) { this.sendReport({ @@ -191,7 +192,7 @@ export class StorybookReporter implements Reporter { const unhandledErrors = this.ctx.state.getUnhandledErrors(); const isCancelled = this.ctx.isCancelling; - const report = this.getProgressReport(Date.now()); + const report = await this.getProgressReport(Date.now()); const testSuiteFailures = report.details.testResults.filter( (t) => t.status === 'failed' && t.results.length === 0