Skip to content

Commit

Permalink
Merge pull request #177 from storybookjs/fix/coverage-error-storystorev7
Browse files Browse the repository at this point in the history
Support storyStoreV7 in coverage check
  • Loading branch information
yannbf committed Aug 24, 2022
2 parents 2f72fee + 1385c6d commit 8addce3
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 227 deletions.
24 changes: 24 additions & 0 deletions src/playwright/transformPlaywright.test.ts
Expand Up @@ -89,6 +89,14 @@ describe('Playwright', () => {
}
if (global.__sbCollectCoverage) {
const isCoverageSetupCorrectly = await page.evaluate(() => '__coverage__' in window);
if (!isCoverageSetupCorrectly) {
throw new Error(\`[Test runner] An error occurred when evaluating code coverage:
The code in this story is not instrumented, which means the coverage setup is likely not correct.
More info: https://github.com/storybookjs/test-runner#setting-up-code-coverage\`);
}
await jestPlaywright.saveCoverage(page);
}
Expand Down Expand Up @@ -164,6 +172,14 @@ describe('Playwright', () => {
}
if (global.__sbCollectCoverage) {
const isCoverageSetupCorrectly = await page.evaluate(() => '__coverage__' in window);
if (!isCoverageSetupCorrectly) {
throw new Error(\`[Test runner] An error occurred when evaluating code coverage:
The code in this story is not instrumented, which means the coverage setup is likely not correct.
More info: https://github.com/storybookjs/test-runner#setting-up-code-coverage\`);
}
await jestPlaywright.saveCoverage(page);
}
Expand Down Expand Up @@ -240,6 +256,14 @@ describe('Playwright', () => {
}
if (global.__sbCollectCoverage) {
const isCoverageSetupCorrectly = await page.evaluate(() => '__coverage__' in window);
if (!isCoverageSetupCorrectly) {
throw new Error(\`[Test runner] An error occurred when evaluating code coverage:
The code in this story is not instrumented, which means the coverage setup is likely not correct.
More info: https://github.com/storybookjs/test-runner#setting-up-code-coverage\`);
}
await jestPlaywright.saveCoverage(page);
}
Expand Down
12 changes: 12 additions & 0 deletions src/playwright/transformPlaywright.ts
Expand Up @@ -4,12 +4,19 @@ import { userOrAutoTitle } from '@storybook/store';

import { getStorybookMetadata } from '../util';
import { transformCsf } from '../csf/transformCsf';
import dedent from 'ts-dedent';

const filePrefixer = template(`
import global from 'global';
const { setupPage } = require('@storybook/test-runner');
`);

const coverageErrorMessage = dedent`
[Test runner] An error occurred when evaluating code coverage:
The code in this story is not instrumented, which means the coverage setup is likely not correct.
More info: https://github.com/storybookjs/test-runner#setting-up-code-coverage
`;

export const testPrefixer = template(
`
console.log({ id: %%id%%, title: %%title%%, name: %%name%%, storyExport: %%storyExport%% });
Expand All @@ -34,6 +41,11 @@ export const testPrefixer = template(
}
if(global.__sbCollectCoverage) {
const isCoverageSetupCorrectly = await page.evaluate(() => '__coverage__' in window);
if (!isCoverageSetupCorrectly) {
throw new Error(\`${coverageErrorMessage}\`);
}
await jestPlaywright.saveCoverage(page);
}
Expand Down

0 comments on commit 8addce3

Please sign in to comment.