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

Conversation

SaurabhAgarwala
Copy link
Contributor

@SaurabhAgarwala SaurabhAgarwala commented Aug 14, 2020

Summary

Related to #8794

This PR adds type definitions tests for Jest's own API. The types are imported from @jest/types and @jest/globals. The tests for foo are defined in a file call foo.test.ts present in the test-types directory under the root directory.

A custom runner called jest-runner-tsd is being used for the type definition tests.

Under the hood, a forked version of tsd is being used for carrying out the tests.

This PR implements the type testing feature. More type tests for other Jest APIs will be added as a separate PR.

Demo

JestDemo

The above screenshot demonstrate the working of both the failing as well as passing type tests for a few API of the top-level-jest-namespace. The failing tests are just for demo purpose and will be deleted once the PR is approved.

Authors

@SimenB
Copy link
Member

SimenB commented Aug 19, 2020

We only emit the TS types for the Running TypeScript compiler & ESLint workflow, so I believe we need to only run the type tests in that workflow as well. A separate config file might be what we wanna do rather than using projects here.

// jest.config.types.js

/**
 * 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';

module.exports = {
  displayName: 'typings test',
  runner: 'jest-runner-tsd',
  testMatch: ['<rootDir>/test-types/*.test.ts'],
};

then add a script for running it

{
  "scripts": {
    "test-types": "yarn jest --config jest.config.types.js"
  }
}

and finally in the workflow after this: https://github.com/facebook/jest/blob/c9c8dba4dd8de34269bdb971173659399bcbfd55/.github/workflows/nodejs.yml#L40-L41

jest.config.js Outdated
'<rootDir>',
'<rootDir>/examples/*/',
{
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',
},

package.json Outdated Show resolved Hide resolved
jest.config.js Outdated Show resolved Hide resolved
.eslintrc.js Outdated Show resolved Hide resolved
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

👏

Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants