Skip to content

Commit 86aac28

Browse files
authored
Fix/inline snapshot indent (#30)
* re-do jest indents with snapshot patch * add script to remove all inline snapshots * linter
1 parent 8c26a4c commit 86aac28

File tree

5 files changed

+287
-254
lines changed

5 files changed

+287
-254
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
],
1111
"scripts": {
1212
"test": "jest",
13+
"test:remove-inline-snapshots": "npx replace '\\.toMatchInlineSnapshot\\(\\s*`[\\s\\S]*?`\\s*\\);' '.toMatchInlineSnapshot();' test -r --include='*.test.js'",
1314
"lint": "npm run prettier && npm run eslint",
1415
"lint:ci": "npm run prettier:ci && npm run eslint:ci",
1516
"eslint": "eslint --fix .",

patches/jest-snapshot+29.7.0.patch

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/node_modules/jest-snapshot/build/InlineSnapshots.js b/node_modules/jest-snapshot/build/InlineSnapshots.js
2+
index 3481ad9..3c227dd 100644
3+
--- a/node_modules/jest-snapshot/build/InlineSnapshots.js
4+
+++ b/node_modules/jest-snapshot/build/InlineSnapshots.js
5+
@@ -193,11 +193,24 @@ const saveSnapshotsForFile = (snapshots, sourceFilePath, rootDir, prettier) => {
6+
7+
// A hack to prevent unexpected line breaks in the generated code
8+
node.loc.end.line = node.loc.start.line;
9+
+ const codeParts = generate(node, {
10+
+ retainLines: true
11+
+ }).code.trim().split("\n");
12+
+ const codeIndented = codeParts
13+
+ .map((part, index) => {
14+
+ switch (index) {
15+
+ case 0:
16+
+ return part;
17+
+ case codeParts.length - 1:
18+
+ return " ".repeat(node.loc.start.column) + part;
19+
+ default:
20+
+ return " ".repeat(node.loc.start.column + 2) + part;
21+
+ }
22+
+ })
23+
+ .join("\n");
24+
return (
25+
sourceSoFar.slice(0, node.start) +
26+
- generate(node, {
27+
- retainLines: true
28+
- }).code.trim() +
29+
+ codeIndented +
30+
sourceSoFar.slice(node.end)
31+
);
32+
},

test/integration-local/featureToggles.integration.test.js

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -259,29 +259,29 @@ describe("local integration test", () => {
259259

260260
expect(featureTogglesLoggerSpy.error).toHaveBeenCalledTimes(0);
261261
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
262-
[
263-
[
264-
"finished initialization with %i feature toggle%s with %s",
265-
8,
266-
"s",
267-
"NO_REDIS",
268-
],
269-
]
270-
`);
262+
[
263+
[
264+
"finished initialization with %i feature toggle%s with %s",
265+
8,
266+
"s",
267+
"NO_REDIS",
268+
],
269+
]
270+
`);
271271
expect(featureTogglesLoggerSpy.warning).toHaveBeenCalledTimes(0);
272272
expect(featureTogglesLoggerSpy.error).toHaveBeenCalledTimes(0);
273273
expect(redisWrapperLoggerSpy.info).toHaveBeenCalledTimes(0);
274274
expect(redisWrapperLoggerSpy.warning.mock.calls).toMatchInlineSnapshot(`
275-
[
276-
[
277-
"%s | %O",
278-
"caught error event: connect ECONNREFUSED 127.0.0.1:6379",
279-
{
280-
"clientName": "main",
281-
},
282-
],
283-
]
284-
`);
275+
[
276+
[
277+
"%s | %O",
278+
"caught error event: connect ECONNREFUSED 127.0.0.1:6379",
279+
{
280+
"clientName": "main",
281+
},
282+
],
283+
]
284+
`);
285285
});
286286

287287
it("getFeatureValue, changeFeatureValue without scopes", async () => {
@@ -295,22 +295,22 @@ describe("local integration test", () => {
295295

296296
expect(await changeFeatureValue(FEATURE.E, newValue)).toBeUndefined();
297297
expect(stateFromInfo(getFeatureInfo(FEATURE.E))).toMatchInlineSnapshot(`
298-
{
299-
"rootValue": 9,
300-
}
301-
`);
298+
{
299+
"rootValue": 9,
300+
}
301+
`);
302302
expect(getFeatureValue(FEATURE.E)).toEqual(newValue);
303303

304304
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
305-
[
306-
[
307-
"finished initialization with %i feature toggle%s with %s",
308-
8,
309-
"s",
310-
"NO_REDIS",
311-
],
312-
]
313-
`);
305+
[
306+
[
307+
"finished initialization with %i feature toggle%s with %s",
308+
8,
309+
"s",
310+
"NO_REDIS",
311+
],
312+
]
313+
`);
314314
expect(featureTogglesLoggerSpy.warning).toHaveBeenCalledTimes(0);
315315
expect(featureTogglesLoggerSpy.error).toHaveBeenCalledTimes(0);
316316
expect(redisWrapperLoggerSpy.info).toHaveBeenCalledTimes(0);
@@ -385,72 +385,72 @@ describe("local integration test", () => {
385385

386386
expect(await changeFeatureValue(FEATURE.E, scopeNewValue, scopeMap)).toBeUndefined();
387387
expect(stateFromInfo(getFeatureInfo(FEATURE.E))).toMatchInlineSnapshot(`
388-
{
389-
"scopedValues": {
390-
"component::c1##tenant::t1": 3,
391-
},
392-
}
393-
`);
388+
{
389+
"scopedValues": {
390+
"component::c1##tenant::t1": 3,
391+
},
392+
}
393+
`);
394394
expect(getFeatureValue(FEATURE.E, subScopeMap)).toEqual(scopeNewValue);
395395
expect(getFeatureValue(FEATURE.E, scopeMap)).toEqual(scopeNewValue);
396396
expect(getFeatureValue(FEATURE.E, superScopeMap)).toEqual(rootOldValue);
397397
expect(getFeatureValue(FEATURE.E)).toEqual(rootOldValue);
398398

399399
expect(await changeFeatureValue(FEATURE.E, superScopeNewValue, superScopeMap)).toBeUndefined();
400400
expect(stateFromInfo(getFeatureInfo(FEATURE.E))).toMatchInlineSnapshot(`
401-
{
402-
"scopedValues": {
403-
"component::c1##tenant::t1": 3,
404-
"tenant::t1": 2,
405-
},
406-
}
407-
`);
401+
{
402+
"scopedValues": {
403+
"component::c1##tenant::t1": 3,
404+
"tenant::t1": 2,
405+
},
406+
}
407+
`);
408408
expect(getFeatureValue(FEATURE.E, subScopeMap)).toEqual(scopeNewValue);
409409
expect(getFeatureValue(FEATURE.E, scopeMap)).toEqual(scopeNewValue);
410410
expect(getFeatureValue(FEATURE.E, superScopeMap)).toEqual(superScopeNewValue);
411411
expect(getFeatureValue(FEATURE.E)).toEqual(rootOldValue);
412412

413413
expect(await changeFeatureValue(FEATURE.E, subScopeNewValue, subScopeMap)).toBeUndefined();
414414
expect(stateFromInfo(getFeatureInfo(FEATURE.E))).toMatchInlineSnapshot(`
415-
{
416-
"scopedValues": {
417-
"component::c1##layer::l1##tenant::t1": 4,
418-
"component::c1##tenant::t1": 3,
419-
"tenant::t1": 2,
420-
},
421-
}
422-
`);
415+
{
416+
"scopedValues": {
417+
"component::c1##layer::l1##tenant::t1": 4,
418+
"component::c1##tenant::t1": 3,
419+
"tenant::t1": 2,
420+
},
421+
}
422+
`);
423423
expect(getFeatureValue(FEATURE.E, subScopeMap)).toEqual(subScopeNewValue);
424424
expect(getFeatureValue(FEATURE.E, scopeMap)).toEqual(scopeNewValue);
425425
expect(getFeatureValue(FEATURE.E, superScopeMap)).toEqual(superScopeNewValue);
426426
expect(getFeatureValue(FEATURE.E)).toEqual(rootOldValue);
427427

428428
expect(await changeFeatureValue(FEATURE.E, rootNewValue)).toBeUndefined();
429429
expect(stateFromInfo(getFeatureInfo(FEATURE.E))).toMatchInlineSnapshot(`
430-
{
431-
"rootValue": 1,
432-
"scopedValues": {
433-
"component::c1##layer::l1##tenant::t1": 4,
434-
"component::c1##tenant::t1": 3,
435-
"tenant::t1": 2,
436-
},
437-
}
438-
`);
430+
{
431+
"rootValue": 1,
432+
"scopedValues": {
433+
"component::c1##layer::l1##tenant::t1": 4,
434+
"component::c1##tenant::t1": 3,
435+
"tenant::t1": 2,
436+
},
437+
}
438+
`);
439439
expect(getFeatureValue(FEATURE.E, subScopeMap)).toEqual(subScopeNewValue);
440440
expect(getFeatureValue(FEATURE.E, scopeMap)).toEqual(scopeNewValue);
441441
expect(getFeatureValue(FEATURE.E, superScopeMap)).toEqual(superScopeNewValue);
442442
expect(getFeatureValue(FEATURE.E)).toEqual(rootNewValue);
443443

