Skip to content

Commit 8a1a251

Browse files
remove color characters from test inline snapshots
1 parent d57af5c commit 8a1a251

File tree

2 files changed

+90
-66
lines changed

2 files changed

+90
-66
lines changed

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14711,6 +14711,37 @@ export default{
1471114711
});
1471214712
});
1471314713

14714+
function normalizeLogWithConfigDiff(log: string): string {
14715+
// If the path is long the log could be wrapped so we need to remove the potential wrapping
14716+
let normalizedLog = log.replace(/"main":\s*"/, '"main": "');
14717+
14718+
if (process.platform === "win32") {
14719+
// On windows the snapshot paths incorrectly use double slashes, such as:
14720+
// `\"main\": \"C://Users//RUNNER~1//AppData//Local//Temp//wrangler-testse63LuJ//index.js\",
14721+
// so in the `main` field we replace all possible occurrences of `//` with just `\\`
14722+
// (so that the path normalization of `normalizeString` can appropriately work)
14723+
normalizedLog = normalizedLog.replace(
14724+
/"main": "(.*?)"/,
14725+
(_, mainPath: string) => `"main": "${mainPath.replaceAll("//", "\\")}"`
14726+
);
14727+
}
14728+
14729+
normalizedLog = normalizeString(normalizedLog);
14730+
14731+
// normalizedLog = normalizedLog.replaceAll("\t", "<__TAB__>");
14732+
// normalizedLog = normalizedLog.replaceAll(" ", "<__SPACE__>");
14733+
14734+
// Let's remove the various extra characters for colors to get a more clear
14735+
normalizedLog = normalizedLog
14736+
.replaceAll("", "X")
14737+
.replaceAll(/X\[\d+(?:;\d+)?m/g, "");
14738+
14739+
// Let's also normalize Windows newlines
14740+
normalizedLog = normalizedLog.replaceAll("\r\n", "\n");
14741+
14742+
return normalizedLog;
14743+
}
14744+
1471414745
describe("config remote differences", () => {
1471514746
it("should present a diff warning to the user when there are differences between the local config (json/jsonc) and the dash config", async () => {
1471614747
writeWorkerSource();
@@ -14760,12 +14791,12 @@ export default{
1476014791
await runWrangler("deploy --x-remote-diff-check");
1476114792

1476214793
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
14763-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:[0m
14794+
"▲ [WARNING] The local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:
1476414795
1476514796
{
1476614797
vars: {
14767-
[31m- MY_VAR: \\"abc\\"[39m
14768-
[32m+ MY_VAR: 123[39m
14798+
- MY_VAR: \\"abc\\"
14799+
+ MY_VAR: 123
1476914800
}
1477014801
}
1477114802
@@ -14827,12 +14858,12 @@ export default{
1482714858
// to be able to show toml content/diffs, that combined with the fact that json(c) config files are the
1482814859
// recommended ones moving forward makes this small shortcoming of the config diffing acceptable
1482914860
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
14830-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:[0m
14861+
"▲ [WARNING] The local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:
1483114862
1483214863
{
1483314864
vars: {
14834-
[31m- MY_VAR: \\"abc\\"[39m
14835-
[32m+ MY_VAR: \\"this is a toml file\\"[39m
14865+
- MY_VAR: \\"abc\\"
14866+
+ MY_VAR: \\"this is a toml file\\"
1483614867
}
1483714868
}
1483814869
@@ -14842,27 +14873,6 @@ export default{
1484214873
"
1484314874
`);
1484414875
});
14845-
14846-
function normalizeLogWithConfigDiff(log: string): string {
14847-
// If the path is long the log could be wrapped so we need to remove the potential wrapping
14848-
let normalizedLog = log.replace(/"main":\s*"/, '"main": "');
14849-
14850-
if (process.platform === "win32") {
14851-
// On windows the snapshot paths incorrectly use double slashes, such as:
14852-
// `\"main\": \"C://Users//RUNNER~1//AppData//Local//Temp//wrangler-testse63LuJ//index.js\",
14853-
// so in the `main` field we replace all possible occurrences of `//` with just `\\`
14854-
// (so that the path normalization of `normalizeString` can appropriately work)
14855-
normalizedLog = normalizedLog.replace(
14856-
/"main": "(.*?)"/,
14857-
(_, mainPath: string) =>
14858-
`"main": "${mainPath.replaceAll("//", "\\")}"`
14859-
);
14860-
}
14861-
14862-
normalizedLog = normalizeString(normalizedLog);
14863-
14864-
return normalizedLog;
14865-
}
1486614876
});
1486714877

1486814878
describe("with strict mode enabled", () => {
@@ -14902,13 +14912,13 @@ export default{
1490214912

1490314913
await runWrangler("deploy --x-remote-diff-check --strict");
1490414914

14905-
expect(std.warn).toMatchInlineSnapshot(`
14906-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:[0m
14915+
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
14916+
"▲ [WARNING] The local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:
1490714917
1490814918
{
1490914919
observability: {
14910-
[31m- enabled: true[39m
14911-
[32m+ enabled: false[39m
14920+
- enabled: true
14921+
+ enabled: false
1491214922
}
1491314923
}
1491414924

packages/wrangler/src/__tests__/deploy/config-diffs.test.ts

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import { getRemoteConfigDiff } from "../../deploy/config-diffs";
22
import type { Config, RawConfig } from "../../config";
33

4+
function normalizeDiff(log: string): string {
5+
let normalizedLog = log;
6+
7+
// Let's remove the various extra characters for colors to get a more clear
8+
normalizedLog = normalizedLog
9+
.replaceAll("", "X")
10+
.replaceAll(/X\[\d+(?:;\d+)?m/g, "");
11+
12+
// Let's also normalize Windows newlines
13+
normalizedLog = normalizedLog.replaceAll("\r\n", "\n");
14+
15+
return normalizedLog;
16+
}
17+
418
describe("getRemoteConfigsDiff", () => {
519
it("should handle a very simple diffing scenario (no diffs, random order)", () => {
620
const { diff, nonDestructive } = getRemoteConfigDiff(
@@ -61,10 +75,10 @@ describe("getRemoteConfigsDiff", () => {
6175
);
6276

6377
assert(diff);
64-
expect(diff.toString()).toMatchInlineSnapshot(`
78+
expect(normalizeDiff(diff.toString())).toMatchInlineSnapshot(`
6579
" {
66-
[31m- compatibility_date: \\"2025-07-08\\"[39m
67-
[32m+ compatibility_date: \\"2025-07-09\\"[39m
80+
- compatibility_date: \\"2025-07-08\\"
81+
+ compatibility_date: \\"2025-07-09\\"
6882
}
6983
"
7084
`);
@@ -98,14 +112,14 @@ describe("getRemoteConfigsDiff", () => {
98112
} as unknown as Config
99113
);
100114
assert(diff);
101-
expect(diff.toString()).toMatchInlineSnapshot(`
115+
expect(normalizeDiff(diff.toString())).toMatchInlineSnapshot(`
102116
" {
103117
kv_namespaces: [
104118
...
105-
[32m+ {[39m
106-
[32m+ binding: \\"MY_KV_2\\"[39m
107-
[32m+ id: \\"my-kv-456\\"[39m
108-
[32m+ }[39m
119+
+ {
120+
+ binding: \\"MY_KV_2\\"
121+
+ id: \\"my-kv-456\\"
122+
+ }
109123
]
110124
}
111125
"
@@ -142,14 +156,14 @@ describe("getRemoteConfigsDiff", () => {
142156
} as unknown as Config
143157
);
144158
assert(diff);
145-
expect(diff.toString()).toMatchInlineSnapshot(`
159+
expect(normalizeDiff(diff.toString())).toMatchInlineSnapshot(`
146160
" {
147-
[31m- kv_namespaces: [[39m
148-
[31m- {[39m
149-
[31m- binding: \\"MY_KV\\"[39m
150-
[31m- id: \\"my-kv-123\\"[39m
151-
[31m- }[39m
152-
[31m- ][39m
161+
- kv_namespaces: [
162+
- {
163+
- binding: \\"MY_KV\\"
164+
- id: \\"my-kv-123\\"
165+
- }
166+
- ]
153167
}
154168
"
155169
`);
@@ -182,19 +196,19 @@ describe("getRemoteConfigsDiff", () => {
182196
} as unknown as Config
183197
);
184198
assert(diff);
185-
expect(diff.toString()).toMatchInlineSnapshot(`
199+
expect(normalizeDiff(diff.toString())).toMatchInlineSnapshot(`
186200
" {
187-
[31m- kv_namespaces: [[39m
188-
[31m- {[39m
189-
[31m- binding: \\"MY_KV\\"[39m
190-
[31m- id: \\"my-kv-123\\"[39m
191-
[31m- }[39m
192-
[31m- ][39m
193-
[31m- compatibility_date: \\"2025-07-08\\"[39m
194-
[32m+ compatibility_date: \\"2025-07-09\\"[39m
201+
- kv_namespaces: [
202+
- {
203+
- binding: \\"MY_KV\\"
204+
- id: \\"my-kv-123\\"
205+
- }
206+
- ]
207+
- compatibility_date: \\"2025-07-08\\"
208+
+ compatibility_date: \\"2025-07-09\\"
195209
observability: {
196-
[31m- enabled: true[39m
197-
[32m+ enabled: false[39m
210+
- enabled: true
211+
+ enabled: false
198212
}
199213
}
200214
"
@@ -249,11 +263,11 @@ describe("getRemoteConfigsDiff", () => {
249263
{ enabled: true }
250264
);
251265
assert(diff);
252-
expect(diff.toString()).toMatchInlineSnapshot(`
266+
expect(normalizeDiff(diff.toString())).toMatchInlineSnapshot(`
253267
" {
254268
observability: {
255-
[31m- enabled: false[39m
256-
[32m+ enabled: true[39m
269+
- enabled: false
270+
+ enabled: true
257271
}
258272
}
259273
"
@@ -267,12 +281,12 @@ describe("getRemoteConfigsDiff", () => {
267281
{ logs: { enabled: true } }
268282
);
269283
assert(diff);
270-
expect(diff.toString()).toMatchInlineSnapshot(`
284+
expect(normalizeDiff(diff.toString())).toMatchInlineSnapshot(`
271285
" {
272286
observability: {
273287
logs: {
274-
[31m- enabled: false[39m
275-
[32m+ enabled: true[39m
288+
- enabled: false
289+
+ enabled: true
276290
}
277291
}
278292
}
@@ -298,12 +312,12 @@ describe("getRemoteConfigsDiff", () => {
298312
{ logs: { enabled: true, head_sampling_rate: 0.9 } }
299313
);
300314
assert(diff);
301-
expect(diff.toString()).toMatchInlineSnapshot(`
315+
expect(normalizeDiff(diff.toString())).toMatchInlineSnapshot(`
302316
" {
303317
observability: {
304318
logs: {
305-
[31m- head_sampling_rate: 1[39m
306-
[32m+ head_sampling_rate: 0.9[39m
319+
- head_sampling_rate: 1
320+
+ head_sampling_rate: 0.9
307321
}
308322
}
309323
}

0 commit comments

Comments
 (0)