This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented internally that order of scenarios can be controlled
- Loading branch information
1 parent
339a439
commit fcdf222
Showing
2 changed files
with
23 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { configure } from '@storybook/react'; | ||
|
||
/** | ||
* Generate a comparison function for string arrays. | ||
* @param prioritizes List of regular expressions for preferred. | ||
* | ||
* If more than one was described, the first one takes precedence. | ||
*/ | ||
const createComparer = (...prioritizes: RegExp[]) => (a: string, b: string) => { | ||
const matches = prioritizes.map(reg => ({ a: reg.test(a), b: reg.test(b) })); | ||
const prior = matches.reduce( | ||
(acc, { a: hitA, b: hitB }) => acc || +(hitA !== hitB) * (hitA ? -1 : 1), | ||
0 | ||
); | ||
return prior || a.localeCompare(b); | ||
}; | ||
|
||
// automatically import all files ending in *.stories.js(x), *.stories.ts(x) | ||
configure(() => { | ||
const req = require.context('~/stories', true, /.stories.[jt]sx?$/); | ||
const files = req.keys().sort(createComparer()); | ||
files.forEach(filename => req(filename).default()); | ||
}, module); |