Skip to content

Commit

Permalink
Merge pull request #19028 from storybookjs/test-runner-6.4
Browse files Browse the repository at this point in the history
Build: Use new test runner with builtin junit
  • Loading branch information
shilman committed Aug 27, 2022
2 parents 5b2c539 + 066d9c1 commit 3691842
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions scripts/tasks/test-runner.ts
@@ -1,6 +1,3 @@
import { join } from 'path';
import { pathExistsSync, readFile, writeFile } from 'fs-extra';

import { servePackages } from '../utils/serve-packages';
import type { Task } from '../task';
import { exec } from '../utils/exec';
Expand All @@ -17,31 +14,16 @@ export const testRunner: Task = {

// We could split this out into a separate task if it became annoying
const publishController = await servePackages({});
await exec(`yarn add --dev @storybook/test-runner jest-junit`, execOptions);

// Note we could split this out into a separate task too. We sort of do by checking if the file exists
const testFilePathname = join(sandboxDir, 'test-runner-jest.config.js');
if (junitFilename && !(await pathExistsSync(testFilePathname))) {
await exec(`yarn test-storybook --eject`, execOptions);
const testFile = await readFile(testFilePathname, 'utf8');

const reporters = `reporters: [
'default',
['jest-junit', {
outputDirectory: '${junitFilename}',
addFileAttribute: 'true',
usePathForSuiteName: 'true',
uniqueOutputName: 'true' },
],
],`;

const newTestFile = testFile.replace(/}\s*$/m, `${reporters}$&`);
await writeFile(testFilePathname, newTestFile);
}
await exec(`yarn add --dev @storybook/test-runner`, execOptions);

const storybookController = await serveSandbox(builtSandboxDir, {});

await exec(`yarn test-storybook --url http://localhost:8001`, execOptions);
await exec(`yarn test-storybook --url http://localhost:8001 --junit`, {
...execOptions,
env: {
JEST_JUNIT_OUTPUT_FILE: junitFilename,
},
});

publishController.abort();
storybookController.abort();
Expand Down

0 comments on commit 3691842

Please sign in to comment.