From dcf1346a8bfd609ec495d63be1850200eb9e7e43 Mon Sep 17 00:00:00 2001 From: pacexy Date: Wed, 17 May 2023 16:33:25 +0800 Subject: [PATCH] fix: `toMatchInlineSnapshot` fails when file path includes parentheses (fix #3370) (#3371) --- packages/utils/src/source-map.ts | 2 +- .../test/snapshot-inline-(parentheses).test.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/core/test/snapshot-inline-(parentheses).test.ts diff --git a/packages/utils/src/source-map.ts b/packages/utils/src/source-map.ts index 69899cc00d06..7539ac09d0f0 100644 --- a/packages/utils/src/source-map.ts +++ b/packages/utils/src/source-map.ts @@ -23,7 +23,7 @@ function extractLocation(urlLike: string) { return [urlLike] const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/ - const parts = regExp.exec(urlLike.replace(/[()]/g, '')) + const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, '')) if (!parts) return [urlLike] return [parts[1], parts[2] || undefined, parts[3] || undefined] diff --git a/test/core/test/snapshot-inline-(parentheses).test.ts b/test/core/test/snapshot-inline-(parentheses).test.ts new file mode 100644 index 000000000000..5cf443ebfc41 --- /dev/null +++ b/test/core/test/snapshot-inline-(parentheses).test.ts @@ -0,0 +1,18 @@ +import { expect, test } from 'vitest' + +test('object', () => { + expect({ + foo: { + type: 'object', + map: new Map(), + }, + }) + .toMatchInlineSnapshot(` + { + "foo": { + "map": Map {}, + "type": "object", + }, + } + `) +})