diff --git a/scripts/tasks/test-runner.ts b/scripts/tasks/test-runner.ts index 82db5bca9699..277e0f568d67 100644 --- a/scripts/tasks/test-runner.ts +++ b/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'; @@ -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();