Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS migration jest-circus #7916

Merged
merged 44 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1850348
Migration to ts (part 1)
doniyor2109 Feb 16, 2019
3309c3b
Merge remote-tracking branch 'jest/master' into jest-circus/ts_migration
doniyor2109 Feb 16, 2019
e89b57b
Migration to ts (part 2)
doniyor2109 Feb 16, 2019
62d423c
Migration to ts (part 3)
doniyor2109 Feb 16, 2019
6d18743
Minor tweaks
doniyor2109 Feb 16, 2019
f8d6b1c
TS migration (part 4)
doniyor2109 Feb 16, 2019
a279271
Wrong dts
doniyor2109 Feb 16, 2019
d0adc8e
dts for co
doniyor2109 Feb 16, 2019
bd16585
Added project references
doniyor2109 Feb 16, 2019
017df40
Merge remote-tracking branch 'jest/master' into jest-circus/ts_migration
doniyor2109 Feb 16, 2019
2ad24c1
Remove not ts module
doniyor2109 Feb 16, 2019
b033e2e
Replace custom co dts with @types/co
doniyor2109 Feb 17, 2019
f75fa0a
No index file
SimenB Feb 17, 2019
0fad01d
Some tweaks
doniyor2109 Feb 17, 2019
e982e1e
Some tweaks
doniyor2109 Feb 17, 2019
2d82778
Temp DiffOptions type
doniyor2109 Feb 17, 2019
c76f342
Remove extra eslint disable
doniyor2109 Feb 17, 2019
6401264
Workaround for global vars
doniyor2109 Feb 17, 2019
6e11c8d
Resolves
doniyor2109 Feb 17, 2019
dd6cc0f
Move @types/co to devDeps
doniyor2109 Feb 17, 2019
ecdc291
Update packages/jest-circus/src/run.ts
SimenB Feb 17, 2019
54a986e
Update packages/jest-circus/src/utils.ts
SimenB Feb 17, 2019
0cc1688
Tweaks
doniyor2109 Feb 17, 2019
aecf7e1
Remove extra types
doniyor2109 Feb 17, 2019
ffa6116
Fix failing test
doniyor2109 Feb 18, 2019
8a8b967
Merge remote-tracking branch 'jest/master' into jest-circus/ts_migration
doniyor2109 Feb 21, 2019
ec797a0
TS migration part (4)
doniyor2109 Feb 21, 2019
2638e24
Fix linter errors
doniyor2109 Feb 21, 2019
41e8e8d
Fix types for tests
doniyor2109 Feb 21, 2019
6df3fd4
Fix @jest/types cannot be found in test
doniyor2109 Feb 22, 2019
bb16143
Detailed comment for flowfix
doniyor2109 Feb 22, 2019
9e8545b
Ignore ts errors for non migrated modules
doniyor2109 Feb 22, 2019
aa322f8
`import =` is not supported by @babel/plugin-transform-typescript
doniyor2109 Feb 22, 2019
a0766a6
Fix weired ts error
doniyor2109 Feb 22, 2019
1f88dd6
Fix linter errors
doniyor2109 Feb 22, 2019
de7b093
Remove extra eslint disables
doniyor2109 Feb 22, 2019
ec2bcda
Move expect types to @jest/types
doniyor2109 Feb 22, 2019
0ed2e9e
[email protected]:doniyor2109/jest.giterge branch 'master' into jest-ci…
SimenB Feb 22, 2019
136f986
tweaks
SimenB Feb 22, 2019
fbe9d77
remove jest config change
SimenB Feb 22, 2019
5b49c03
fix test
SimenB Feb 22, 2019
88655bb
Added reminder for replacing Each type
doniyor2109 Feb 22, 2019
849b8c2
keep comments from old tests
SimenB Feb 22, 2019
cba5c77
Update CHANGELOG.md
SimenB Feb 22, 2019
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
4 changes: 4 additions & 0 deletions packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"@babel/traverse": "^7.1.0",
"@jest/types": "^24.1.0",
"@types/node": "*",
"chalk": "^2.0.1",
"co": "^4.6.0",
"expect": "^24.1.0",
Expand All @@ -25,6 +28,7 @@
},
"devDependencies": {
"@types/babel__traverse": "^7.0.4",
"@types/co": "^4.6.0",
"@types/stack-utils": "^1.0.1",
"execa": "^1.0.0",
"jest-diff": "^24.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow scrict-local
*/

'use strict';

import type {EventHandler} from 'types/Circus';
import {EventHandler} from '../types';

const testEventHandler: EventHandler = (event, state) => {
switch (event.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow strict-local
*/

'use strict';
// $FlowFixMe - execa is untyped
import {sync as spawnSync} from 'execa';
import fs from 'fs';
import os from 'os';
import path from 'path';
import crypto from 'crypto';
import {sync as spawnSync, ExecaReturns} from 'execa';
// @ts-ignore
import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest';

const CIRCUS_PATH = require.resolve('../../build/index');
const CIRCUS_PATH = require.resolve('../../build');
const CIRCUS_RUN_PATH = require.resolve('../../build/run');
const CIRCUS_STATE_PATH = require.resolve('../../build/state');
const TEST_EVENT_HANDLER_PATH = require.resolve('./testEventHandler');
const BABEL_REGISTER_PATH = require.resolve('@babel/register');

skipSuiteOnWindows();

interface Result extends ExecaReturns {
status: number;
error: string;
}

export const runTest = (source: string) => {
const filename = crypto
.createHash('md5')
Expand All @@ -33,7 +35,7 @@ export const runTest = (source: string) => {
const tmpFilename = path.join(os.tmpdir(), filename);

const content = `
require('${BABEL_REGISTER_PATH}');
require('${BABEL_REGISTER_PATH}')({extensions: [".js", ".ts"]});
const circus = require('${CIRCUS_PATH}');
global.test = circus.test;
global.describe = circus.describe;
Expand All @@ -54,7 +56,9 @@ export const runTest = (source: string) => {
`;

fs.writeFileSync(tmpFilename, content);
const result = spawnSync('node', [tmpFilename], {cwd: process.cwd()});
const result = spawnSync('node', [tmpFilename], {
cwd: process.cwd(),
}) as Result;

// For compat with cross-spawn
result.status = result.code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow strict-local
*/

'use strict';

import {runTest} from '../__mocks__/testUtils';

test('tests are not marked done until their parent afterAll runs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow strict-local
*/

'use strict';

import {runTest} from '../__mocks__/testUtils';

test('simple test', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
*/

'use strict';
import {Global} from '@jest/types';

let circusIt;
let circusTest;
let circusIt: Global.It;
let circusTest: Global.It;

// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
// the two with this alias.

const aliasCircusIt = () => {
const {it, test} = require('../index.js');
const {it, test} = require('../');
circusIt = it;
circusTest = test;
};
Expand All @@ -35,21 +33,21 @@ describe('test/it error throwing', () => {
});
it(`it throws error with missing callback function`, () => {
expect(() => {
// $FlowFixMe: Easy, we're testing runtime errors here
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
// @ts-ignore: Easy, we're testing runtime errors here
circusIt('test2');
}).toThrowError(
'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',
);
});
it(`it throws an error when first argument isn't a string`, () => {
expect(() => {
// $FlowFixMe: Easy, we're testing runtime errors here
// @ts-ignore: Easy, we're testing runtime errors here
circusIt(() => {});
}).toThrowError('Invalid first argument, () => {}. It must be a string.');
});
it('it throws an error when callback function is not a function', () => {
expect(() => {
// $FlowFixMe: Easy, we're testing runtime errors here
// @ts-ignore: Easy, we're testing runtime errors here
circusIt('test4', 'test4b');
}).toThrowError(
'Invalid second argument, test4b. It must be a callback function.',
Expand All @@ -62,21 +60,21 @@ describe('test/it error throwing', () => {
});
it(`test throws error with missing callback function`, () => {
expect(() => {
// $FlowFixMe: Easy, we're testing runtime errors here
// @ts-ignore: Easy, we're testing runtime errors here
circusTest('test6');
}).toThrowError(
'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',
);
});
it(`test throws an error when first argument isn't a string`, () => {
expect(() => {
// $FlowFixMe: Easy, we're testing runtime errors here
// @ts-ignore: Easy, we're testing runtime errors here
circusTest(() => {});
}).toThrowError('Invalid first argument, () => {}. It must be a string.');
});
it('test throws an error when callback function is not a function', () => {
expect(() => {
// $FlowFixMe: Easy, we're testing runtime errors here
// @ts-ignore: Easy, we're testing runtime errors here
circusTest('test8', 'test8b');
}).toThrowError(
'Invalid second argument, test8b. It must be a callback function.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
*/

'use strict';
import {Global} from '@jest/types';

let circusIt;
let circusIt: Global.It;

// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
// the two with this alias.

const aliasCircusIt = () => {
const {it} = require('../index.js');
const {it} = require('../');
circusIt = it;
};

Expand All @@ -24,7 +22,7 @@ aliasCircusIt();
describe('test/it.todo error throwing', () => {
it('todo throws error when given no arguments', () => {
expect(() => {
// $FlowFixMe: Testing runitme errors here
// @ts-ignore: Testing runtime errors here
circusIt.todo();
}).toThrowError('Todo must be called with only a description.');
});
Expand All @@ -35,7 +33,7 @@ describe('test/it.todo error throwing', () => {
});
it('todo throws error when given none string description', () => {
expect(() => {
// $FlowFixMe: Testing runitme errors here
// @ts-ignore: Testing runtime errors here
circusIt.todo(() => {});
}).toThrowError('Todo must be called with only a description.');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow strict-local
*/

'use strict';

import {runTest} from '../__mocks__/testUtils';

test('beforeEach is executed before each test in current/child describe blocks', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

const circus = require('../index.js');
import circus from '../';
import {HookType} from '../types';

describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
describe.each(['beforeEach', 'beforeAll', 'afterEach', 'afterAll'])(
'%s hooks error throwing',
fn => {
(fn: HookType) => {
test.each([
['String'],
[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
*/

import type {EventHandler, Exception} from 'types/Circus';
import {EventHandler, TEST_TIMEOUT_SYMBOL} from './types';

import {
addErrorToEachTestUnderDescribe,
Expand All @@ -22,9 +20,6 @@ import {
restoreGlobalErrorHandlers,
} from './globalErrorHandlers';

// To pass this value from Runtime object to state we need to use global[sym]
const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL');

const eventHandler: EventHandler = (event, state): void => {
switch (event.name) {
case 'include_test_location_in_result': {
Expand Down Expand Up @@ -112,14 +107,14 @@ const eventHandler: EventHandler = (event, state): void => {

if (type === 'beforeAll') {
invariant(describeBlock, 'always present for `*All` hooks');
addErrorToEachTestUnderDescribe(describeBlock, error, asyncError);
addErrorToEachTestUnderDescribe(describeBlock!, error, asyncError);
} else if (type === 'afterAll') {
// Attaching `afterAll` errors to each test makes execution flow
// too complicated, so we'll consider them to be global.
state.unhandledErrors.push([error, asyncError]);
} else {
invariant(test, 'always present for `*Each` hooks');
test.errors.push([error, asyncError]);
test!.errors.push([error, asyncError]);
SimenB marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}
Expand Down Expand Up @@ -152,8 +147,7 @@ const eventHandler: EventHandler = (event, state): void => {
break;
}
case 'test_retry': {
const errors: Array<[?Exception, Exception]> = [];
event.test.errors = errors;
event.test.errors = [];
break;
}
case 'run_start': {
Expand Down Expand Up @@ -185,8 +179,8 @@ const eventHandler: EventHandler = (event, state): void => {
invariant(state.originalGlobalErrorHandlers);
invariant(state.parentProcess);
restoreGlobalErrorHandlers(
state.parentProcess,
state.originalGlobalErrorHandlers,
state.parentProcess!,
SimenB marked this conversation as resolved.
Show resolved Hide resolved
state.originalGlobalErrorHandlers!,
);
break;
}
Expand Down
Loading