-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Refactor addon-jest to use a parameter-based pattern #3678
Changes from 1 commit
0eb725b
d075bfd
2343a9a
1270509
a10c19a
1e3d925
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import addons from '@storybook/addons'; | ||
import deprecate from 'util-deprecate'; | ||
|
||
const findTestResults = (testFiles, jestTestResults, jestTestFilesExt) => | ||
testFiles.map(name => { | ||
[].concat(testFiles).map(name => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it lets the user set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I didn't know. Good trick. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Hypnosphi -- good one, I'll make that change. |
||
if (jestTestResults && jestTestResults.testResults) { | ||
return { | ||
name, | ||
|
@@ -27,9 +28,27 @@ export const withTests = userOptions => { | |
}; | ||
const options = Object.assign({}, defaultOptions, userOptions); | ||
|
||
return (...testFiles) => (storyFn, { kind, story }) => { | ||
emitAddTests({ kind, story, testFiles, options }); | ||
return (...args) => { | ||
if (typeof args[0] === 'string') { | ||
return deprecate((story, { kind }) => { | ||
emitAddTests({ kind, story, testFiles: args, options }); | ||
|
||
return storyFn(); | ||
return story(); | ||
}, '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; | ||
|
||
if (testFiles && !testFiles.skip) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Poking @tmeasday just in case you missed this comment, since this is part of the 4.0 release. If you didn't, just ignore this message! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @Keraito -- I have not forgotten, just getting around to this, sorry! |
||
emitAddTests({ kind, story, testFiles, options }); | ||
} | ||
|
||
return story(); | ||
}; | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":2,"numPassedTests":6,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTotalTestSuites":2,"numTotalTests":6,"snapshot":{"added":0,"didUpdate":false,"failure":false,"filesAdded":0,"filesRemoved":0,"filesUnmatched":0,"filesUpdated":0,"matched":0,"total":0,"unchecked":0,"uncheckedKeys":[],"unmatched":0,"updated":0},"startTime":1527433445200,"success":true,"testResults":[{"assertionResults":[{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should create the app","location":null,"status":"passed","title":"should create the app"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should have as title 'app'","location":null,"status":"passed","title":"should have as title 'app'"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should render title in a h1 tag","location":null,"status":"passed","title":"should render title in a h1 tag"}],"endTime":1527433449835,"message":"","name":"/Users/jetbrains/IdeaProjects/storybook/examples/angular-cli/src/app/app.component.spec.ts","startTime":1527433446968,"status":"passed","summary":""},{"assertionResults":[{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should create the app","location":null,"status":"passed","title":"should create the app"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should have as title 'app'","location":null,"status":"passed","title":"should have as title 'app'"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should render title in a h1 tag","location":null,"status":"passed","title":"should render title in a h1 tag"}],"endTime":1527433449838,"message":"","name":"/Users/jetbrains/IdeaProjects/storybook/examples/angular-cli/dist/app/app.component.spec.ts","startTime":1527433446974,"status":"passed","summary":""}],"wasInterrupted":false} | ||
{"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":2,"numPassedTests":6,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTotalTestSuites":2,"numTotalTests":6,"snapshot":{"added":0,"didUpdate":false,"failure":false,"filesAdded":0,"filesRemoved":0,"filesUnmatched":0,"filesUpdated":0,"matched":0,"total":0,"unchecked":0,"uncheckedKeys":[],"unmatched":0,"updated":0},"startTime":1527573039637,"success":true,"testResults":[{"assertionResults":[{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should create the app","location":null,"status":"passed","title":"should create the app"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should have as title 'app'","location":null,"status":"passed","title":"should have as title 'app'"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should render title in a h1 tag","location":null,"status":"passed","title":"should render title in a h1 tag"}],"endTime":1527573042008,"message":"","name":"/Users/tom/OSS/storybook/examples/angular-cli/dist/app/app.component.spec.ts","startTime":1527573040569,"status":"passed","summary":""},{"assertionResults":[{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should create the app","location":null,"status":"passed","title":"should create the app"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should have as title 'app'","location":null,"status":"passed","title":"should have as title 'app'"},{"ancestorTitles":["AppComponent"],"failureMessages":[],"fullName":"AppComponent should render title in a h1 tag","location":null,"status":"passed","title":"should render title in a h1 tag"}],"endTime":1527573042010,"message":"","name":"/Users/tom/OSS/storybook/examples/angular-cli/src/app/app.component.spec.ts","startTime":1527573040569,"status":"passed","summary":""}],"wasInterrupted":false} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import { storiesOf } from '@storybook/angular'; | ||
import { withTests } from '@storybook/addon-jest'; | ||
|
||
import { AppComponent } from '../app/app.component'; | ||
import { wTests } from '../../.storybook/withTests'; | ||
import * as results from '../../addon-jest.testresults.json'; | ||
|
||
storiesOf('Addon|Jest', module) | ||
.addDecorator(wTests('app.component')) | ||
.add('app.component with jest tests', () => ({ | ||
component: AppComponent, | ||
props: {}, | ||
})); | ||
.addDecorator( | ||
withTests({ | ||
results, | ||
filesExt: '((\\.specs?)|(\\.tests?))?(\\.ts)?$', | ||
}) | ||
) | ||
.add( | ||
'app.component with jest tests', | ||
() => ({ | ||
component: AppComponent, | ||
props: {}, | ||
}), | ||
{ | ||
jest: 'app.component', | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optionnal => optional 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was an existing line ;)