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 the visual regression testing
- Loading branch information
1 parent
aaf8518
commit f87b9e5
Showing
5 changed files
with
76 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,45 @@ | ||
import noop from 'lodash.noop'; | ||
import getArgs from './args'; | ||
import spawnAsync from './spawnAsync'; | ||
import * as storybook from './storybook'; | ||
|
||
/** Command definition for BackstopJS. */ | ||
type BackstopCommand = 'reference' | 'test'; | ||
|
||
/** CLI Options definition for BackstopJS. */ | ||
interface IBackstopOptions { | ||
/** Command for BackstopJS. */ | ||
backstop: BackstopCommand; | ||
} | ||
|
||
/** Default values of options for BackstopJS. */ | ||
export const options = Object.freeze({ backstop: 'test' } as IBackstopOptions); | ||
|
||
/** | ||
* Get CLI for BackstopJS. | ||
* @param options command for BackstopJS, and port number. | ||
*/ | ||
const getBackstopCLI = ({ | ||
command, | ||
port | ||
}: { | ||
command: BackstopCommand; | ||
port?: number; | ||
}) => | ||
`backstop ${command} --configPath=backstop.config.js ${ | ||
port && port > 0 ? `--port=${port}` : '' | ||
}`; | ||
|
||
/** | ||
* Launch the BackstopJS. | ||
* | ||
* And launch the Storybook server on dynamic port if required. | ||
*/ | ||
const backstopAsync = async () => { | ||
const { exists, port } = await storybook.findServer(); | ||
const kill = exists ? noop : await storybook.launchNoWaitAsync(port); | ||
await spawnAsync(getBackstopCLI({ command: getArgs().backstop, port })); | ||
kill(); | ||
}; | ||
|
||
export default backstopAsync; |