Skip to content

Commit

Permalink
Merge pull request #4689 from storybooks/addon-jest/fix-tests-matching
Browse files Browse the repository at this point in the history
Addons Jest - Fix test matching
  • Loading branch information
igor-dv committed Nov 5, 2018
2 parents 7cba6dc + 648d308 commit 2a553ac
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions addons/jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
});

Expand All @@ -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 });
Expand Down

0 comments on commit 2a553ac

Please sign in to comment.