Skip to content

Commit

Permalink
Add config for printFunctionName
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavovnicius committed Jul 10, 2019
1 parent a501718 commit e6b66e0
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 4 deletions.
Expand Up @@ -128,6 +128,7 @@ export const initialize = ({
expand,
getBabelTraverse,
getPrettier,
printFunctionName: config.printFunctionName,
updateSnapshot,
});
setState({snapshotState, testPath});
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.ts
Expand Up @@ -186,6 +186,7 @@ const groupOptions = (
modulePaths: options.modulePaths,
name: options.name,
prettierPath: options.prettierPath,
printFunctionName: options.printFunctionName,
resetMocks: options.resetMocks,
resetModules: options.resetModules,
resolver: options.resolver,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/src/setup_jest_globals.ts
Expand Up @@ -108,6 +108,7 @@ export default ({
getBabelTraverse: () => require('@babel/traverse').default,
getPrettier: () =>
config.prettierPath ? require(config.prettierPath) : null,
printFunctionName: config.printFunctionName,
updateSnapshot,
});
setState({snapshotState, testPath});
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-snapshot/src/State.ts
Expand Up @@ -25,6 +25,7 @@ export type SnapshotStateOptions = {
getPrettier: () => null | any;
getBabelTraverse: () => Function;
expand?: boolean;
printFunctionName: boolean;
};

export type SnapshotMatchOptions = {
Expand All @@ -48,6 +49,7 @@ export default class SnapshotState {
private _uncheckedKeys: Set<string>;
private _getBabelTraverse: () => Function;
private _getPrettier: () => null | any;
private _printFunctionName: boolean;

added: number;
expand: boolean;
Expand Down Expand Up @@ -76,6 +78,7 @@ export default class SnapshotState {
this.unmatched = 0;
this._updateSnapshot = options.updateSnapshot;
this.updated = 0;
this._printFunctionName = options.printFunctionName;
}

markSnapshotsAsCheckedForTest(testName: string) {
Expand Down Expand Up @@ -189,7 +192,7 @@ export default class SnapshotState {
this._uncheckedKeys.delete(key);
}

const receivedSerialized = serialize(received);
const receivedSerialized = serialize(received, this._printFunctionName);
const expected = isInline ? inlineSnapshot : this._snapshotData[key];
const pass = expected === receivedSerialized;
const hasSnapshot = isInline
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-snapshot/src/utils.ts
Expand Up @@ -128,13 +128,13 @@ export const getSnapshotData = (
const addExtraLineBreaks = (string: string): string =>
string.includes('\n') ? `\n${string}\n` : string;

export const serialize = (data: string): string =>
export const serialize = (data: string, printFunctionName: any): string =>
addExtraLineBreaks(
normalizeNewlines(
prettyFormat(data, {
escapeRegex: true,
plugins: getSerializers(),
printFunctionName: false,
printFunctionName,
}),
),
);
Expand Down
1 change: 1 addition & 0 deletions packages/jest-types/src/Config.ts
Expand Up @@ -418,6 +418,7 @@ export type ProjectConfig = {
transformIgnorePatterns: Array<Glob>;
watchPathIgnorePatterns: Array<string>;
unmockedModulePathPatterns: Array<string> | null | undefined;
printFunctionName: boolean;
};

export type Argv = Arguments<
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-validate/src/__tests__/fixtures/jestConfig.js
Expand Up @@ -42,6 +42,7 @@ const defaultConfig = {
notifyMode: 'failure-change',
preset: null,
prettierPath: 'prettier',
printFunctionName: false,
resetMocks: false,
resetModules: false,
restoreMocks: false,
Expand Down Expand Up @@ -131,7 +132,7 @@ const validConfig = {
watchman: true,
};

const format = (value: string) => require('pretty-format')(value, {min: true});
const format = (value: string) => require('pretty-format')(value, { min: true });

const deprecatedConfig = {
preprocessorIgnorePatterns: (config: Object) =>
Expand Down

0 comments on commit e6b66e0

Please sign in to comment.