Skip to content

Commit 1391b2b

Browse files
authored
test: use snapshots everywhere (#1311)
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent d95d947 commit 1391b2b

14 files changed

+1063
-676
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ clean: ## Clean build artifacts and other generated files
7070
.PHONY: fmt
7171
fmt: ## Format the codebase with ocamlformat
7272
dune build @fmt --auto-promote
73-
cd $(TEST_E2E_DIR) && yarn fmt
73+
cd $(TEST_E2E_DIR)
7474

7575
.PHONY: watch
7676
watch: ## Watch for the filesystem and rebuild on every change
@@ -97,7 +97,7 @@ nix-tests:
9797
nix-fmt:
9898
$(MAKE) yarn-install
9999
dune build @fmt --auto-promote
100-
cd $(TEST_E2E_DIR) && yarn fmt
100+
cd $(TEST_E2E_DIR)
101101

102102
.PHONY: coverage-deps
103103
coverage-deps:

ocaml-lsp-server/test/e2e/__tests__/ocamllsp-hoverExtended.ts

Lines changed: 120 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,24 @@ describe("ocamllsp/hoverExtended", () => {
2727
verbosity: 0,
2828
});
2929

30-
expect(result).toMatchObject({
31-
contents: { kind: "plaintext", value: "int" },
32-
range: {
33-
end: { character: 5, line: 0 },
34-
start: { character: 4, line: 0 },
35-
},
36-
});
30+
expect(result).toMatchInlineSnapshot(`
31+
Object {
32+
"contents": Object {
33+
"kind": "plaintext",
34+
"value": "int",
35+
},
36+
"range": Object {
37+
"end": Object {
38+
"character": 5,
39+
"line": 0,
40+
},
41+
"start": Object {
42+
"character": 4,
43+
"line": 0,
44+
},
45+
},
46+
}
47+
`);
3748
});
3849

3950
it("returns type inferred under cursor (markdown formatting)", async () => {
@@ -63,13 +74,26 @@ describe("ocamllsp/hoverExtended", () => {
6374
verbosity: 0,
6475
});
6576

66-
expect(result).toMatchObject({
67-
contents: { kind: "markdown", value: "```ocaml\nint\n```" },
68-
range: {
69-
end: { character: 5, line: 0 },
70-
start: { character: 4, line: 0 },
71-
},
72-
});
77+
expect(result).toMatchInlineSnapshot(`
78+
Object {
79+
"contents": Object {
80+
"kind": "markdown",
81+
"value": "\`\`\`ocaml
82+
int
83+
\`\`\`",
84+
},
85+
"range": Object {
86+
"end": Object {
87+
"character": 5,
88+
"line": 0,
89+
},
90+
"start": Object {
91+
"character": 4,
92+
"line": 0,
93+
},
94+
},
95+
}
96+
`);
7397
});
7498

7599
it("returns type inferred under cursor with documentation", async () => {
@@ -104,18 +128,28 @@ describe("ocamllsp/hoverExtended", () => {
104128
verbosity: 0,
105129
});
106130

107-
expect(result).toMatchObject({
108-
contents: {
109-
kind: "markdown",
110-
value: outdent`
111-
\`\`\`ocaml
112-
'a -> 'a
113-
\`\`\`
114-
---
115-
This function has a nice documentation
116-
`,
117-
},
118-
});
131+
expect(result).toMatchInlineSnapshot(`
132+
Object {
133+
"contents": Object {
134+
"kind": "markdown",
135+
"value": "\`\`\`ocaml
136+
'a -> 'a
137+
\`\`\`
138+
---
139+
This function has a nice documentation",
140+
},
141+
"range": Object {
142+
"end": Object {
143+
"character": 11,
144+
"line": 3,
145+
},
146+
"start": Object {
147+
"character": 9,
148+
"line": 3,
149+
},
150+
},
151+
}
152+
`);
119153
});
120154

