Skip to content

Commit d57069a

Browse files
committed
Get rid of manual steps when updating snapshots
1 parent 2958795 commit d57069a

File tree

2 files changed

+87
-57
lines changed

2 files changed

+87
-57
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 72 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FIXTURE_FOLDER,
66
FIXTURE_URI,
77
REPO_ROOT_FOLDER,
8+
updateSnapshotUris,
89
} from '../../../testing/fixtures'
910
import Analyzer from '../analyser'
1011
import { getDefaultConfiguration } from '../config'
@@ -153,7 +154,7 @@ describe('findDeclarationLocations', () => {
153154
word: './extension.inc',
154155
position: { character: 10, line: 2 },
155156
})
156-
expect(result).toMatchInlineSnapshot(`
157+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
157158
Array [
158159
Object {
159160
"range": Object {
@@ -166,7 +167,7 @@ describe('findDeclarationLocations', () => {
166167
"line": 0,
167168
},
168169
},
169-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
170+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
170171
},
171172
]
172173
`)
@@ -188,7 +189,7 @@ describe('findDeclarationLocations', () => {
188189
word: './scripts/tag-release.inc',
189190
position: { character: 10, line: 16 },
190191
})
191-
expect(result).toMatchInlineSnapshot(`
192+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
192193
Array [
193194
Object {
194195
"range": Object {
@@ -201,7 +202,7 @@ describe('findDeclarationLocations', () => {
201202
"line": 0,
202203
},
203204
},
204-
"uri": "file://${REPO_ROOT_FOLDER}/scripts/tag-release.inc",
205+
"uri": "file://__REPO_ROOT_FOLDER__/scripts/tag-release.inc",
205206
},
206207
]
207208
`)
@@ -214,7 +215,7 @@ describe('findDeclarationLocations', () => {
214215
uri: CURRENT_URI,
215216
word: 'node_version',
216217
})
217-
expect(result).toMatchInlineSnapshot(`
218+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
218219
Array [
219220
Object {
220221
"range": Object {
@@ -239,7 +240,7 @@ describe('findDeclarationLocations', () => {
239240
uri: FIXTURE_URI.SCOPE,
240241
word: 'X',
241242
})
242-
expect(result).toMatchInlineSnapshot(`
243+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
243244
Array [
244245
Object {
245246
"range": Object {
@@ -252,7 +253,7 @@ describe('findDeclarationLocations', () => {
252253
"line": 12,
253254
},
254255
},
255-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
256+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
256257
},
257258
]
258259
`)
@@ -264,7 +265,7 @@ describe('findDeclarationLocations', () => {
264265
uri: FIXTURE_URI.SCOPE,
265266
word: 'i',
266267
})
267-
expect(result).toMatchInlineSnapshot(`
268+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
268269
Array [
269270
Object {
270271
"range": Object {
@@ -277,7 +278,7 @@ describe('findDeclarationLocations', () => {
277278
"line": 37,
278279
},
279280
},
280-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
281+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
281282
},
282283
]
283284
`)
@@ -434,12 +435,14 @@ describe('findDeclarationsMatchingWord', () => {
434435
})
435436

436437
expect(
437-
analyzer.findDeclarationsMatchingWord({
438-
word: 'npm_config_logl',
439-
uri: FIXTURE_URI.INSTALL,
440-
exactMatch: false,
441-
position: { line: 1000, character: 0 },
442-
}),
438+
updateSnapshotUris(
439+
analyzer.findDeclarationsMatchingWord({
440+
word: 'npm_config_logl',
441+
uri: FIXTURE_URI.INSTALL,
442+
exactMatch: false,
443+
position: { line: 1000, character: 0 },
444+
}),
445+
),
443446
).toMatchInlineSnapshot(`
444447
Array [
445448
Object {
@@ -455,7 +458,7 @@ describe('findDeclarationsMatchingWord', () => {
455458
"line": 40,
456459
},
457460
},
458-
"uri": "file://${FIXTURE_FOLDER}install.sh",
461+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/install.sh",
459462
},
460463
"name": "npm_config_loglevel",
461464
},
@@ -472,12 +475,14 @@ describe('findDeclarationsMatchingWord', () => {
472475
).toMatchInlineSnapshot(`Array []`)
473476

474477
expect(
475-
analyzer.findDeclarationsMatchingWord({
476-
word: 'BLU',
477-
uri: FIXTURE_URI.INSTALL,
478-
exactMatch: false,
479-
position: { line: 6, character: 9 },
480-
}),
478+
updateSnapshotUris(
479+
analyzer.findDeclarationsMatchingWord({
480+
word: 'BLU',
481+
uri: FIXTURE_URI.INSTALL,
482+
exactMatch: false,
483+
position: { line: 6, character: 9 },
484+
}),
485+
),
481486
).toMatchInlineSnapshot(`
482487
Array [
483488
Object {
@@ -493,20 +498,22 @@ describe('findDeclarationsMatchingWord', () => {
493498
"line": 6,
494499
},
495500
},
496-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
501+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
497502
},
498503
"name": "BLUE",
499504
},
500505
]
501506
`)
502507

503508
expect(
504-
analyzer.findDeclarationsMatchingWord({
505-
word: 'BLU',
506-
uri: FIXTURE_URI.SOURCING,
507-
exactMatch: false,
508-
position: { line: 6, character: 9 },
509-
}),
509+
updateSnapshotUris(
510+
analyzer.findDeclarationsMatchingWord({
511+
word: 'BLU',
512+
uri: FIXTURE_URI.SOURCING,
513+
exactMatch: false,
514+
position: { line: 6, character: 9 },
515+
}),
516+
),
510517
).toMatchInlineSnapshot(`
511518
Array [
512519
Object {
@@ -522,7 +529,7 @@ describe('findDeclarationsMatchingWord', () => {
522529
"line": 6,
523530
},
524531
},
525-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
532+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
526533
},
527534
"name": "BLUE",
528535
},
@@ -553,12 +560,14 @@ describe('findDeclarationsMatchingWord', () => {
553560
).toMatchInlineSnapshot(`Array []`)
554561

555562
expect(
556-
analyzer.findDeclarationsMatchingWord({
557-
word: 'BLU',
558-
uri: FIXTURE_URI.SOURCING,
559-
exactMatch: false,
560-
position: { line: 6, character: 9 },
561-
}),
563+
updateSnapshotUris(
564+
analyzer.findDeclarationsMatchingWord({
565+
word: 'BLU',
566+
uri: FIXTURE_URI.SOURCING,
567+
exactMatch: false,
568+
position: { line: 6, character: 9 },
569+
}),
570+
),
562571
).toMatchInlineSnapshot(`
563572
Array [
564573
Object {
@@ -574,7 +583,7 @@ describe('findDeclarationsMatchingWord', () => {
574583
"line": 6,
575584
},
576585
},
577-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
586+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
578587
},
579588
"name": "BLUE",
580589
},
@@ -604,7 +613,7 @@ describe('findDeclarationsMatchingWord', () => {
604613
expect(findWordFromLine('f', 0)).toEqual([])
605614

606615
// First definition
607-
expect(findWordFromLine('X', 3)).toMatchInlineSnapshot(`
616+
expect(updateSnapshotUris(findWordFromLine('X', 3))).toMatchInlineSnapshot(`
608617
Array [
609618
Object {
610619
"kind": 13,
@@ -619,15 +628,15 @@ describe('findDeclarationsMatchingWord', () => {
619628
"line": 2,
620629
},
621630
},
622-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
631+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
623632
},
624633
"name": "X",
625634
},
626635
]
627636
`)
628637

629638
// Local variable definition
630-
expect(findWordFromLine('X', 13)).toMatchInlineSnapshot(`
639+
expect(updateSnapshotUris(findWordFromLine('X', 13))).toMatchInlineSnapshot(`
631640
Array [
632641
Object {
633642
"containerName": "g",
@@ -643,15 +652,15 @@ describe('findDeclarationsMatchingWord', () => {
643652
"line": 12,
644653
},
645654
},
646-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
655+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
647656
},
648657
"name": "X",
649658
},
650659
]
651660
`)
652661

653662
// Local function definition
654-
expect(findWordFromLine('f', 23)).toMatchInlineSnapshot(`
663+
expect(updateSnapshotUris(findWordFromLine('f', 23))).toMatchInlineSnapshot(`
655664
Array [
656665
Object {
657666
"containerName": "g",
@@ -667,15 +676,15 @@ describe('findDeclarationsMatchingWord', () => {
667676
"line": 18,
668677
},
669678
},
670-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
679+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
671680
},
672681
"name": "f",
673682
},
674683
]
675684
`)
676685

677686
// Last definition
678-
expect(findWordFromLine('X', 1000)).toMatchInlineSnapshot(`
687+
expect(updateSnapshotUris(findWordFromLine('X', 1000))).toMatchInlineSnapshot(`
679688
Array [
680689
Object {
681690
"kind": 13,
@@ -690,14 +699,14 @@ describe('findDeclarationsMatchingWord', () => {
690699
"line": 4,
691700
},
692701
},
693-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
702+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
694703
},
695704
"name": "X",
696705
},
697706
]
698707
`)
699708

700-
expect(findWordFromLine('f', 1000)).toMatchInlineSnapshot(`
709+
expect(updateSnapshotUris(findWordFromLine('f', 1000))).toMatchInlineSnapshot(`
701710
Array [
702711
Object {
703712
"kind": 12,
@@ -712,15 +721,15 @@ describe('findDeclarationsMatchingWord', () => {
712721
"line": 7,
713722
},
714723
},
715-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
724+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
716725
},
717726
"name": "f",
718727
},
719728
]
720729
`)
721730

722731
// Global variable defined inside a function
723-
expect(findWordFromLine('GLOBAL_1', 1000)).toMatchInlineSnapshot(`
732+
expect(updateSnapshotUris(findWordFromLine('GLOBAL_1', 1000))).toMatchInlineSnapshot(`
724733
Array [
725734
Object {
726735
"containerName": "g",
@@ -736,7 +745,7 @@ describe('findDeclarationsMatchingWord', () => {
736745
"line": 13,
737746
},
738747
},
739-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
748+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
740749
},
741750
"name": "GLOBAL_1",
742751
},
@@ -868,8 +877,14 @@ describe('getAllVariables', () => {
868877

869878
newAnalyzer.analyze({ uri, document })
870879

871-
expect(newAnalyzer.getAllVariables({ uri, position: { line: 20, character: 0 } }))
872-
.toMatchInlineSnapshot(`
880+
expect(
881+
updateSnapshotUris(
882+
newAnalyzer.getAllVariables({
883+
uri,
884+
position: { line: 20, character: 0 },
885+
}),
886+
),
887+
).toMatchInlineSnapshot(`
873888
Array [
874889
Object {
875890
"kind": 13,
@@ -884,7 +899,7 @@ describe('getAllVariables', () => {
884899
"line": 10,
885900
},
886901
},
887-
"uri": "file://${FIXTURE_FOLDER}sourcing.sh",
902+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/sourcing.sh",
888903
},
889904
"name": "BOLD",
890905
},
@@ -901,7 +916,7 @@ describe('getAllVariables', () => {
901916
"line": 4,
902917
},
903918
},
904-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
919+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
905920
},
906921
"name": "RED",
907922
},
@@ -918,7 +933,7 @@ describe('getAllVariables', () => {
918933
"line": 5,
919934
},
920935
},
921-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
936+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
922937
},
923938
"name": "GREEN",
924939
},
@@ -935,7 +950,7 @@ describe('getAllVariables', () => {
935950
"line": 6,
936951
},
937952
},
938-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
953+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
939954
},
940955
"name": "BLUE",
941956
},
@@ -952,7 +967,7 @@ describe('getAllVariables', () => {
952967
"line": 7,
953968
},
954969
},
955-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
970+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
956971
},
957972
"name": "BOLD",
958973
},
@@ -969,7 +984,7 @@ describe('getAllVariables', () => {
969984
"line": 10,
970985
},
971986
},
972-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
987+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
973988
},
974989
"name": "RESET",
975990
},

0 commit comments

Comments
 (0)