Skip to content
Permalink
Browse files

Inherit "only" mode unless there is tests with "only" mode already (#…

  • Loading branch information
doniyor2109 authored and SimenB committed Feb 14, 2019
1 parent 0c1d5f9 commit 696d424ecb7753778dc54c58c58d824f9055ed9c
@@ -12,6 +12,7 @@
- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652))
- `[jest-changed-files]` Improve default file selection for Mercurial repos ([#7880](https://github.com/facebook/jest/pull/7880))
- `[jest-validate]` Fix validating async functions ([#7894](https://github.com/facebook/jest/issues/7894))
- `[jest-circus]` Fix bug with test.only ([#7888](https://github.com/facebook/jest/pull/7888))

### Chore & Maintenance

@@ -0,0 +1,17 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import {json} from '../runJest';

it('runs only "it.only" tests', () => {
const {
json: {numPassedTests, numPendingTests},
} = json('focused-tests');
expect(numPassedTests).toBe(1);
expect(numPendingTests).toBe(2);
});
@@ -0,0 +1,25 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';

/* eslint-disable jest/no-focused-tests */

describe('describe', () => {
it('it', () => {
expect(1).toBe(1);
});
});

describe.only('describe only', () => {
it.only('it only', () => {
expect(1).toBe(1);
});

it('it', () => {
expect(1).toBe(1);
});
});
@@ -0,0 +1 @@
{}
@@ -55,6 +55,28 @@ const eventHandler: EventHandler = (event, state): void => {
});
}

// inherit mode from its parent describe but
// do not inherit "only" mode when there is already tests with "only" mode
const shouldInheritMode = !(
currentDescribeBlock.mode === 'only' &&
currentDescribeBlock.tests.find(test => test.mode === 'only')
);

if (shouldInheritMode) {
currentDescribeBlock.tests.forEach(test => {
if (!test.mode) {
test.mode = currentDescribeBlock.mode;
}
});
}

if (
!state.hasFocusedTests &&
currentDescribeBlock.tests.some(test => test.mode === 'only')
) {
state.hasFocusedTests = true;
}

if (currentDescribeBlock.parent) {
state.currentDescribeBlock = currentDescribeBlock.parent;
}
@@ -65,12 +65,6 @@ export const makeTest = (
timeout: ?number,
asyncError: Exception,
): TestEntry => {
let _mode = mode;
if (!mode) {
// if not set explicitly, inherit from its parent describe
_mode = parent.mode;
}

const errors: Array<[?Exception, Exception]> = [];

return {
@@ -79,7 +73,7 @@ export const makeTest = (
errors,
fn,
invocations: 0,
mode: _mode,
mode,
name: convertDescriptorToString(name),
parent,
startedAt: null,

0 comments on commit 696d424

Please sign in to comment.
You can’t perform that action at this time.