Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addons Jest - Fix test matching #4689

Merged
merged 3 commits into from
Nov 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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