444444
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
445-
[
446-
[
447-
"finished initialization with %i feature toggle%s with %s",
448-
8,
449-
"s",
450-
"NO_REDIS",
451-
],
452-
]
453-
`);
445+
[
446+
[
447+
"finished initialization with %i feature toggle%s with %s",
448+
8,
449+
"s",
450+
"NO_REDIS",
451+
],
452+
]
453+
`);
454454
expect(featureTogglesLoggerSpy.warning).toHaveBeenCalledTimes(0);
455455
expect(featureTogglesLoggerSpy.error).toHaveBeenCalledTimes(0);
456456
expect(redisWrapperLoggerSpy.info).toHaveBeenCalledTimes(0);
@@ -474,30 +474,30 @@ describe("local integration test", () => {
474474
expect(await changeFeatureValue(FEATURE.E, subScopeNewValue, subScopeMap)).toBeUndefined();
475475
expect(await changeFeatureValue(FEATURE.E, rootNewValue)).toBeUndefined();
476476
expect(stateFromInfo(getFeatureInfo(FEATURE.E))).toMatchInlineSnapshot(`
477-
{
478-
"rootValue": 1,
479-
"scopedValues": {
480-
"component::c1##layer::l1##tenant::t1": 4,
481-
"component::c1##tenant::t1": 3,
482-
"tenant::t1": 2,
483-
},
484-
}
485-
`);
477+
{
478+
"rootValue": 1,
479+
"scopedValues": {
480+
"component::c1##layer::l1##tenant::t1": 4,
481+
"component::c1##tenant::t1": 3,
482+
"tenant::t1": 2,
483+
},
484+
}
485+
`);
486486
expect(getFeatureValue(FEATURE.E, subScopeMap)).toEqual(subScopeNewValue);
487487
expect(getFeatureValue(FEATURE.E, scopeMap)).toEqual(scopeNewValue);
488488
expect(getFeatureValue(FEATURE.E, superScopeMap)).toEqual(superScopeNewValue);
489489
expect(getFeatureValue(FEATURE.E)).toEqual(rootNewValue);
490490

491491
expect(await changeFeatureValue(FEATURE.E, scopeNewValue, scopeMap, { clearSubScopes: true })).toBeUndefined();
492492
expect(stateFromInfo(getFeatureInfo(FEATURE.E))).toMatchInlineSnapshot(`
493-
{
494-
"rootValue": 1,
495-
"scopedValues": {
496-
"component::c1##tenant::t1": 3,
497-
"tenant::t1": 2,
498-
},
499-
}
500-
`);
493+
{
494+
"rootValue": 1,
495+
"scopedValues": {
496+
"component::c1##tenant::t1": 3,
497+
"tenant::t1": 2,
498+
},
499+
}
500+
`);
501501
expect(getFeatureValue(FEATURE.E, subScopeMap)).toEqual(scopeNewValue);
502502
expect(getFeatureValue(FEATURE.E, scopeMap)).toEqual(scopeNewValue);
503503
expect(getFeatureValue(FEATURE.E, superScopeMap)).toEqual(superScopeNewValue);
@@ -511,15 +511,15 @@ describe("local integration test", () => {
511511
expect(getFeatureValue(FEATURE.E)).toEqual(rootOldValue);
512512

513513
expect(featureTogglesLoggerSpy.info.mock.calls).toMatchInlineSnapshot(`
514-
[
515-
[
516-
"finished initialization with %i feature toggle%s with %s",
517-
8,
518-
"s",
519-
"NO_REDIS",
520-
],
521-
]
522-
`);
514+
[
515+
[
516+
"finished initialization with %i feature toggle%s with %s",
517+
8,
518+
"s",
519+
"NO_REDIS",
520+
],
521+
]
522+
`);
523523
expect(featureTogglesLoggerSpy.warning).toHaveBeenCalledTimes(0);
524524
expect(featureTogglesLoggerSpy.error).toHaveBeenCalledTimes(0);
525525
expect(redisWrapperLoggerSpy.info).toHaveBeenCalledTimes(0);
@@ -592,41 +592,41 @@ describe("local integration test", () => {
592592
expect(await validateFeatureValue(FEATURE.C, "")).toMatchInlineSnapshot(`[]`);
593593
registerFeatureValueValidation(FEATURE.C, failingValidator1);
594594
expect(await validateFeatureValue(FEATURE.C, "")).toMatchInlineSnapshot(`
595-
[
596-
{
597-
"errorMessage": "registered validator "{0}" failed for value "{1}" with error {2}",
598-
"errorMessageValues": [
599-
"failingValidator1",
600-
"",
601-
"bla1",
602-
],
603-
"featureKey": "test/feature_c",
604-
},
605-
]
606-
`);
595+
[
596+
{
597+
"errorMessage": "registered validator "{0}" failed for value "{1}" with error {2}",
598+
"errorMessageValues": [
599+
"failingValidator1",
600+
"",
601+
"bla1",
602+
],
603+
"featureKey": "test/feature_c",
604+
},
605+
]
606+
`);
607607
registerFeatureValueValidation(FEATURE.C, failingValidator2);
608608
expect(await validateFeatureValue(FEATURE.C, "")).toMatchInlineSnapshot(`
609-
[
610-
{
611-
"errorMessage": "registered validator "{0}" failed for value "{1}" with error {2}",
612-
"errorMessageValues": [
613-
"failingValidator1",
614-
"",
615-
"bla1",
616-
],
617-
"featureKey": "test/feature_c",
618-
},
619-
{
620-
"errorMessage": "registered validator "{0}" failed for value "{1}" with error {2}",
621-
"errorMessageValues": [
622-
"failingValidator2",
623-
"",
624-
"bla2",
625-
],
626-
"featureKey": "test/feature_c",
627-
},
628-
]
629-
`);
609+
[
610+
{
611+
"errorMessage": "registered validator "{0}" failed for value "{1}" with error {2}",
612+
"errorMessageValues": [
613+
"failingValidator1",
614+
"",
615+
"bla1",
616+
],
617+
"featureKey": "test/feature_c",
618+
},
619+
{
620+
"errorMessage": "registered validator "{0}" failed for value "{1}" with error {2}",
621+
"errorMessageValues": [
622+
"failingValidator2",
623+
"",
624+
"bla2",
625+
],
626+
"featureKey": "test/feature_c",
627+
},
628+
]
629+
`);
630630
});
631631
});
632632
});

0 commit comments

Comments
 (0)