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

Implement tests for type definitions in Jest #10407

Merged
merged 58 commits into from Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
083e01d
Started working on tests
smartclash Aug 6, 2020
09d8df1
Complete describe type tests
smartclash Aug 11, 2020
00024a0
Fix typings file not being resolved issue
smartclash Aug 11, 2020
9d035fb
Add it type tests
SaurabhAgarwala Aug 11, 2020
f810f60
Add lifecycle events type tests
SaurabhAgarwala Aug 11, 2020
ee5a034
Fixed it.test.ts callback based tests
smartclash Aug 11, 2020
2903bf0
Modify lifecycle events tests having callbacks
SaurabhAgarwala Aug 11, 2020
bd37c12
Fix eslint issueS
smartclash Aug 12, 2020
f6e93c3
Fix config
smartclash Aug 12, 2020
2d4aecd
Using jest's projects to incorporate typings test
smartclash Aug 12, 2020
7927d6b
Merge master
smartclash Aug 12, 2020
58f9d2a
Fix conflicts and merge master
smartclash Aug 12, 2020
8a8b3a0
Add test-types/ files to .eslintrc.js
SaurabhAgarwala Aug 13, 2020
ae0932f
Added tests for done callback types
smartclash Aug 13, 2020
5c30a6c
Add tests for done callback types
smartclash Aug 13, 2020
baaa5b3
Add type tests for top-level-jest-namespace APIs
SaurabhAgarwala Aug 13, 2020
06bb37f
Upgrade @types/jest and fix top-level-jest-namespace type tests
SaurabhAgarwala Aug 13, 2020
73fd3c5
Upgrade jest types to ^26.0
smartclash Aug 13, 2020
25abba7
Finish half of basic-matchers types test
smartclash Aug 13, 2020
68d4d1d
Merge branch 'tests/types' of github.com:MLH-Fellowship/jest into tes…
smartclash Aug 13, 2020
955faa1
Next batch of tests
smartclash Aug 13, 2020
f1097eb
Next batch of tests
smartclash Aug 13, 2020
49730e4
Completed basic-matchers types test except two for two types
smartclash Aug 13, 2020
fddc123
Make tests pass
smartclash Aug 13, 2020
71e943b
Remove unsused import
smartclash Aug 13, 2020
85a0c09
Revert "Upgrade jest types to ^26.0"
smartclash Aug 13, 2020
6e4af8d
First batch of changes
smartclash Aug 14, 2020
1f8ccc3
Second batch of changes
smartclash Aug 14, 2020
7545656
Third batch of changes
smartclash Aug 14, 2020
984415b
Completed migrating types in basic-matchers test file
smartclash Aug 14, 2020
557977e
Finished done-callback
smartclash Aug 14, 2020
c306c92
Finished describe
smartclash Aug 14, 2020
12a8925
Create new test file test.test.ts (LOL)
smartclash Aug 14, 2020
5dbb7b0
Finish up it.test.ts
smartclash Aug 14, 2020
b254e34
Upgrade top-level-jest-namespace
smartclash Aug 14, 2020
881dfca
Merge branch 'master' into tests/types
smartclash Aug 14, 2020
c41d028
Use published packages
smartclash Aug 17, 2020
f5f41ff
Fix config and fix dependencies
smartclash Aug 17, 2020
871a037
Fixing stuffs according to review
smartclash Aug 17, 2020
93a0750
Remove type tests for jasmine
smartclash Aug 17, 2020
a79b2fd
Deleted other tests
smartclash Aug 18, 2020
bb82d1f
Made basic-matchers.test.ts pass as many tests as possible
smartclash Aug 18, 2020
b2ea8b6
Make the PR checks pass
smartclash Aug 18, 2020
a44245b
Add top-level-jest-namespace.test.ts
smartclash Aug 18, 2020
b109287
Add demonstration tests
SaurabhAgarwala Aug 18, 2020
5926b8e
Extraneous dependencies fix
smartclash Aug 18, 2020
3c4372a
Remove basic-matchers.test.ts
smartclash Aug 19, 2020
687385d
Update jest-runner-tsd
smartclash Aug 19, 2020
bf290cd
Move jest-runner-tsd into dev Dep
smartclash Aug 19, 2020
51e74fd
Specify the reason behind having empty.d.ts
smartclash Aug 19, 2020
be9ae43
Seperate config file for testing types
smartclash Aug 19, 2020
73f9a31
Add new rule to GH workflow
smartclash Aug 19, 2020
a642888
Removed projects
smartclash Aug 19, 2020
08b54b7
Removed demo failing test
smartclash Aug 19, 2020
f6dc7b5
Remove warnings
smartclash Aug 19, 2020
fa97a05
Update .eslintrc.js
SaurabhAgarwala Aug 19, 2020
2c3f3a3
Add more tests
smartclash Aug 19, 2020
0bc621a
Merge branch 'tests/types' of github.com:MLH-Fellowship/jest into tes…
smartclash Aug 19, 2020
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
12 changes: 12 additions & 0 deletions .eslintrc.js
Expand Up @@ -114,6 +114,17 @@ module.exports = {
'import/no-extraneous-dependencies': 0,
},
},
{
files: ['test-types/*.test.ts'],
rules: {
'@typescript-eslint/array-type': 0,
'eslint-comments/disable-enable-pair': 0,
'jest/no-focused-tests': 0,
'jest/no-identical-title': 0,
'jest/valid-expect': 0,
'sort-keys': 0,
SaurabhAgarwala marked this conversation as resolved.
Show resolved Hide resolved
},
},
],
parser: 'babel-eslint',
plugins: ['markdown', 'import', 'prettier', 'eslint-comments'],
Expand All @@ -128,6 +139,7 @@ module.exports = {
2,
{
devDependencies: [
'/test-types/**',
'**/__tests__/**',
'**/__mocks__/**',
'**/?(*.)(spec|test).js?(x)',
Expand Down
11 changes: 10 additions & 1 deletion jest.config.js
Expand Up @@ -27,14 +27,23 @@ module.exports = {
'website/.*',
'e2e/runtime-internal-module-registry/__mocks__',
],
projects: ['<rootDir>', '<rootDir>/examples/*/'],
projects: [
'<rootDir>',
'<rootDir>/examples/*/',
{
SimenB marked this conversation as resolved.
Show resolved Hide resolved
displayName: 'typings test',
Copy link
Member

@SimenB SimenB Aug 19, 2020

Choose a reason for hiding this comment

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

can we do something like this to make it be more "typescript color" than green?

Suggested change
displayName: 'typings test',
displayName: {
color: 'blue',
name: 'types',
},

runner: 'jest-runner-tsd',
testMatch: ['<rootDir>/test-types/*.test.ts'],
},
],
setupFilesAfterEnv: ['<rootDir>/testSetupFile.js'],
snapshotSerializers: [
'<rootDir>/packages/pretty-format/build/plugins/ConvertAnsi.js',
SaurabhAgarwala marked this conversation as resolved.
Show resolved Hide resolved
require.resolve('jest-snapshot-serializer-raw'),
],
testEnvironment: './packages/jest-environment-node',
testPathIgnorePatterns: [
'/test-types/',
'/__arbitraries__/',
'/node_modules/',
'/examples/',
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -55,12 +55,14 @@
"istanbul-reports": "^3.0.0",
"jest": "workspace:packages/jest",
"jest-junit": "^11.0.1",
"jest-runner-tsd": "^1.0.1",
"jest-silent-reporter": "^0.2.1",
"jest-snapshot-serializer-raw": "^1.1.0",
"jest-watch-typeahead": "^0.6.0",
"jquery": "^3.2.1",
"lerna": "^3.20.2",
"micromatch": "^4.0.2",
"mlh-tsd": "^0.14.1",
"mock-fs": "^4.4.1",
"prettier": "^2.0.1",
"progress": "^2.0.0",
Expand Down
8 changes: 8 additions & 0 deletions test-types/empty.d.ts
@@ -0,0 +1,8 @@
/**
* 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.
*
* This has to be a empty file
SimenB marked this conversation as resolved.
Show resolved Hide resolved
*/
22 changes: 22 additions & 0 deletions test-types/failing.test.ts
@@ -0,0 +1,22 @@
/**
* 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.
*
* @type ./empty.d.ts
*/

import {expectType} from 'mlh-tsd';
//eslint-disable-next-line import/no-extraneous-dependencies
import {jest} from '@jest/globals';

// DEMO: The following three tests should fail
expectType<string>(jest.addMatchers({}));
expectType<void>(jest.autoMockOff());
expectType<void>(jest.autoMockOn());

// DEMO: The following three tests should pass
expectType<typeof jest>(jest.clearAllMocks());
expectType<void>(jest.clearAllTimers());
expectType<typeof jest>(jest.resetAllMocks());
81 changes: 81 additions & 0 deletions test-types/top-level-jest-namespace.test.ts
@@ -0,0 +1,81 @@
/**
* 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.
*
* @type ./empty.d.ts
*/

import {expectError, expectType} from 'mlh-tsd';
//eslint-disable-next-line import/no-extraneous-dependencies
import {jest} from '@jest/globals';

expectType<void>(jest.addMatchers({}));
expectType<typeof jest>(jest.autoMockOff());
expectType<typeof jest>(jest.autoMockOn());
expectType<typeof jest>(jest.clearAllMocks());
expectType<void>(jest.clearAllTimers());
expectType<typeof jest>(jest.resetAllMocks());
expectType<typeof jest>(jest.restoreAllMocks());
expectType<void>(jest.clearAllTimers());
expectType<typeof jest>(jest.deepUnmock('moduleName'));
expectType<typeof jest>(jest.disableAutomock());
expectType<typeof jest>(jest.doMock('moduleName'));
expectType<typeof jest>(jest.doMock('moduleName', jest.fn()));

expectError(jest.doMock('moduleName', jest.fn(), {}));
expectError(jest.doMock('moduleName', jest.fn(), {virtual: true}));

expectType<typeof jest>(jest.dontMock('moduleName'));
expectType<typeof jest>(jest.enableAutomock());
expectType<typeof jest>(jest.mock('moduleName'));
expectType<typeof jest>(jest.mock('moduleName', jest.fn()));
expectType<typeof jest>(jest.mock('moduleName', jest.fn(), {}));
expectType<typeof jest>(jest.mock('moduleName', jest.fn(), {virtual: true}));
expectType<typeof jest>(jest.resetModuleRegistry());
expectType<typeof jest>(jest.resetModules());
expectType<typeof jest>(jest.isolateModules(() => {}));
expectType<typeof jest>(jest.retryTimes(3));

expectType<void>(jest.runAllImmediates());
expectType<void>(jest.runAllTicks());
expectType<void>(jest.runAllTimers());
expectType<void>(jest.runOnlyPendingTimers());
expectType<void>(jest.runTimersToTime(9001));
expectType<void>(jest.advanceTimersByTime(9001));

expectType<typeof jest>(jest.setMock('moduleName', {}));
expectType<typeof jest>(jest.setMock('moduleName', {}));
expectType<typeof jest>(jest.setMock('moduleName', {a: 'b'}));
expectType<typeof jest>(jest.setTimeout(9001));
expectType<typeof jest>(jest.unmock('moduleName'));
expectType<typeof jest>(jest.useFakeTimers());
expectType<typeof jest>(jest.useRealTimers());

jest.advanceTimersToNextTimer();
SimenB marked this conversation as resolved.
Show resolved Hide resolved
jest.advanceTimersToNextTimer(2);

// https://jestjs.io/docs/en/jest-object#jestusefaketimersimplementation-modern--legacy
expectType<typeof jest>(jest.useFakeTimers('modern'));
expectType<typeof jest>(jest.useFakeTimers('legacy'));

expectError(jest.useFakeTimers('foo'));

// https://jestjs.io/docs/en/jest-object#jestsetsystemtimenow-number--date
expectType<void>(jest.setSystemTime());
expectType<void>(jest.setSystemTime(0));
expectType<void>(jest.setSystemTime(new Date(0)));

expectError(jest.setSystemTime('foo'));

// https://jestjs.io/docs/en/jest-object#jestgetrealsystemtime
expectType<number>(jest.getRealSystemTime());

expectError(jest.getRealSystemTime('foo'));

// https://jestjs.io/docs/en/jest-object#jestrequireactualmodulename
expectType<unknown>(jest.requireActual('./thisReturnsTheActualModule'));

// https://jestjs.io/docs/en/jest-object#jestrequiremockmodulename
expectType<unknown>(jest.requireMock('./thisAlwaysReturnsTheMock'));