Skip to content

Commit 681e178

Browse files
committed
Get rid of manual steps when updating snapshots
1 parent 1732deb commit 681e178

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'
@@ -122,7 +123,7 @@ describe('findDeclarationLocations', () => {
122123
word: './extension.inc',
123124
position: { character: 10, line: 2 },
124125
})
125-
expect(result).toMatchInlineSnapshot(`
126+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
126127
Array [
127128
Object {
128129
"range": Object {
@@ -135,7 +136,7 @@ describe('findDeclarationLocations', () => {
135136
"line": 0,
136137
},
137138
},
138-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
139+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
139140
},
140141
]
141142
`)
@@ -157,7 +158,7 @@ describe('findDeclarationLocations', () => {
157158
word: './scripts/tag-release.inc',
158159
position: { character: 10, line: 16 },
159160
})
160-
expect(result).toMatchInlineSnapshot(`
161+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
161162
Array [
162163
Object {
163164
"range": Object {
@@ -170,7 +171,7 @@ describe('findDeclarationLocations', () => {
170171
"line": 0,
171172
},
172173
},
173-
"uri": "file://${REPO_ROOT_FOLDER}/scripts/tag-release.inc",
174+
"uri": "file://__REPO_ROOT_FOLDER__/scripts/tag-release.inc",
174175
},
175176
]
176177
`)
@@ -183,7 +184,7 @@ describe('findDeclarationLocations', () => {
183184
uri: CURRENT_URI,
184185
word: 'node_version',
185186
})
186-
expect(result).toMatchInlineSnapshot(`
187+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
187188
Array [
188189
Object {
189190
"range": Object {
@@ -208,7 +209,7 @@ describe('findDeclarationLocations', () => {
208209
uri: FIXTURE_URI.SCOPE,
209210
word: 'X',
210211
})
211-
expect(result).toMatchInlineSnapshot(`
212+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
212213
Array [
213214
Object {
214215
"range": Object {
@@ -221,7 +222,7 @@ describe('findDeclarationLocations', () => {
221222
"line": 12,
222223
},
223224
},
224-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
225+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
225226
},
226227
]
227228
`)
@@ -233,7 +234,7 @@ describe('findDeclarationLocations', () => {
233234
uri: FIXTURE_URI.SCOPE,
234235
word: 'i',
235236
})
236-
expect(result).toMatchInlineSnapshot(`
237+
expect(updateSnapshotUris(result)).toMatchInlineSnapshot(`
237238
Array [
238239
Object {
239240
"range": Object {
@@ -246,7 +247,7 @@ describe('findDeclarationLocations', () => {
246247
"line": 37,
247248
},
248249
},
249-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
250+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
250251
},
251252
]
252253
`)
@@ -403,12 +404,14 @@ describe('findDeclarationsMatchingWord', () => {
403404
})
404405

405406
expect(
406-
analyzer.findDeclarationsMatchingWord({
407-
word: 'npm_config_logl',
408-
uri: FIXTURE_URI.INSTALL,
409-
exactMatch: false,
410-
position: { line: 1000, character: 0 },
411-
}),
407+
updateSnapshotUris(
408+
analyzer.findDeclarationsMatchingWord({
409+
word: 'npm_config_logl',
410+
uri: FIXTURE_URI.INSTALL,
411+
exactMatch: false,
412+
position: { line: 1000, character: 0 },
413+
}),
414+
),
412415
).toMatchInlineSnapshot(`
413416
Array [
414417
Object {
@@ -424,7 +427,7 @@ describe('findDeclarationsMatchingWord', () => {
424427
"line": 40,
425428
},
426429
},
427-
"uri": "file://${FIXTURE_FOLDER}install.sh",
430+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/install.sh",
428431
},
429432
"name": "npm_config_loglevel",
430433
},
@@ -441,12 +444,14 @@ describe('findDeclarationsMatchingWord', () => {
441444
).toMatchInlineSnapshot(`Array []`)
442445

443446
expect(
444-
analyzer.findDeclarationsMatchingWord({
445-
word: 'BLU',
446-
uri: FIXTURE_URI.INSTALL,
447-
exactMatch: false,
448-
position: { line: 6, character: 9 },
449-
}),
447+
updateSnapshotUris(
448+
analyzer.findDeclarationsMatchingWord({
449+
word: 'BLU',
450+
uri: FIXTURE_URI.INSTALL,
451+
exactMatch: false,
452+
position: { line: 6, character: 9 },
453+
}),
454+
),
450455
).toMatchInlineSnapshot(`
451456
Array [
452457
Object {
@@ -462,20 +467,22 @@ describe('findDeclarationsMatchingWord', () => {
462467
"line": 6,
463468
},
464469
},
465-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
470+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
466471
},
467472
"name": "BLUE",
468473
},
469474
]
470475
`)
471476

472477
expect(
473-
analyzer.findDeclarationsMatchingWord({
474-
word: 'BLU',
475-
uri: FIXTURE_URI.SOURCING,
476-
exactMatch: false,
477-
position: { line: 6, character: 9 },
478-
}),
478+
updateSnapshotUris(
479+
analyzer.findDeclarationsMatchingWord({
480+
word: 'BLU',
481+
uri: FIXTURE_URI.SOURCING,
482+
exactMatch: false,
483+
position: { line: 6, character: 9 },
484+
}),
485+
),
479486
).toMatchInlineSnapshot(`
480487
Array [
481488
Object {
@@ -491,7 +498,7 @@ describe('findDeclarationsMatchingWord', () => {
491498
"line": 6,
492499
},
493500
},
494-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
501+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
495502
},
496503
"name": "BLUE",
497504
},
@@ -522,12 +529,14 @@ describe('findDeclarationsMatchingWord', () => {
522529
).toMatchInlineSnapshot(`Array []`)
523530

524531
expect(
525-
analyzer.findDeclarationsMatchingWord({
526-
word: 'BLU',
527-
uri: FIXTURE_URI.SOURCING,
528-
exactMatch: false,
529-
position: { line: 6, character: 9 },
530-
}),
532+
updateSnapshotUris(
533+
analyzer.findDeclarationsMatchingWord({
534+
word: 'BLU',
535+
uri: FIXTURE_URI.SOURCING,
536+
exactMatch: false,
537+
position: { line: 6, character: 9 },
538+
}),
539+
),
531540
).toMatchInlineSnapshot(`
532541
Array [
533542
Object {
@@ -543,7 +552,7 @@ describe('findDeclarationsMatchingWord', () => {
543552
"line": 6,
544553
},
545554
},
546-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
555+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
547556
},
548557
"name": "BLUE",
549558
},
@@ -573,7 +582,7 @@ describe('findDeclarationsMatchingWord', () => {
573582
expect(findWordFromLine('f', 0)).toEqual([])
574583

575584
// First definition
576-
expect(findWordFromLine('X', 3)).toMatchInlineSnapshot(`
585+
expect(updateSnapshotUris(findWordFromLine('X', 3))).toMatchInlineSnapshot(`
577586
Array [
578587
Object {
579588
"kind": 13,
@@ -588,15 +597,15 @@ describe('findDeclarationsMatchingWord', () => {
588597
"line": 2,
589598
},
590599
},
591-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
600+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
592601
},
593602
"name": "X",
594603
},
595604
]
596605
`)
597606

598607
// Local variable definition
599-
expect(findWordFromLine('X', 13)).toMatchInlineSnapshot(`
608+
expect(updateSnapshotUris(findWordFromLine('X', 13))).toMatchInlineSnapshot(`
600609
Array [
601610
Object {
602611
"containerName": "g",
@@ -612,15 +621,15 @@ describe('findDeclarationsMatchingWord', () => {
612621
"line": 12,
613622
},
614623
},
615-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
624+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
616625
},
617626
"name": "X",
618627
},
619628
]
620629
`)
621630

622631
// Local function definition
623-
expect(findWordFromLine('f', 23)).toMatchInlineSnapshot(`
632+
expect(updateSnapshotUris(findWordFromLine('f', 23))).toMatchInlineSnapshot(`
624633
Array [
625634
Object {
626635
"containerName": "g",
@@ -636,15 +645,15 @@ describe('findDeclarationsMatchingWord', () => {
636645
"line": 18,
637646
},
638647
},
639-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
648+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
640649
},
641650
"name": "f",
642651
},
643652
]
644653
`)
645654

646655
// Last definition
647-
expect(findWordFromLine('X', 1000)).toMatchInlineSnapshot(`
656+
expect(updateSnapshotUris(findWordFromLine('X', 1000))).toMatchInlineSnapshot(`
648657
Array [
649658
Object {
650659
"kind": 13,
@@ -659,14 +668,14 @@ describe('findDeclarationsMatchingWord', () => {
659668
"line": 4,
660669
},
661670
},
662-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
671+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
663672
},
664673
"name": "X",
665674
},
666675
]
667676
`)
668677

669-
expect(findWordFromLine('f', 1000)).toMatchInlineSnapshot(`
678+
expect(updateSnapshotUris(findWordFromLine('f', 1000))).toMatchInlineSnapshot(`
670679
Array [
671680
Object {
672681
"kind": 12,
@@ -681,15 +690,15 @@ describe('findDeclarationsMatchingWord', () => {
681690
"line": 7,
682691
},
683692
},
684-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
693+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
685694
},
686695
"name": "f",
687696
},
688697
]
689698
`)
690699

691700
// Global variable defined inside a function
692-
expect(findWordFromLine('GLOBAL_1', 1000)).toMatchInlineSnapshot(`
701+
expect(updateSnapshotUris(findWordFromLine('GLOBAL_1', 1000))).toMatchInlineSnapshot(`
693702
Array [
694703
Object {
695704
"containerName": "g",
@@ -705,7 +714,7 @@ describe('findDeclarationsMatchingWord', () => {
705714
"line": 13,
706715
},
707716
},
708-
"uri": "file://${FIXTURE_FOLDER}scope.sh",
717+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/scope.sh",
709718
},
710719
"name": "GLOBAL_1",
711720
},
@@ -842,8 +851,14 @@ describe('getAllVariables', () => {
842851

843852
newAnalyzer.analyze({ uri, document })
844853

845-
expect(newAnalyzer.getAllVariables({ uri, position: { line: 20, character: 0 } }))
846-
.toMatchInlineSnapshot(`
854+
expect(
855+
updateSnapshotUris(
856+
newAnalyzer.getAllVariables({
857+
uri,
858+
position: { line: 20, character: 0 },
859+
}),
860+
),
861+
).toMatchInlineSnapshot(`
847862
Array [
848863
Object {
849864
"kind": 13,
@@ -858,7 +873,7 @@ describe('getAllVariables', () => {
858873
"line": 10,
859874
},
860875
},
861-
"uri": "file://${FIXTURE_FOLDER}sourcing.sh",
876+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/sourcing.sh",
862877
},
863878
"name": "BOLD",
864879
},
@@ -875,7 +890,7 @@ describe('getAllVariables', () => {
875890
"line": 4,
876891
},
877892
},
878-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
893+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
879894
},
880895
"name": "RED",
881896
},
@@ -892,7 +907,7 @@ describe('getAllVariables', () => {
892907
"line": 5,
893908
},
894909
},
895-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
910+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
896911
},
897912
"name": "GREEN",
898913
},
@@ -909,7 +924,7 @@ describe('getAllVariables', () => {
909924
"line": 6,
910925
},
911926
},
912-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
927+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
913928
},
914929
"name": "BLUE",
915930
},
@@ -926,7 +941,7 @@ describe('getAllVariables', () => {
926941
"line": 7,
927942
},
928943
},
929-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
944+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
930945
},
931946
"name": "BOLD",
932947
},
@@ -943,7 +958,7 @@ describe('getAllVariables', () => {
943958
"line": 10,
944959
},
945960
},
946-
"uri": "file://${FIXTURE_FOLDER}extension.inc",
961+
"uri": "file://__REPO_ROOT_FOLDER__/testing/fixtures/extension.inc",
947962
},
948963
"name": "RESET",
949964
},

0 commit comments

Comments
 (0)