-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46c430f
commit 917d80a
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# jest-storybook | ||
|
||
Jest implementation for Storybook. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "jest-storybook", | ||
"version": "1.0.0", | ||
"description": "Jest implementation for Storybook", | ||
"main": "src/jest.storybook.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybooks/storybook" | ||
}, | ||
"keywords": [ | ||
"jest", | ||
"storybook" | ||
], | ||
"author": "evexoio (Abdullah Samman)", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/storybooks/storybook/issues" | ||
}, | ||
"homepage": "https://github.com/storybooks/storybook", | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-preset-jest": "^23.2.0", | ||
"falafel": "^2.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
testMatch: ['**/*.stories.js'], | ||
transform: { | ||
'^.+\\.js$': 'jest-storybook', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const falafel = require('falafel'); // eslint-disable-line import/no-extraneous-dependencies | ||
const babel = require('babel-core'); | ||
const jestPreset = require('babel-preset-jest'); | ||
|
||
module.exports.process = (src, filename) => { | ||
let output = falafel(src, { sourceType: 'module' }, (node) => { // AST just to import getStorybook. overkill? | ||
if (node.type === 'ImportSpecifier' && node.imported.name === 'storiesOf') { | ||
node.update(`${node.source()}, getStorybook`); | ||
} | ||
}); | ||
|
||
output = ` | ||
import addons, { mockChannel } from '@storybook/addons'; | ||
addons.setChannel(mockChannel()); | ||
${output.toString()} | ||
const storybook = getStorybook(); | ||
storybook.forEach((story) => { | ||
story.stories.forEach((subStory) => { | ||
describe(story.kind, () => { | ||
it(subStory.name, () => { | ||
expect(subStory.render()).toMatchSnapshot(); | ||
}); }); }); });`; | ||
|
||
if (babel.util.canCompile(filename)) { | ||
src = babel.transform(output, { | ||
filename, | ||
presets: [jestPreset], | ||
}); | ||
} | ||
|
||
return src; | ||
}; |