121155
it("returns type inferred under cursor with documentation with tags (markdown formatting)", async () => {
@@ -170,48 +204,58 @@ describe("ocamllsp/hoverExtended", () => {
170204
verbosity: 0,
171205
});
172206

173-
expect(result).toMatchObject({
174-
contents: {
175-
kind: "markdown",
176-
value: outdent`
177-
\`\`\`ocaml
178-
int -> int -> int
179-
\`\`\`
180-
---
181-
This function has a nice documentation.
207+
expect(result).toMatchInlineSnapshot(`
208+
Object {
209+
"contents": Object {
210+
"kind": "markdown",
211+
"value": "\`\`\`ocaml
212+
int -> int -> int
213+
\`\`\`
214+
---
215+
This function has a nice documentation.
182216
183-
It performs division of two integer numbers.
217+
It performs division of two integer numbers.
184218
185-
***@param*** \`x\`
186-
dividend
219+
***@param*** \`x\`
220+
dividend
187221
188-
***@param*** divisor
222+
***@param*** divisor
189223
190-
***@return***
191-
*quotient*, i.e. result of division
224+
***@return***
225+
*quotient*, i.e. result of division
192226
193-
***@raise*** \`Division_by_zero\`
194-
raised when divided by zero
227+
***@raise*** \`Division_by_zero\`
228+
raised when divided by zero
195229
196-
***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\(%C3%B7,_or_/\\))
197-
article
230+
***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\\\(%C3%B7,_or_/\\\\))
231+
article
198232
199-
***@see*** \`arithmetic.ml\`
200-
for more context
233+
***@see*** \`arithmetic.ml\`
234+
for more context
201235
202-
***@since*** \`4.0.0\`
236+
***@since*** \`4.0.0\`
203237
204-
***@before*** \`4.4.0\`
238+
***@before*** \`4.4.0\`
205239
206-
***@deprecated***
207-
use \`(/)\`
240+
***@deprecated***
241+
use \`(/)\`
208242
209-
***@version*** \`1.0.0\`
243+
***@version*** \`1.0.0\`
210244
211-
***@author*** John Doe
212-
`,
213-
},
214-
});
245+
***@author*** John Doe",
246+
},
247+
"range": Object {
248+
"end": Object {
249+
"character": 11,
250+
"line": 23,
251+
},
252+
"start": Object {
253+
"character": 8,
254+
"line": 23,
255+
},
256+
},
257+
}
258+
`);
215259
});
216260

217261
it("returns good type when cursor is between values", async () => {
@@ -246,16 +290,26 @@ describe("ocamllsp/hoverExtended", () => {
246290
verbosity: 0,
247291
});
248292

249-
expect(result).toMatchObject({
250-
contents: {
251-
kind: "markdown",
252-
value: "```ocaml\nint\n```",
253-
},
254-
range: {
255-
start: { character: 12, line: 3 },
256-
end: { character: 13, line: 3 },
257-
},
258-
});
293+
expect(result).toMatchInlineSnapshot(`
294+
Object {
295+
"contents": Object {
296+
"kind": "markdown",
297+
"value": "\`\`\`ocaml
298+
int
299+
\`\`\`",
300+
},
301+
"range": Object {
302+
"end": Object {
303+
"character": 13,
304+
"line": 3,
305+
},
306+
"start": Object {
307+
"character": 12,
308+
"line": 3,
309+
},
310+
},
311+
}
312+
`);
259313
});
260314

261315
it("regression test for #343", async () => {

ocaml-lsp-server/test/e2e/__tests__/textDocument-codeLens.test.ts

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,57 @@ describe("textDocument/references", () => {
5151

5252
let result = await query();
5353

54-
expect(result).toMatchObject([
55-
{
56-
command: { command: "", title: "int -> int -> int" },
57-
range: {
58-
end: { character: 19, line: 4 },
59-
start: { character: 2, line: 4 },
60-
},
54+
expect(result).toMatchInlineSnapshot(`
55+
Array [
56+
Object {
57+
"command": Object {
58+
"command": "",
59+
"title": "int -> int -> int",
60+
},
61+
"range": Object {
62+
"end": Object {
63+
"character": 19,
64+
"line": 4,
6165
},
62-
{
63-
command: { command: "", title: "string" },
64-
range: {
65-
end: { character: 20, line: 1 },
66-
start: { character: 0, line: 1 },
67-
},
66+
"start": Object {
67+
"character": 2,
68+
"line": 4,
6869
},
69-
{
70-
command: { command: "", title: "int" },
71-
range: {
72-
end: { character: 12, line: 0 },
73-
start: { character: 0, line: 0 },
74-
},
70+
},
71+
},
72+
Object {
73+
"command": Object {
74+
"command": "",
75+
"title": "string",
76+
},
77+
"range": Object {
78+
"end": Object {
79+
"character": 20,
80+
"line": 1,
81+
},
82+
"start": Object {
83+
"character": 0,
84+
"line": 1,
85+
},
86+
},
87+
},
88+
Object {
89+
"command": Object {
90+
"command": "",
91+
"title": "int",
92+
},
93+
"range": Object {
94+
"end": Object {
95+
"character": 12,
96+
"line": 0,
97+
},
98+
"start": Object {
99+
"character": 0,
100+
"line": 0,
75101
},
76-
]);
102+
},
103+
},
104+
]
105+
`);
77106
});
78107
});

ocaml-lsp-server/test/e2e/__tests__/textDocument-declaration.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ describe("textDocument/declaration", () => {
6767
);
6868

6969
expect(result.length).toBe(1);
70-
expect(result[0].range).toMatchObject({
71-
end: { character: 0, line: 0 },
72-
start: { character: 0, line: 0 },
73-
});
70+
expect(result[0].range).toMatchInlineSnapshot(`
71+
Object {
72+
"end": Object {
73+
"character": 0,
74+
"line": 0,
75+
},
76+
"start": Object {
77+
"character": 0,
78+
"line": 0,
79+
},
80+
}
81+
`);
7482
expect(result[0].uri).toEqualUri(testUri(createPathForFile("lib.mli")));
7583
});
7684
});

0 commit comments

Comments
 (0)