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

Jest jasmine/ts migration #7970

Merged
merged 36 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a9fb41b
Migration to ts (part 1)
doniyor2109 Feb 23, 2019
239e2c7
Migration to ts (part 2)
doniyor2109 Feb 24, 2019
09867ae
Configure ts config
doniyor2109 Feb 24, 2019
0d4c004
Migrating TS (part 3)
doniyor2109 Feb 24, 2019
f57370a
fix typo
SimenB Feb 24, 2019
f9d1025
include types in package.json
SimenB Feb 24, 2019
e2877b0
Migrating TS (part 4)
doniyor2109 Feb 24, 2019
d00496a
Some tweaks
doniyor2109 Feb 27, 2019
eee8339
Small tweaks
doniyor2109 Mar 1, 2019
5ef9829
Merge remote-tracking branch 'jest/master' into jest-jasmine/ts_migra…
doniyor2109 Mar 1, 2019
2d14cf1
Merge remote-tracking branch 'jest/master' into jest-jasmine/ts_migra…
doniyor2109 Mar 2, 2019
bc6d48f
Small tweaks
doniyor2109 Mar 2, 2019
d2b3eba
Small tweaks
doniyor2109 Mar 2, 2019
b52c8f2
TS migration part (6)
doniyor2109 Mar 2, 2019
a3263b5
TS migration part (final)
doniyor2109 Mar 3, 2019
d5a4c17
Linter fixes
doniyor2109 Mar 3, 2019
b73f4b7
Fix tests
doniyor2109 Mar 3, 2019
67a046a
Merge branch 'master' into jest-jasmine/ts_migration
SimenB Mar 3, 2019
69a427e
Small tweaks
doniyor2109 Mar 3, 2019
645bc92
Merge remote-tracking branch 'jest/master' into jest-jasmine/ts_migra…
doniyor2109 Mar 3, 2019
03ec289
Merge remote-tracking branch 'origin/jest-jasmine/ts_migration' into …
doniyor2109 Mar 3, 2019
7aeeb6f
Update changelog
doniyor2109 Mar 3, 2019
26c59b5
Tweaks for property fields
doniyor2109 Mar 3, 2019
7f76abb
Merge remote-tracking branch 'jest/master' into jest-jasmine/ts_migra…
doniyor2109 Mar 3, 2019
0625619
Resolve import/no-extraneous-dependencies
doniyor2109 Mar 3, 2019
14a1564
fix jest-diff import
SimenB Mar 3, 2019
9a9c65f
tweaks
SimenB Mar 3, 2019
f9106ef
Remove extra types
doniyor2109 Mar 3, 2019
b9b422a
Merge remote-tracking branch 'origin/jest-jasmine/ts_migration' into …
doniyor2109 Mar 3, 2019
ee9d572
Merge branch 'master' into jest-jasmine/ts_migration
SimenB Mar 3, 2019
93f7414
fix error after merging master
SimenB Mar 3, 2019
8e3ecd8
Merge remote-tracking branch 'origin/jest-jasmine/ts_migration' into …
doniyor2109 Mar 4, 2019
cf01cf9
Merge remote-tracking branch 'jest/master' into jest-jasmine/ts_migra…
doniyor2109 Mar 4, 2019
b89e537
Merge branch 'master' into jest-jasmine/ts_migration
SimenB Mar 5, 2019
548f05f
lint
SimenB Mar 5, 2019
8e264a3
fix type error
SimenB Mar 5, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

### Chore & Maintenance

