Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Sep 24, 2023
1 parent 5d89923 commit a1ce469
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, Depende
% @types/node in the root need to stay on ~14.14.45
'@types/node',
% upgrading the entire repository is a breaking change
'glob'
'glob',
% repository and snapshot
'prettier'
]).

% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"jest-message-util": "workspace:*",
"jest-util": "workspace:*",
"natural-compare": "^1.4.0",
"pretty-format": "workspace:^",
"pretty-format": "workspace:*",
"semver": "^7.5.3",
"synckit": "^0.8.5"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export const processInlineSnapshotsWithBabel = (

export const processPrettierAst = (
ast: File,
options: Record<string, any>,
options: Record<string, any> | null,
snapshotMatcherNames: Array<string>,
keepNode?: boolean,
): void => {
Expand Down Expand Up @@ -463,16 +463,16 @@ export const processPrettierAst = (
? parent.loc.start.column
: callee.loc.start.column;

const useSpaces = !options.useTabs;
const useSpaces = !options?.useTabs;
snapshot = indent(
snapshot,
Math.ceil(
useSpaces
? startColumn / (options.tabWidth ?? 1)
? startColumn / (options?.tabWidth ?? 1)
: // Each tab is 2 characters.
startColumn / 2,
),
useSpaces ? ' '.repeat(options.tabWidth ?? 1) : '\t',
useSpaces ? ' '.repeat(options?.tabWidth ?? 1) : '\t',
);

if (keepNode) {
Expand Down
9 changes: 8 additions & 1 deletion packages/jest-snapshot/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {runAsWorker} from 'synckit';
import {processPrettierAst} from './utils';

Expand Down Expand Up @@ -38,7 +45,7 @@ runAsWorker(
originalText: sourceFileWithSnapshots,
parser: inferredParser,
});
processPrettierAst(ast, config!, snapshotMatcherNames, true);
processPrettierAst(ast, config, snapshotMatcherNames, true);
// Snapshots have now been inserted. Run prettier to make sure that the code is
// formatted, except snapshot indentation. Snapshots cannot be formatted until
// after the initial format because we don't know where the call expression
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13094,7 +13094,7 @@ __metadata:
natural-compare: ^1.4.0
prettier: ^3.0.3
prettier-v2: "npm:prettier@^2.1.5"
pretty-format: "workspace:^"
pretty-format: "workspace:*"
semver: ^7.5.3
synckit: ^0.8.5
tsd-lite: ^0.8.0
Expand Down Expand Up @@ -17346,7 +17346,7 @@ __metadata:
languageName: node
linkType: hard

"pretty-format@workspace:*, pretty-format@workspace:^, pretty-format@workspace:packages/pretty-format":
"pretty-format@workspace:*, pretty-format@workspace:packages/pretty-format":
version: 0.0.0-use.local
resolution: "pretty-format@workspace:packages/pretty-format"
dependencies:
Expand Down

0 comments on commit a1ce469

Please sign in to comment.