Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lint fixes
  • Loading branch information
palmerj3 committed Jul 26, 2018
commit c607e87762d42587f1b2972e1d06bea242e53627
4 changes: 2 additions & 2 deletions e2e/__tests__/test_retries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Test Retries', () => {

const reporterConfig = {
reporters: [
['<rootDir>/reporters/RetryReporter.js', { output: outputFilePath }],
['<rootDir>/reporters/RetryReporter.js', {output: outputFilePath}],
],
};

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Test Retries', () => {

const reporterConfig = {
reporters: [
['<rootDir>/reporters/RetryReporter.js', { output: outputFilePath }],
['<rootDir>/reporters/RetryReporter.js', {output: outputFilePath}],
],
};

Expand Down
68 changes: 34 additions & 34 deletions packages/jest-circus/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

import type {
RunResult,
TestEntry,
TestContext,
Hook,
DescribeBlock,
TestEntry,
TestContext,
Hook,
DescribeBlock,
} from 'types/Circus';

import { getState, dispatch } from './state';
import {getState, dispatch} from './state';
import {
callAsyncFn,
getAllHooksForDescribe,
Expand All @@ -29,22 +29,22 @@ import {
const Promise = getOriginalPromise();

const run = async (): Promise<RunResult> => {
const { rootDescribeBlock } = getState();
dispatch({ name: 'run_start' });
const {rootDescribeBlock} = getState();
dispatch({name: 'run_start'});
await _runTestsForDescribeBlock(rootDescribeBlock);
dispatch({ name: 'run_finish' });
dispatch({name: 'run_finish'});
return makeRunResult(
getState().rootDescribeBlock,
getState().unhandledErrors,
);
};

const _runTestsForDescribeBlock = async (describeBlock: DescribeBlock) => {
dispatch({ describeBlock, name: 'run_describe_start' });
const { beforeAll, afterAll } = getAllHooksForDescribe(describeBlock);
dispatch({describeBlock, name: 'run_describe_start'});
const {beforeAll, afterAll} = getAllHooksForDescribe(describeBlock);

for (const hook of beforeAll) {
await _callHook({ describeBlock, hook });
await _callHook({describeBlock, hook});
}

// Tests that fail and are retried we run after other tests
Expand Down Expand Up @@ -78,47 +78,47 @@ const _runTestsForDescribeBlock = async (describeBlock: DescribeBlock) => {
}

for (const hook of afterAll) {
await _callHook({ describeBlock, hook });
await _callHook({describeBlock, hook});
}
dispatch({ describeBlock, name: 'run_describe_finish' });
dispatch({describeBlock, name: 'run_describe_finish'});
};

const _runTest = async (test: TestEntry): Promise<void> => {
dispatch({ name: 'test_start', test });
dispatch({name: 'test_start', test});
const testContext = Object.create(null);
const { hasFocusedTests, testNamePattern } = getState();
const {hasFocusedTests, testNamePattern} = getState();

const isSkipped =
test.mode === 'skip' ||
(hasFocusedTests && test.mode !== 'only') ||
(testNamePattern && !testNamePattern.test(getTestID(test)));

if (isSkipped) {
dispatch({ name: 'test_skip', test });
dispatch({name: 'test_skip', test});
return;
}

const { afterEach, beforeEach } = getEachHooksForTest(test);
const {afterEach, beforeEach} = getEachHooksForTest(test);

for (const hook of beforeEach) {
if (test.errors.length) {
// If any of the before hooks failed already, we don't run any
// hooks after that.
break;
}
await _callHook({ hook, test, testContext });
await _callHook({hook, test, testContext});
}

await _callTest(test, testContext);

for (const hook of afterEach) {
await _callHook({ hook, test, testContext });
await _callHook({hook, test, testContext});
}

// `afterAll` hooks should not affect test status (pass or fail), because if
// we had a global `afterAll` hook it would block all existing tests until
// this hook is executed. So we dispatche `test_done` right away.
dispatch({ name: 'test_done', test });
dispatch({name: 'test_done', test});
};

const _callHook = ({
Expand All @@ -127,25 +127,25 @@ const _callHook = ({
describeBlock,
testContext,
}: {
hook: Hook,
describeBlock?: DescribeBlock,
test?: TestEntry,
testContext?: TestContext,
}): Promise<mixed> => {
dispatch({ hook, name: 'hook_start' });
hook: Hook,
describeBlock?: DescribeBlock,
test?: TestEntry,
testContext?: TestContext,
}): Promise<mixed> => {
dispatch({hook, name: 'hook_start'});
const timeout = hook.timeout || getState().testTimeout;
return callAsyncFn(hook.fn, testContext, { isHook: true, timeout })
.then(() => dispatch({ describeBlock, hook, name: 'hook_success', test }))
return callAsyncFn(hook.fn, testContext, {isHook: true, timeout})
.then(() => dispatch({describeBlock, hook, name: 'hook_success', test}))
.catch(error =>
dispatch({ describeBlock, error, hook, name: 'hook_failure', test }),
);
dispatch({describeBlock, error, hook, name: 'hook_failure', test}),
);
};

const _callTest = async (
test: TestEntry,
testContext: TestContext,
): Promise<void> => {
dispatch({ name: 'test_fn_start', test });
dispatch({name: 'test_fn_start', test});
const timeout = test.timeout || getState().testTimeout;
invariant(test.fn, `Tests with no 'fn' should have 'mode' set to 'skipped'`);

Expand All @@ -154,9 +154,9 @@ const _callTest = async (
return;
}

await callAsyncFn(test.fn, testContext, { isHook: false, timeout })
.then(() => dispatch({ name: 'test_fn_success', test }))
.catch(error => dispatch({ error, name: 'test_fn_failure', test }));
await callAsyncFn(test.fn, testContext, {isHook: false, timeout})
.then(() => dispatch({name: 'test_fn_success', test}))
.catch(error => dispatch({error, name: 'test_fn_failure', test}));
};

export default run;