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

chore:add typecheck for tests of jest-snapshot #13408

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion package.json
Expand Up @@ -113,7 +113,7 @@
"test": "yarn lint && yarn jest",
"typecheck": "yarn typecheck:examples && yarn typecheck:tests",
"typecheck:examples": "tsc -p examples/angular --noEmit && tsc -p examples/expect-extend --noEmit && tsc -p examples/typescript --noEmit",
"typecheck:tests": "tsc -b packages/{babel-jest,babel-plugin-jest-hoist,diff-sequences,expect,expect-utils,jest-circus,jest-cli,jest-config,jest-console}/src/{__tests__,init/__tests__}",
"typecheck:tests": "tsc -b packages/{babel-jest,babel-plugin-jest-hoist,diff-sequences,expect,expect-utils,jest-circus,jest-cli,jest-config,jest-console,jest-snapshot}/src/{__tests__,init/__tests__}",
"verify-old-ts": "node ./scripts/verifyOldTs.mjs",
"verify-pnp": "node ./scripts/verifyPnP.mjs",
"watch": "yarn build:js && node ./scripts/watch.mjs",
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts
Expand Up @@ -19,7 +19,9 @@ jest.mock('prettier', () => {
format: (text, opts) =>
realPrettier.format(text, {
pluginSearchDirs: [
require('path').dirname(require.resolve('prettier')),
(require('path') as typeof import('path')).dirname(
require.resolve('prettier'),
),
],
...opts,
}),
Expand Down
10 changes: 6 additions & 4 deletions packages/jest-snapshot/src/__tests__/dedentLines.test.ts
Expand Up @@ -11,12 +11,14 @@ import {dedentLines} from '../dedentLines';
const $$typeof = Symbol.for('react.test.json');
const plugins = [builtinPlugins.ReactTestComponent];

const formatLines2 = val => format(val, {indent: 2, plugins}).split('\n');
const formatLines0 = val => format(val, {indent: 0, plugins}).split('\n');
const formatLines2 = (val: unknown) =>
format(val, {indent: 2, plugins}).split('\n');
const formatLines0 = (val: unknown) =>
format(val, {indent: 0, plugins}).split('\n');

describe('dedentLines non-null', () => {
test('no lines', () => {
const indented = [];
const indented: Array<string> = [];
const dedented = indented;

expect(dedentLines(indented)).toEqual(dedented);
Expand Down Expand Up @@ -129,7 +131,7 @@ describe('dedentLines null', () => {
['object key multi-line', {'multi\nline\nkey': false}],
['object value multi-line', {key: 'multi\nline\nvalue'}],
['object key and value multi-line', {'multi\nline': '\nleading nl'}],
])('%s', (name, val) => {
])('%s', (_name, val) => {
expect(dedentLines(formatLines2(val))).toBeNull();
});

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-snapshot/src/__tests__/mockSerializer.test.ts
Expand Up @@ -85,7 +85,7 @@ test('mock with 2 calls', () => {
});

test('indent option', () => {
const fn = jest.fn(val => val);
const fn = jest.fn((val: {key: string}) => val);
fn({key: 'value'});
const expected = [
'[MockFunction] {',
Expand All @@ -110,7 +110,7 @@ test('indent option', () => {
});

test('min option', () => {
const fn = jest.fn(val => val);
const fn = jest.fn((val: {key: string}) => val);
fn({key: 'value'});
const expected =
'[MockFunction] {"calls": [[{"key": "value"}]], "results": [{"type": "return", "value": {"key": "value"}}]}';
Expand Down
15 changes: 10 additions & 5 deletions packages/jest-snapshot/src/__tests__/plugins.test.ts
Expand Up @@ -5,13 +5,18 @@
* LICENSE file in the root directory of this source tree.
*/

beforeEach(() => jest.resetModules());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went on fixing tests of this package because of this line. Not sure if it works currently.

import type {Plugin} from 'pretty-format';

beforeEach(() => {
jest.resetModules();
});

const testPath = (names: Array<string>) => {
const {addSerializer, getSerializers} = require('../plugins');
const {addSerializer, getSerializers} =
require('../plugins') as typeof import('../plugins');
const prev = getSerializers();
const added = names.map(name =>
require(require.resolve(`./plugins/${name}`)),
const added = names.map(
name => require(require.resolve(`./plugins/${name}`)) as Plugin,
);

// Jest tests snapshotSerializers in order preceding built-in serializers.
Expand All @@ -27,7 +32,7 @@ const testPath = (names: Array<string>) => {
};

it('gets plugins', () => {
const {getSerializers} = require('../plugins');
const {getSerializers} = require('../plugins') as typeof import('../plugins');
const plugins = getSerializers();
expect(plugins).toHaveLength(5);
});
Expand Down