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 7 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/jest-jasmine2/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 @@ -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 {}
79 changes: 0 additions & 79 deletions packages/jest-jasmine2/src/PCancelable.js

This file was deleted.

90 changes: 90 additions & 0 deletions packages/jest-jasmine2/src/PCancelable.ts
@@ -0,0 +1,90 @@
/**
* 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.
*/

/* eslint-disable no-this-before-super, constructor-super */

class CancelError extends Error {
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
super('Promise was canceled');
this.name = 'CancelError';
}
}

// @ts-ignore
class PCancelable<T> extends Promise {
private _pending: boolean;
private _canceled: boolean;
private _cancel?: Function;
private _reject: (reason?: any) => void;
private _promise: Promise<T>;

static CancelError: CancelError;

static fn<F extends (...args: any[]) => any>(fn: F) {
return function(...args: Parameters<F>) {
return new PCancelable<ReturnType<F>>((onCancel, resolve, reject) => {
args.unshift(onCancel);
fn.apply(null, args).then(resolve, reject);
});
};
}

// @ts-ignore
constructor(executor: (onCancel, resolve, reject) => any) {
this._pending = true;
this._canceled = false;

this._promise = new Promise<T>((resolve, reject) => {
this._reject = reject;

return executor(
(fn: Function) => {
this._cancel = fn;
},
(val: unknown) => {
this._pending = false;
resolve(val);
},
(err?: any) => {
this._pending = false;
reject(err);
},
);
});
}

then(...args: Parameters<Promise<T>['then']>) {
return this._promise.then.apply(this._promise, args);
}

catch(...args: Parameters<Promise<T>['catch']>) {
return this._promise.catch.apply(this._promise, args);
}

cancel() {
if (!this._pending || this._canceled) {
return;
}

if (typeof this._cancel === 'function') {
try {
this._cancel();
} catch (err) {
this._reject(err);
}
}

this._canceled = true;
this._reject(new CancelError());
}

get canceled() {
return this._canceled;
}
}

export = PCancelable;
Expand Up @@ -6,12 +6,10 @@
*
*/

'use strict';

import Suite from '../jasmine/Suite';

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

beforeEach(() => {
suite = new Suite({
Expand Down
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

import expectationResultFactory from '../expectationResultFactory';

describe('expectationResultFactory', () => {
Expand Down
Expand Up @@ -3,12 +3,8 @@
*
* 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';

describe.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
'%s hooks error throwing',
fn => {
Expand Down
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
Expand Up @@ -6,6 +6,4 @@
*
*/

'use strict';

test('global.test', () => {});
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
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
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

jest.useFakeTimers();

import pTimeout from '../pTimeout';
Expand Down
Expand Up @@ -6,8 +6,6 @@
*
*/

'use strict';

import queueRunner from '../queueRunner';

describe('queueRunner', () => {
Expand Down Expand Up @@ -87,7 +85,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 Down
Expand Up @@ -6,19 +6,17 @@
*
*/

'use strict';

import JasmineReporter from '../reporter';

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

beforeEach(() => {
reporter = new JasmineReporter({});
});

it('reports nested suites', () => {
const makeSpec = name => ({
const makeSpec = (name: string) => ({
description: 'description',
failedExpectations: [],
fullName: name,
Expand Down
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