Skip to content

Commit

Permalink
Fix testNamePattern value with interactive snapshots (#6579)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze authored and SimenB committed Jul 3, 2018
1 parent fa8550d commit 4ec046b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes

- `[jest-regex-util]` Improve handling already escaped path separators on Windows ([#6523](https://github.com/facebook/jest/pull/6523))
- `[jest-cli]` Fix `testNamePattern` value with interactive snapshots ([#6579](https://github.com/facebook/jest/pull/6579))

### Chore & Maintenance

Expand Down
36 changes: 18 additions & 18 deletions packages/jest-cli/src/__tests__/snapshot_interactive_mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ describe('SnapshotInteractiveMode', () => {

test('call to run process the first file', () => {
const assertions = [
{path: 'first.js', title: 'test one'},
{path: 'second.js', title: 'test two'},
{fullName: 'test one', path: 'first.js'},
{fullName: 'test two', path: 'second.js'},
];
instance.run(assertions, mockCallback);
expect(instance.isActive()).toBeTruthy();
Expand All @@ -53,8 +53,8 @@ describe('SnapshotInteractiveMode', () => {

test('call to abort', () => {
const assertions = [
{path: 'first.js', title: 'test one'},
{path: 'second.js', title: 'test two'},
{fullName: 'test one', path: 'first.js'},
{fullName: 'test two', path: 'second.js'},
];
instance.run(assertions, mockCallback);
expect(instance.isActive()).toBeTruthy();
Expand All @@ -66,8 +66,8 @@ describe('SnapshotInteractiveMode', () => {

test('call to reset', () => {
const assertions = [
{path: 'first.js', title: 'test one'},
{path: 'second.js', title: 'test two'},
{fullName: 'test one', path: 'first.js'},
{fullName: 'test two', path: 'second.js'},
];
instance.run(assertions, mockCallback);
expect(instance.isActive()).toBeTruthy();
Expand All @@ -85,15 +85,15 @@ describe('SnapshotInteractiveMode', () => {
});

test('press ENTER trigger a run', () => {
const assertions = [{path: 'first.js', title: 'test one'}];
const assertions = [{fullName: 'test one', path: 'first.js'}];
instance.run(assertions, mockCallback);
instance.put(KEYS.ENTER);
expect(mockCallback).toHaveBeenCalledTimes(2);
expect(mockCallback).toHaveBeenCalledWith(assertions[0], false);
});

test('skip 1 test, then restart', () => {
const assertions = [{path: 'first.js', title: 'test one'}];
const assertions = [{fullName: 'test one', path: 'first.js'}];

instance.run(assertions, mockCallback);
expect(mockCallback).nthCalledWith(1, assertions[0], false);
Expand All @@ -113,7 +113,7 @@ describe('SnapshotInteractiveMode', () => {
});

test('skip 1 test, then quit', () => {
const assertions = [{path: 'first.js', title: 'test one'}];
const assertions = [{fullName: 'test one', path: 'first.js'}];

instance.run(assertions, mockCallback);
expect(mockCallback).nthCalledWith(1, assertions[0], false);
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('SnapshotInteractiveMode', () => {
instance.updateWithResults({snapshot: {failure: true}});
});

const assertions = [{path: 'first.js', title: 'test one'}];
const assertions = [{fullName: 'test one', path: 'first.js'}];

instance.run(assertions, mockCallback);
expect(mockCallback).nthCalledWith(1, assertions[0], false);
Expand All @@ -162,8 +162,8 @@ describe('SnapshotInteractiveMode', () => {

test('skip 2 tests, then finish and restart', () => {
const assertions = [
{path: 'first.js', title: 'test one'},
{path: 'first.js', title: 'test two'},
{fullName: 'test one', path: 'first.js'},
{fullName: 'test two', path: 'first.js'},
];
instance.run(assertions, mockCallback);
expect(mockCallback).nthCalledWith(1, assertions[0], false);
Expand Down Expand Up @@ -207,8 +207,8 @@ describe('SnapshotInteractiveMode', () => {
});

const assertions = [
{path: 'first.js', title: 'test one'},
{path: 'first.js', title: 'test two'},
{fullName: 'test one', path: 'first.js'},
{fullName: 'test two', path: 'first.js'},
];

instance.run(assertions, mockCallback);
Expand Down Expand Up @@ -255,8 +255,8 @@ describe('SnapshotInteractiveMode', () => {
});

const assertions = [
{path: 'first.js', title: 'test one'},
{path: 'first.js', title: 'test two'},
{fullName: 'test one', path: 'first.js'},
{fullName: 'test two', path: 'first.js'},
];

instance.run(assertions, mockCallback);
Expand Down Expand Up @@ -303,8 +303,8 @@ describe('SnapshotInteractiveMode', () => {
});

const assertions = [
{path: 'first.js', title: 'test one'},
{path: 'first.js', title: 'test two'},
{fullName: 'test one', path: 'first.js'},
{fullName: 'test two', path: 'first.js'},
];

instance.run(assertions, mockCallback);
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/plugins/update_snapshots_interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
testResult.testResults.forEach(result => {
if (result.status === 'failed') {
failedTestPaths.push({
fullName: result.fullName,
path: testResult.testFilePath,
title: result.title,
});
}
});
Expand Down Expand Up @@ -77,7 +77,7 @@ class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
(assertion: ?AssertionLocation, shouldUpdateSnapshot: boolean) => {
updateConfigAndRun({
mode: 'watch',
testNamePattern: assertion ? `^${assertion.title}$` : '',
testNamePattern: assertion ? `^${assertion.fullName}$` : '',
testPathPattern: assertion ? assertion.path : '',

updateSnapshot: shouldUpdateSnapshot ? 'all' : 'none',
Expand Down
2 changes: 1 addition & 1 deletion types/TestResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export type FailedAssertion = {|
|};

export type AssertionLocation = {|
fullName: string,
path: string,
title: string,
|};

export type Status = 'passed' | 'failed' | 'skipped' | 'pending';
Expand Down

0 comments on commit 4ec046b

Please sign in to comment.