diff --git a/addons/jest/src/index.js b/addons/jest/src/index.js index 1ccd4f842bb4..583e02533bff 100644 --- a/addons/jest/src/index.js +++ b/addons/jest/src/index.js @@ -5,13 +5,19 @@ import { normalize } from 'upath'; const findTestResults = (testFiles, jestTestResults, jestTestFilesExt) => Object.values(testFiles).map(name => { const fileName = `${name}${jestTestFilesExt}`; + if (jestTestResults && jestTestResults.testResults) { + const fileNamePattern = new RegExp(fileName); + return { fileName, name, - result: jestTestResults.testResults.find(t => normalize(t.name).includes(fileName)), + result: jestTestResults.testResults.find(test => + normalize(test.name).match(fileNamePattern) + ), }; } + return { fileName, name }; }); @@ -38,13 +44,12 @@ export const withTests = userOptions => { }, 'Passing component filenames to the `@storybook/addon-jest` via `withTests` is deprecated. Instead, use the `jest` story parameter'); } - const [ - story, - { - kind, - parameters: { jest: testFiles }, - }, - ] = args; + const [story, { kind, parameters = {} }] = args; + let { jest: testFiles } = parameters; + + if (typeof testFiles === 'string') { + testFiles = [testFiles]; + } if (testFiles && !testFiles.disable) { emitAddTests({ kind, story, testFiles, options });