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 snapshot - TS migration #7899

Merged
merged 37 commits into from Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0ecbf42
WIP - migration to ts (part 1)
doniyor2109 Feb 14, 2019
7a181dc
Remove old snapshots
doniyor2109 Feb 14, 2019
60c07cd
Merge remote-tracking branch 'jest/master' into jest-snapshot/ts_migr…
doniyor2109 Feb 14, 2019
f12de38
Use MatcherState type from expect (not implemented yet)
doniyor2109 Feb 14, 2019
1c70f23
Handle when line and column are zero
doniyor2109 Feb 14, 2019
934b93c
Remove extra exports
doniyor2109 Feb 14, 2019
b94d602
Minor tweaks
doniyor2109 Feb 15, 2019
7dc5065
Small tweaks
SimenB Feb 15, 2019
b6522be
Small tweaks
doniyor2109 Feb 15, 2019
27837ec
Revert underscores
doniyor2109 Feb 15, 2019
c7991d8
Private methods
doniyor2109 Feb 15, 2019
6cd97aa
Minor tweaks
doniyor2109 Feb 15, 2019
cdb6096
Meaningful name
SimenB Feb 15, 2019
5706125
Remove extra ts-ignore
doniyor2109 Feb 15, 2019
835974d
Small change
SimenB Feb 15, 2019
e6b14dc
Migrate tests to es modules
doniyor2109 Feb 15, 2019
d0f3789
Small tweak
doniyor2109 Feb 15, 2019
81cec4a
Eslint fixes
doniyor2109 Feb 15, 2019
9c16d91
Fix `import =` is not supported in test
doniyor2109 Feb 15, 2019
36d32f3
Remove extra dep
doniyor2109 Feb 15, 2019
1fb3194
Add Frame type to jest-message-util
doniyor2109 Feb 15, 2019
84ae5ca
Minor tweaks
doniyor2109 Feb 15, 2019
4a14bc4
Better types
SimenB Feb 15, 2019
caf2268
Minor tweaks
doniyor2109 Feb 15, 2019
1202434
Fix Frame types in tests
doniyor2109 Feb 15, 2019
cc59272
Resolve unused vars
doniyor2109 Feb 15, 2019
3c906c3
es imports
doniyor2109 Feb 15, 2019
9bd4eb0
Added package.json types
doniyor2109 Feb 16, 2019
3de88c4
Added @types/natural-comapre
doniyor2109 Feb 16, 2019
bb89663
Merge branch 'master' into jest-snapshot/ts_migration
SimenB Feb 16, 2019
186194e
fix type import
SimenB Feb 16, 2019
9288a1d
remove unused eslint supression comment
SimenB Feb 16, 2019
19aa286
chore: add missing copyright header
SimenB Feb 16, 2019
d9e9314
tweak some types
SimenB Feb 16, 2019
7590af9
explicit export
SimenB Feb 16, 2019
b915c81
changelog
SimenB Feb 16, 2019
2a8795e
prettify tsconfig
SimenB Feb 16, 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
1 change: 1 addition & 0 deletions packages/jest-snapshot/src/State.ts
Expand Up @@ -39,6 +39,7 @@ export type SnapshotMatchOptions = {
export default class SnapshotState {
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
private _counters: Map<string, number>;
private _dirty: boolean;
// @ts-ignore
private _index: number;
private _updateSnapshot: Config.SnapshotUpdateState;
private _snapshotData: SnapshotData;
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-snapshot/src/mock_serializer.ts
Expand Up @@ -7,15 +7,15 @@
*
*/

import {Config, NewPlugin, Printer, Refs} from 'pretty-format';
import {PrettyFormat} from '@jest/types';

export const serialize = (
val: any,
config: Config,
config: PrettyFormat.Config,
indentation: string,
depth: number,
refs: Refs,
printer: Printer,
refs: PrettyFormat.Refs,
printer: PrettyFormat.Printer,
): string => {
// Serialize a non-default name, even if config.printFunctionName is false.
const name = val.getMockName();
Expand Down Expand Up @@ -46,6 +46,6 @@ export const serialize = (

export const test = (val: any) => val && !!val._isMockFunction;

const plugin: NewPlugin = {serialize, test};
const plugin: PrettyFormat.NewPlugin = {serialize, test};

export default plugin;
8 changes: 5 additions & 3 deletions packages/jest-snapshot/src/plugins.ts
Expand Up @@ -7,7 +7,9 @@
*
*/

import prettyFormat, {Plugin} from 'pretty-format';
import prettyFormat from 'pretty-format';
import {PrettyFormat} from '@jest/types';

import jestMockSerializer from './mock_serializer';

const {
Expand All @@ -19,7 +21,7 @@ const {
AsymmetricMatcher,
} = prettyFormat.plugins;

let PLUGINS: Array<Plugin> = [
let PLUGINS: Array<PrettyFormat.Plugin> = [
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
ReactTestComponent,
ReactElement,
DOMElement,
Expand All @@ -30,7 +32,7 @@ let PLUGINS: Array<Plugin> = [
];

// Prepend to list so the last added is the first tested.
export const addSerializer = (plugin: Plugin) => {
export const addSerializer = (plugin: PrettyFormat.Plugin) => {
PLUGINS = [plugin].concat(PLUGINS);
};

Expand Down
117 changes: 117 additions & 0 deletions packages/jest-types/src/PrettyFormat.ts
@@ -0,0 +1,117 @@
/**
* 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.
*/

export type Colors = {
comment: {close: string; open: string};
content: {close: string; open: string};
prop: {close: string; open: string};
tag: {close: string; open: string};
value: {close: string; open: string};
};
type Indent = (arg0: string) => string;
export type Refs = Array<any>;
type Print = (arg0: any) => string;

export type Theme = {
comment: string;
content: string;
prop: string;
tag: string;
value: string;
};

type ThemeReceived = {
comment?: string;
content?: string;
prop?: string;
tag?: string;
value?: string;
};

export type Options = {
callToJSON: boolean;
escapeRegex: boolean;
escapeString: boolean;
highlight: boolean;
indent: number;
maxDepth: number;
min: boolean;
plugins: Plugins;
printFunctionName: boolean;
theme: Theme;
};

export type OptionsReceived = {
callToJSON?: boolean;
escapeRegex?: boolean;
escapeString?: boolean;
highlight?: boolean;
indent?: number;
maxDepth?: number;
min?: boolean;
plugins?: Plugins;
printFunctionName?: boolean;
theme?: ThemeReceived;
};

export type Config = {
callToJSON: boolean;
colors: Colors;
escapeRegex: boolean;
escapeString: boolean;
indent: string;
maxDepth: number;
min: boolean;
plugins: Plugins;
printFunctionName: boolean;
spacingInner: string;
spacingOuter: string;
};

export type Printer = (
val: any,
config: Config,
indentation: string,
depth: number,
refs: Refs,
hasCalledToJSON?: boolean,
) => string;

type Test = (arg0: any) => boolean;

export type NewPlugin = {
serialize: (
val: any,
config: Config,
indentation: string,
depth: number,
refs: Refs,
printer: Printer,
) => string;
test: Test;
};

type PluginOptions = {
edgeSpacing: string;
min: boolean;
spacing: string;
};

type OldPlugin = {
print: (
val: any,
print: Print,
indent: Indent,
options: PluginOptions,
colors: Colors,
) => string;
test: Test;
};

export type Plugin = NewPlugin | OldPlugin;

export type Plugins = Array<Plugin>;
11 changes: 10 additions & 1 deletion packages/jest-types/src/index.ts
Expand Up @@ -11,5 +11,14 @@ import * as SourceMaps from './SourceMaps';
import * as TestResult from './TestResult';
import * as Mocks from './Mocks';
import * as Transform from './Transform';
import * as PrettyFormat from './PrettyFormat';

export {Config, Console, SourceMaps, TestResult, Mocks, Transform};
export {
Config,
Console,
SourceMaps,
TestResult,
Mocks,
Transform,
PrettyFormat,
};
1 change: 1 addition & 0 deletions packages/pretty-format/package.json
Expand Up @@ -21,6 +21,7 @@
"@types/ansi-styles": "^3.2.1",
"@types/react": "*",
"@types/react-test-renderer": "*",
"@jest/types": "^24.1.0",
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
"immutable": "4.0.0-rc.9",
"react": "*",
"react-dom": "*",
Expand Down
4 changes: 1 addition & 3 deletions packages/pretty-format/src/index.ts
Expand Up @@ -18,8 +18,6 @@ import {
Theme,
} from './types';

export * from './types';

import {
printIteratorEntries,
printIteratorValues,
Expand Down Expand Up @@ -522,4 +520,4 @@ prettyFormat.plugins = {
ReactTestComponent,
};

export default prettyFormat;
export = prettyFormat;
111 changes: 2 additions & 109 deletions packages/pretty-format/src/types.ts
Expand Up @@ -5,113 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

export type Colors = {
comment: {close: string; open: string};
content: {close: string; open: string};
prop: {close: string; open: string};
tag: {close: string; open: string};
value: {close: string; open: string};
};
type Indent = (arg0: string) => string;
export type Refs = Array<any>;
type Print = (arg0: any) => string;
import {PrettyFormat} from '@jest/types';

export type Theme = {
comment: string;
content: string;
prop: string;
tag: string;
value: string;
};

type ThemeReceived = {
comment?: string;
content?: string;
prop?: string;
tag?: string;
value?: string;
};

export type Options = {
callToJSON: boolean;
escapeRegex: boolean;
escapeString: boolean;
highlight: boolean;
indent: number;
maxDepth: number;
min: boolean;
plugins: Plugins;
printFunctionName: boolean;
theme: Theme;
};

export type OptionsReceived = {
callToJSON?: boolean;
escapeRegex?: boolean;
escapeString?: boolean;
highlight?: boolean;
indent?: number;
maxDepth?: number;
min?: boolean;
plugins?: Plugins;
printFunctionName?: boolean;
theme?: ThemeReceived;
};

export type Config = {
callToJSON: boolean;
colors: Colors;
escapeRegex: boolean;
escapeString: boolean;
indent: string;
maxDepth: number;
min: boolean;
plugins: Plugins;
printFunctionName: boolean;
spacingInner: string;
spacingOuter: string;
};

export type Printer = (
val: any,
config: Config,
indentation: string,
depth: number,
refs: Refs,
hasCalledToJSON?: boolean,
) => string;

type Test = (arg0: any) => boolean;

export type NewPlugin = {
serialize: (
val: any,
config: Config,
indentation: string,
depth: number,
refs: Refs,
printer: Printer,
) => string;
test: Test;
};

type PluginOptions = {
edgeSpacing: string;
min: boolean;
spacing: string;
};

type OldPlugin = {
print: (
val: any,
print: Print,
indent: Indent,
options: PluginOptions,
colors: Colors,
) => string;
test: Test;
};

export type Plugin = NewPlugin | OldPlugin;

export type Plugins = Array<Plugin>;
export = PrettyFormat;
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions packages/pretty-format/tsconfig.json
Expand Up @@ -3,5 +3,9 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
},
"references": [{
"path": "../jest-types"
}
]
SimenB marked this conversation as resolved.
Show resolved Hide resolved
}