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 56 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ module.exports = {
'import/no-extraneous-dependencies': 0,
},
},
{
files: ['test-types/*.test.ts'],
rules: {
'jest/no-focused-tests': 0,
'jest/no-identical-title': 0,
'jest/valid-expect': 0,
},
},
],
parser: 'babel-eslint',
plugins: ['markdown', 'import', 'prettier', 'eslint-comments'],
Expand All @@ -128,6 +136,7 @@ module.exports = {
2,
{
devDependencies: [
'/test-types/**',
'**/__tests__/**',
'**/__mocks__/**',
'**/?(*.)(spec|test).js?(x)',
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
run: yarn
- name: build
run: yarn build
- name: test typings
run: yarn test-types
- name: verify TypeScript@3.8 compatibility
run: yarn verify-old-ts
- name: run eslint
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
],
testEnvironment: './packages/jest-environment-node',
testPathIgnorePatterns: [
'/test-types/',
'/__arbitraries__/',
'/node_modules/',
'/examples/',
Expand Down
35 changes: 35 additions & 0 deletions jest.config.types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* 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';

const assert = require('assert');
const baseConfig = require('./jest.config');

const {
modulePathIgnorePatterns,
testPathIgnorePatterns,
watchPathIgnorePatterns,
} = baseConfig;

assert.strictEqual(
testPathIgnorePatterns[0],
'/test-types/',
'First entry must be types',
);

module.exports = {
displayName: {
color: 'blue',
name: 'types',
},
modulePathIgnorePatterns,
runner: 'jest-runner-tsd',
testMatch: ['<rootDir>/test-types/*.test.ts'],
testPathIgnorePatterns: testPathIgnorePatterns.slice(1),
watchPathIgnorePatterns,
};
SimenB marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@
"istanbul-reports": "^3.0.0",
"jest": "workspace:packages/jest",
"jest-junit": "^11.0.1",
"jest-runner-tsd": "^1.1.0",
"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 Expand Up @@ -90,6 +92,7 @@
"lint:prettier": "prettier '**/*.{md,yml,yaml}' 'website/static/**/*.{css,js}' --write --ignore-path .gitignore",
"lint:prettier:ci": "prettier '**/*.{md,yml,yaml}' 'website/static/**/*.{css,js}' --check --ignore-path .gitignore",
"publish": "yarn build-clean && yarn build && lerna publish --silent",
"test-types": "yarn jest --config jest.config.types.js",
"test-ci": "yarn jest-coverage --color -i --config jest.config.ci.js && yarn test-leak && node ./scripts/mapCoverage.js && codecov",
"test-ci-partial": "yarn jest --color -i --config jest.config.ci.js",
"test-pretty-format-perf": "node packages/pretty-format/perf/test.js",
Expand Down
9 changes: 9 additions & 0 deletions test-types/empty.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* 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
* @see https://github.com/MLH-Fellowship/jest-runner-tsd/blob/e25720040939fc79ab38d73c1495be90d5b92566/README.md#for-typescript-projects
*/
81 changes: 81 additions & 0 deletions test-types/top-level-jest-namespace.test.ts
Original file line number Diff line number Diff line change
@@ -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'));
Loading