- `[jest-jasmine2]`: TS migration ([#7970](https://github.com/facebook/jest/pull/7970))
- `[jest-each]`: Refactor into multiple files with better types ([#8018](https://github.com/facebook/jest/pull/8018))
- `[jest-each]`: Migrate to Typescript ([#8007](https://github.com/facebook/jest/pull/8007))
- `[jest-environment-jsdom]`: Migrate to TypeScript ([#7985](https://github.com/facebook/jest/pull/8003))
Expand Down
8 changes: 5 additions & 3 deletions packages/jest-jasmine2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"@babel/traverse": "^7.1.0",
"@jest/environment": "^24.1.0",
"@jest/types": "^24.1.0",
"chalk": "^2.0.1",
"co": "^4.6.0",
"expect": "^24.1.0",
"is-generator-fn": "^2.0.0",
"jest-each": "^24.0.0",
"jest-matcher-utils": "^24.0.0",
"jest-message-util": "^24.0.0",
"jest-runtime": "^24.1.0",
"jest-snapshot": "^24.1.0",
"jest-util": "^24.0.0",
"pretty-format": "^24.0.0",
"throat": "^4.0.0"
},
"devDependencies": {
"@types/babel__traverse": "^7.0.4",
"jest-diff": "^24.0.0",
"jest-runtime": "^24.1.0"
"@types/babel__traverse": "^7.0.4"
},
"engines": {
"node": ">= 6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export default class ExpectationFailed extends Error {}
7 changes: 6 additions & 1 deletion packages/jest-jasmine2/src/PCancelable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
/**
* 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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
*
*/

'use strict';

import Suite from '../jasmine/Suite';
import Suite, {Attributes} from '../jasmine/Suite';

describe('Suite', () => {
let suite;
let suite: Suite;

beforeEach(() => {
suite = new Suite({
getTestPath: () => '',
});
} as Attributes);
});

it("doesn't throw on addExpectationResult when there are no children", () => {
expect(() => {
// @ts-ignore
suite.addExpectationResult();
}).not.toThrow();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

import expectationResultFactory from '../expectationResultFactory';

describe('expectationResultFactory', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +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';
export type SharedHookType = 'afterAll' | 'beforeAll';
export type HookType = SharedHookType | 'afterEach' | 'beforeEach';

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 @@ -6,8 +6,6 @@
*
*/

'use strict';

describe('test/it error throwing', () => {
it(`it throws error with missing callback function`, () => {
expect(() => {
Expand All @@ -18,11 +16,13 @@ describe('test/it error throwing', () => {
});
it(`it throws an error when first argument isn't a string`, () => {
expect(() => {
// @ts-ignore
it(() => {});
}).toThrowError(`Invalid first argument, () => {}. It must be a string.`);
});
it('it throws an error when callback function is not a function', () => {
expect(() => {
// @ts-ignore
it('test3', 'test3b');
}).toThrowError(
'Invalid second argument, test3b. It must be a callback function.',
Expand All @@ -37,11 +37,13 @@ describe('test/it error throwing', () => {
});
test(`test throws an error when first argument isn't a string`, () => {
expect(() => {
// @ts-ignore
test(() => {});
}).toThrowError(`Invalid first argument, () => {}. It must be a string.`);
});
test('test throws an error when callback function is not a function', () => {
expect(() => {
// @ts-ignore
test('test6', 'test6b');
}).toThrowError(
'Invalid second argument, test6b. It must be a callback function.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
*
*/

'use strict';

test('global.test', () => {});
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

describe('iterators', () => {
Copy link
Member

Choose a reason for hiding this comment

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

These tests looks like they belong in expect, don't they?

/cc @pedrottimark

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I will make sure that expect covers these test cases.

it('works for arrays', () => {
const mixedArray = [1, {}, []];
Expand Down Expand Up @@ -55,9 +53,14 @@ describe('iterators', () => {
});

it('works for Maps', () => {
const keyValuePairs = [['key1', 'value1'], ['key2', 'value2']];
const smallerKeyValuePairs = [['key1', 'value1']];
const biggerKeyValuePairs = [
const keyValuePairs: ReadonlyArray<[string, string]> = [
['key1', 'value1'],
['key2', 'value2'],
];
const smallerKeyValuePairs: ReadonlyArray<[string, string]> = [
['key1', 'value1'],
];
const biggerKeyValuePairs: ReadonlyArray<[string, string]> = [
['key1', 'value1'],
['key2', 'value2'],
['key3', 'value3'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

describe('matchers', () => {
Copy link
Member

Choose a reason for hiding this comment

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

same here - seems like they should be in expect

Copy link
Contributor

Choose a reason for hiding this comment

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

This one might be needed?

describe('matchers', () => {
  it('proxies matchers to expect', () => {
    expect(() => expect(1).toBe(2)).toThrowErrorMatchingSnapshot();
  });
});

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but it doesn't test anything jasmine? I don't understand what it means by "proxies to expect" - it uses expect directly

Copy link
Contributor

Choose a reason for hiding this comment

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

In other words, Jest test suite is integration test that expect works in jasmine.

Copy link
Member

Choose a reason for hiding this comment

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

Right - if expect didn't work in jasmine, the whole test suite would fail. The advantage of using Jest to test Jest 🙂

it('proxies matchers to expect', () => {
expect(() => expect(1).toBe(2)).toThrowErrorMatchingSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

jest.useFakeTimers();

import pTimeout from '../pTimeout';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

import queueRunner from '../queueRunner';

describe('queueRunner', () => {
Expand All @@ -28,6 +26,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(fnTwo).toHaveBeenCalled();
Expand All @@ -51,6 +50,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(fail).toHaveBeenCalled();
Expand Down Expand Up @@ -79,6 +79,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(onException).toHaveBeenCalledWith(error);
Expand All @@ -87,7 +88,7 @@ describe('queueRunner', () => {
});

it('passes an error to `onException` on timeout.', async () => {
const fnOne = jest.fn(next => {});
const fnOne = jest.fn(_next => {});
const fnTwo = jest.fn(next => next());
const onException = jest.fn();
const options = {
Expand All @@ -106,6 +107,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(onException).toHaveBeenCalled();
Expand All @@ -125,6 +127,7 @@ describe('queueRunner', () => {
queueableFns: [{fn: failFn}],
setTimeout,
};
// @ts-ignore
await queueRunner(options);

expect(options.fail).toHaveBeenCalledWith('miserably', 'failed');
Expand All @@ -149,6 +152,7 @@ describe('queueRunner', () => {
],
setTimeout,
};
// @ts-ignore
await queueRunner(options);
expect(fnOne).toHaveBeenCalled();
expect(fail).toHaveBeenCalledWith(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,33 @@
*
*/

'use strict';

import JasmineReporter from '../reporter';
import {SuiteResult} from '../jasmine/Suite';
import {SpecResult} from '../jasmine/Spec';

describe('Jasmine2Reporter', () => {
let reporter;
let reporter: JasmineReporter;

beforeEach(() => {
// @ts-ignore
reporter = new JasmineReporter({});
});

it('reports nested suites', () => {
const makeSpec = name => ({
description: 'description',
failedExpectations: [],
fullName: name,
});
reporter.suiteStarted({description: 'parent'});
reporter.suiteStarted({description: 'child'});
const makeSpec = (name: string) =>
({
description: 'description',
failedExpectations: [],
fullName: name,
} as SpecResult);
reporter.suiteStarted({description: 'parent'} as SuiteResult);
reporter.suiteStarted({description: 'child'} as SuiteResult);
reporter.specDone(makeSpec('spec 1'));
// @ts-ignore
reporter.suiteDone();
reporter.suiteStarted({description: 'child 2'});
reporter.suiteStarted({description: 'child 2'} as SuiteResult);
reporter.specDone(makeSpec('spec 2'));
// @ts-ignore
reporter.jasmineDone();

return reporter.getResults().then(runResults => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*
*/

'use strict';

describe('test/it.todo error throwing', () => {
it('it throws error when given no arguments', () => {
expect(() => {
// @ts-ignore
it.todo();
}).toThrowError('Todo must be called with only a description.');
});
Expand All @@ -21,6 +20,7 @@ describe('test/it.todo error throwing', () => {
});
it('it throws error when given none string description', () => {
expect(() => {
// @ts-ignore
it.todo(() => {});
}).toThrowError('Todo must be called with only a description.');
});
Expand Down
Loading