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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix test matching
  • Loading branch information
igor-dv committed Nov 1, 2018
commit 4f20ef533487c9af77c15166aa718f17b899c554
21 changes: 13 additions & 8 deletions addons/jest/src/index.js
Original file line number Diff line number Diff line change
@@ -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 });