Skip to content

Commit

Permalink
Merge pull request #40 from kadirahq/configurable-storyshot-location
Browse files Browse the repository at this point in the history
Configurable storyshot location
  • Loading branch information
roonyh authored Oct 11, 2016
2 parents b8b7cfe + 1581f22 commit 0b97053
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
File renamed without changes.
13 changes: 8 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ program
.option('-u, --update [boolean]', 'Update saved story snapshots')
.option('-i, --update-interactive [boolean]',
'Update saved story snapshots interactively')
.option('-g, --grep [string]', 'only test stories matching regexp')
.option('-x, --exclude [string]', 'exclude stories matching regexp')
.option('-w, --watch [boolean]', 'watch file changes and rerun tests')
.option('--polyfills [string]', 'add global polyfills')
.option('--loaders [string]', 'add loaders')
.option('-g, --grep [string]', 'Only test stories matching regexp')
.option('-x, --exclude [string]', 'Exclude stories matching regexp')
.option('-w, --watch [boolean]', 'Watch file changes and rerun tests')
.option('--storyshot-dir [string]',
'Path to the directory to store storyshots. Default is [config-dir]/__storyshots__')
.option('--extension [string]', 'File extension to use for storyshot files. Default is `.shot`')
.option('--polyfills [string]', 'Add global polyfills')
.option('--loaders [string]', 'Add loaders')
.parse(process.argv);

const {
Expand Down
7 changes: 5 additions & 2 deletions src/test_runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ export default class Runner {
const {
configDir = './.storybook',
update = false,
updateInteractive: interactive,
updateInteractive = false,
storyshotDir,
extension = 'shot',
} = options;

this.runner = new SnapshotRunner(configDir, { update, interactive });
this.runner = new SnapshotRunner(
{ configDir, update, updateInteractive, storyshotDir, extension });
}

updateState(result) {
Expand Down
16 changes: 11 additions & 5 deletions src/test_runner/snapshot_runner.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
/* eslint class-methods-use-this:0 */

import path from 'path';
import { initializeSnapshotState } from 'jest-snapshot';
import { SnapshotState } from 'jest-snapshot';
import ReactTestRenderer from 'react-test-renderer';
import diff from 'jest-diff';
import promptly from 'promptly';

export default class SnapshotRunner {
constructor(configDir, { update, interactive }) {
constructor({ configDir, update, updateInteractive, storyshotDir, extension }) {
this.configDir = configDir;
this.kind = '';
this.update = update;
this.interactive = interactive;
this.interactive = updateInteractive;
this.storyshotDir = storyshotDir ? path.resolve(storyshotDir) : path.resolve(configDir, '__storyshots__');
this.extension = extension || 'shot';
}

getStoryshotPath(kind) {
return path.join(this.storyshotDir, `${kind}.${this.extension}`);
}

startKind(kind) {
const filePath = path.resolve(this.configDir, kind);
this.state = initializeSnapshotState(filePath, this.update);
const filePath = this.getStoryshotPath(kind);
this.state = new SnapshotState('', this.update, filePath);
this.kind = kind;
const { updated, added, matched, unmatched } = this.state;
this.testOutcomes = { updated, added, matched, unmatched };
Expand Down
2 changes: 1 addition & 1 deletion src/test_runner/tests/snapshot_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('SnapshotRunner', () => {

beforeEach(() => {
runner = new SnapshotRunner(
'/path/to/config-dir', { update: false, interactive: false });
{ configDir: '/path/to/config-dir', update: false, interactive: false });
runner.startKind('TestKind');
});

Expand Down

0 comments on commit 0b97053

Please sign in to comment.