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

Test: Add coverage feature #29713

Merged
merged 38 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
68c4062
add minimal coverage reporting
JReinhold Nov 20, 2024
1e0869b
fix allTestsRun
JReinhold Nov 21, 2024
5aff4be
static link to coverage
JReinhold Nov 21, 2024
50c9292
use configOverrides for coverage config
JReinhold Nov 26, 2024
f0c9a72
Merge branch 'norbert/testmodule-options' of github.com:storybookjs/s…
JReinhold Nov 26, 2024
dcd8483
use cache dir for coverage staticDir
JReinhold Nov 26, 2024
652eaff
Merge branch 'norbert/testmodule-options' of github.com:storybookjs/s…
JReinhold Nov 26, 2024
3af473f
Merge branch 'next' into jeppe/vitest-coverage-backend
ndelangen Nov 26, 2024
7a2bf5a
share testManager with the coverage reporter
ndelangen Nov 26, 2024
50d022b
Merge branch 'next' into jeppe/vitest-coverage-backend
ndelangen Nov 26, 2024
19ec3f6
trying to set coverage override vitest config
ndelangen Nov 26, 2024
426ecaf
This seems like the right thing to do to me @JReinhold
ndelangen Nov 26, 2024
f51b127
add to UI; I'm sure either Jeppe or Gert will change
ndelangen Nov 26, 2024
7a1e4b9
restart vitest on coverage change
JReinhold Nov 26, 2024
39fdd97
only set coverage options when coveage is enabled
JReinhold Nov 27, 2024
c5c3cf6
cleanup
JReinhold Nov 27, 2024
f0fdfb1
fix config types
JReinhold Nov 27, 2024
a5a0b1f
Merge branch 'testing-module-settings' of github.com:storybookjs/stor…
JReinhold Nov 27, 2024
7b001de
integrate coverage backend with UI
JReinhold Nov 28, 2024
6c40e01
Merge branch 'next' of github.com:storybookjs/storybook into jeppe/vi…
JReinhold Nov 28, 2024
2cf1d42
configure coverage color based on watermark config
JReinhold Nov 28, 2024
69884ad
cleanup
JReinhold Nov 28, 2024
172f64c
use coverage.statement as metric
JReinhold Nov 28, 2024
13f59b2
only boot vitest child process on addon-test-specific events
JReinhold Nov 28, 2024
d8948f0
restart vitest before every coverage run
JReinhold Nov 28, 2024
1563d50
cleanup
JReinhold Nov 28, 2024
e69a832
Merge branch 'next' of github.com:storybookjs/storybook into jeppe/vi…
JReinhold Nov 28, 2024
979f974
fix types
JReinhold Nov 28, 2024
4a69993
disable coverage in watch mode
JReinhold Nov 28, 2024
37fb3f7
improve vitest restart comment
JReinhold Nov 29, 2024
56666f0
add coverage html link
JReinhold Nov 29, 2024
5b5a436
rename details.coverage to details.coverageSummary, to not confuse wi…
JReinhold Nov 29, 2024
b13506e
simplify
JReinhold Nov 29, 2024
9f51803
Merge branch 'next' into jeppe/vitest-coverage-backend
JReinhold Nov 29, 2024
f50c6c8
Merge branch 'next' into jeppe/vitest-coverage-backend
JReinhold Nov 29, 2024
04f9ca0
add coverage states to stories
JReinhold Nov 29, 2024
79be746
Merge branch 'jeppe/vitest-coverage-backend' of github.com:storybookj…
JReinhold Nov 29, 2024
d4d566a
sync coverage state on run request
JReinhold Nov 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/addons/test/package.json
Original file line number Diff line number Diff line change
@@ -92,7 +92,6 @@
},
"devDependencies": {
"@devtools-ds/object-inspector": "^1.1.2",
"@storybook/icons": "^1.2.12",
"@types/istanbul-lib-report": "^3.0.3",
"@types/node": "^22.0.0",
"@types/semver": "^7",
8 changes: 4 additions & 4 deletions code/addons/test/src/node/coverage-reporter.ts
Original file line number Diff line number Diff line change
@@ -8,18 +8,18 @@ import type { TestManager } from './test-manager';

export type StorybookCoverageReporterOptions = {
testManager: TestManager;
getCoverageOptions: () => ResolvedCoverageOptions<'v8'>;
coverageOptions: ResolvedCoverageOptions<'v8'>;
};

export default class StorybookCoverageReporter extends ReportBase implements Partial<Visitor> {
#testManager: StorybookCoverageReporterOptions['testManager'];

#getCoverageOptions: StorybookCoverageReporterOptions['getCoverageOptions'];
#coverageOptions: StorybookCoverageReporterOptions['coverageOptions'];

constructor(opts: StorybookCoverageReporterOptions) {
super();
this.#testManager = opts.testManager;
this.#getCoverageOptions = opts.getCoverageOptions;
this.#coverageOptions = opts.coverageOptions;
}

onSummary(node: ReportNode) {
JReinhold marked this conversation as resolved.
Show resolved Hide resolved
@@ -32,7 +32,7 @@ export default class StorybookCoverageReporter extends ReportBase implements Par

// Fallback to Vitest's default watermarks https://vitest.dev/config/#coverage-watermarks
const [lowWatermark = 50, highWatermark = 80] =
this.#getCoverageOptions().watermarks?.statements ?? [];
this.#coverageOptions.watermarks?.statements ?? [];

const coverageDetails: Details['coverageSummary'] = {
percentage,
2 changes: 1 addition & 1 deletion code/addons/test/src/node/test-manager.ts
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ export class TestManager {
}

async handleConfigChange(
payload: TestingModuleConfigChangePayload<any, { coverage: boolean; a11y: boolean }>
payload: TestingModuleConfigChangePayload<{ coverage: boolean; a11y: boolean }>
) {
if (payload.providerId !== TEST_PROVIDER_ID) {
return;
2 changes: 1 addition & 1 deletion code/addons/test/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ export class VitestManager {
'@storybook/experimental-addon-test/internal/coverage-reporter',
{
testManager: this.testManager,
getCoverageOptions: () => this.vitest?.config?.coverage as ResolvedCoverageOptions<'v8'>,
coverageOptions: this.vitest?.config?.coverage as ResolvedCoverageOptions<'v8'>,
},
];
const coverageOptions = (
1 change: 0 additions & 1 deletion code/addons/test/src/node/vitest.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ import process from 'node:process';

import { Channel } from 'storybook/internal/channels';

import { TEST_PROVIDER_ID } from '../constants';
import { TestManager } from './test-manager';

process.env.TEST = 'true';
11 changes: 6 additions & 5 deletions code/core/src/core-events/data/testing-module.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ export type TestingModuleRunRequestPayload<
// TODO: Avoid needing to do a fetch request server-side to retrieve the index
indexUrl: string; // e.g. http://localhost:6006/index.json
storyIds?: string[]; // ['button--primary', 'button--secondary']
config?: TestProviderState<NonNullable<unknown>, Config>['config'];
config?: Config;
};

export type TestingModuleProgressReportPayload =
@@ -77,16 +77,17 @@ export type TestingModuleCancelTestRunResponsePayload =
message: string;
};

export type TestingModuleWatchModeRequestPayload = {
export type TestingModuleWatchModeRequestPayload<
Config extends { [key: string]: any } = NonNullable<unknown>,
> = {
providerId: TestProviderId;
watchMode: boolean;
config?: TestProviderState['config'];
config?: Config;
};

export type TestingModuleConfigChangePayload<
Details extends { [key: string]: any } = NonNullable<unknown>,
Config extends { [key: string]: any } = NonNullable<unknown>,
> = {
providerId: TestProviderId;
config: TestProviderState<Details, Config>['config'];
config: Config;
};