Skip to content

Commit

Permalink
fix watch mode check when coverage flag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jun 17, 2023
1 parent b78beb6 commit aa7a0c9
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/test-storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ const cleanup = () => {
}
};

let isWatchMode = false;
async function reportCoverage(jestOptions) {
if (isWatchMode || process.env.STORYBOOK_COLLECT_COVERAGE !== 'true') {
return;
}

async function reportCoverage() {
const coverageFolderE2E = path.resolve(process.cwd(), '.nyc_output');
const coverageFolder = path.resolve(process.cwd(), 'coverage/storybook');

Expand Down Expand Up @@ -85,7 +80,9 @@ async function reportCoverage(jestOptions) {

const onProcessEnd = () => {
cleanup();
reportCoverage();
if (process.env.STORYBOOK_COLLECT_COVERAGE !== 'true') {
reportCoverage();
}
};

process.on('SIGINT', onProcessEnd);
Expand Down Expand Up @@ -250,7 +247,7 @@ const main = async () => {
}

// set this flag to skip reporting coverage in watch mode
isWatchMode = jestOptions.watch || jestOptions.watchAll;
const isWatchMode = jestOptions.includes('--watch') || jestOptions.includes('--watchAll');

const rawTargetURL = process.env.TARGET_URL || runnerOptions.url || 'http://127.0.0.1:6006';
await checkStorybook(rawTargetURL);
Expand All @@ -259,7 +256,7 @@ const main = async () => {

process.env.TARGET_URL = targetURL;

if (runnerOptions.coverage) {
if (!isWatchMode && runnerOptions.coverage) {
process.env.STORYBOOK_COLLECT_COVERAGE = 'true';
}

Expand All @@ -271,7 +268,7 @@ const main = async () => {
process.env.REFERENCE_URL = sanitizeURL(process.env.REFERENCE_URL);
}

if (jestOptions.shard) {
if (jestOptions.includes('--shard')) {
process.env.JEST_SHARD = 'true';
}

Expand Down

0 comments on commit aa7a0c9

Please sign in to comment.