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 11 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
Mgit@github.com: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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/jest-circus/package.json
Expand Up @@ -8,8 +8,10 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"@babel/traverse": "^7.1.0",
"@jest/types": "^24.1.0",
"chalk": "^2.0.1",
"co": "^4.6.0",
"expect": "^24.1.0",
Expand Down
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
Expand Up @@ -4,17 +4,14 @@
* 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');
Expand All @@ -25,6 +22,11 @@ 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 Down Expand Up @@ -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
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
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
Expand Up @@ -3,20 +3,15 @@
*
* 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';

let circusIt;
let circusTest;

// 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('../index.ts');
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
circusIt = it;
circusTest = test;
};
Expand All @@ -35,21 +30,18 @@ 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
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
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
circusIt('test4', 'test4b');
}).toThrowError(
'Invalid second argument, test4b. It must be a callback function.',
Expand All @@ -62,21 +54,18 @@ describe('test/it error throwing', () => {
});
it(`test throws error with missing callback function`, () => {
expect(() => {
// $FlowFixMe: 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
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
circusTest('test8', 'test8b');
}).toThrowError(
'Invalid second argument, test8b. It must be a callback function.',
Expand Down
Expand Up @@ -3,19 +3,15 @@
*
* 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';

let circusIt;

// 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('../index.ts');
circusIt = it;
};

Expand All @@ -24,7 +20,6 @@ aliasCircusIt();
describe('test/it.todo error throwing', () => {
it('todo throws error when given no arguments', () => {
expect(() => {
// $FlowFixMe: Testing runitme errors here
circusIt.todo();
}).toThrowError('Todo must be called with only a description.');
});
Expand All @@ -35,7 +30,6 @@ describe('test/it.todo error throwing', () => {
});
it('todo throws error when given none string description', () => {
expect(() => {
// $FlowFixMe: Testing runitme errors here
circusIt.todo(() => {});
}).toThrowError('Todo must be called with only a description.');
});
Expand Down
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
Expand Up @@ -3,17 +3,13 @@
*
* 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 '../';

describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
'%s hooks error throwing',
fn => {
(fn: 'beforeEach' | 'beforeAll' | 'afterEach' | 'afterAll') => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be cool to type jest-each so that it would be inferred.

/cc @mattphillips

test.each([
['String'],
[1],
Expand Down
20 changes: 20 additions & 0 deletions packages/jest-circus/src/dts/co.d.ts
@@ -0,0 +1,20 @@
// TODO replace with @types/co when it is merged https://github.com/DefinitelyTyped/DefinitelyTyped/pull/33120
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
declare module 'co' {
type ExtractType<T> = T extends IterableIterator<infer R> ? R : never;

interface Co {
<F extends (...args: any[]) => Generator>(
fn: F,
...args: Parameters<F>
): Promise<ExtractType<ReturnType<F>>>;
default: Co;
co: Co;
wrap: <F extends (...args: any[]) => Generator>(
fn: F,
) => (...args: Parameters<F>) => Promise<ExtractType<ReturnType<F>>>;
}

const co: Co;

export = co;
}
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, Exception, 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,7 +147,7 @@ const eventHandler: EventHandler = (event, state): void => {
break;
}
case 'test_retry': {
const errors: Array<[?Exception, Exception]> = [];
const errors: Array<[Exception | undefined | null, Exception]> = [];
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
event.test.errors = errors;
break;
}
Expand All @@ -172,7 +167,7 @@ const eventHandler: EventHandler = (event, state): void => {
// i'm not sure if this is works. For now i just replicated whatever
// jasmine was doing -- dabramov
state.parentProcess = event.parentProcess;
invariant(state.parentProcess);
invariant(state.parentProcess, '');
state.originalGlobalErrorHandlers = injectGlobalErrorHandlers(
state.parentProcess,
);
Expand All @@ -182,11 +177,11 @@ const eventHandler: EventHandler = (event, state): void => {
break;
}
case 'teardown': {
invariant(state.originalGlobalErrorHandlers);
invariant(state.parentProcess);
invariant(state.originalGlobalErrorHandlers, '');
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
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