-
-
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.
Merge pull request #3757 from storybooks/storyshots-remove-require-co…
…ntext Storyshots - Replace require_context.js with babel-plugin-require-context-hook
- Loading branch information
Showing
27 changed files
with
139 additions
and
206 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
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
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
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
46 changes: 46 additions & 0 deletions
46
addons/storyshots/storyshots-core/src/api/ensureOptionsDefaults.js
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,46 @@ | ||
import { snapshotWithOptions } from '../test-bodies'; | ||
import Stories2SnapsConverter from '../Stories2SnapsConverter'; | ||
|
||
const ignore = ['**/node_modules/**']; | ||
const defaultStories2SnapsConverter = new Stories2SnapsConverter(); | ||
|
||
function getIntegrityOptions({ integrityOptions }) { | ||
if (integrityOptions === false) { | ||
return false; | ||
} | ||
|
||
if (typeof integrityOptions !== 'object') { | ||
return false; | ||
} | ||
|
||
return { | ||
...integrityOptions, | ||
ignore: [...ignore, ...(integrityOptions.ignore || [])], | ||
absolute: true, | ||
}; | ||
} | ||
|
||
function ensureOptionsDefaults(options) { | ||
const { | ||
suite = 'Storyshots', | ||
storyNameRegex, | ||
storyKindRegex, | ||
renderer, | ||
serializer, | ||
stories2snapsConverter = defaultStories2SnapsConverter, | ||
test: testMethod = snapshotWithOptions({ renderer, serializer }), | ||
} = options; | ||
|
||
const integrityOptions = getIntegrityOptions(options); | ||
|
||
return { | ||
suite, | ||
storyNameRegex, | ||
storyKindRegex, | ||
stories2snapsConverter, | ||
testMethod, | ||
integrityOptions, | ||
}; | ||
} | ||
|
||
export default ensureOptionsDefaults; |
19 changes: 0 additions & 19 deletions
19
addons/storyshots/storyshots-core/src/api/getIntegrityOptions.js
This file was deleted.
Oops, something went wrong.
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
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
43 changes: 0 additions & 43 deletions
43
addons/storyshots/storyshots-core/src/frameworks/config-loader.js
This file was deleted.
Oops, something went wrong.
25 changes: 15 additions & 10 deletions
25
addons/storyshots/storyshots-core/src/frameworks/configure.js
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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import loadConfig from './config-loader'; | ||
import runWithRequireContext from './require_context'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
function getConfigPathParts(configPath) { | ||
const resolvedConfigPath = path.resolve(configPath); | ||
|
||
if (fs.lstatSync(resolvedConfigPath).isDirectory()) { | ||
return path.join(resolvedConfigPath, 'config.js'); | ||
} | ||
|
||
return resolvedConfigPath; | ||
} | ||
|
||
function configure(options) { | ||
const { configPath = '.storybook', config, frameworkOptions, storybook } = options; | ||
const { configPath = '.storybook', config, storybook } = options; | ||
|
||
if (config && typeof config === 'function') { | ||
config(storybook); | ||
return; | ||
} | ||
|
||
const appOptions = require.requireActual(frameworkOptions).default; | ||
|
||
const { content, contextOpts } = loadConfig({ | ||
configPath, | ||
appOptions, | ||
}); | ||
const resolvedConfigPath = getConfigPathParts(configPath); | ||
|
||
runWithRequireContext(content, contextOpts); | ||
require.requireActual(resolvedConfigPath); | ||
} | ||
|
||
export default configure; |
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
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
Oops, something went wrong.