Skip to content

Commit

Permalink
Fix esm only import from vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Nov 26, 2024
1 parent ac03998 commit d4fa610
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions code/addons/test/src/node/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d4fa610

Please sign in to comment.