Skip to content

Commit efc9626

Browse files
committed
Use Vitest to have individual snapshot files
1 parent 7d5ba83 commit efc9626

6 files changed

+948
-16
lines changed

tests/analysis_new_tests/tests/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
"scripts": {
66
"build": "rescript",
77
"clean": "rescript clean -with-deps",
8-
"test": "yarn build && node test.js",
9-
"test:update": "node --test-update-snapshots test.js"
8+
"test": "yarn build && vitest run test.js",
9+
"test:update": "vitest run -u test.js"
1010
},
1111
"dependencies": {
1212
"@rescript/react": "link:../../dependencies/rescript-react",
1313
"rescript": "workspace:^"
14+
},
15+
"devDependencies": {
16+
"vitest": "3.1.2"
1417
}
1518
}

tests/analysis_new_tests/tests/test.js renamed to tests/analysis_new_tests/tests/snapshots.test.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test } from "node:test";
1+
import { test, expect } from "vitest";
22
import fs from "node:fs/promises";
33
import path from "node:path";
44
import { glob } from "glob";
@@ -116,7 +116,7 @@ await Promise.all(
116116
resFiles.forEach((file) => {
117117
const blockData = testBlocksPerFile.get(file.relativePath);
118118
for (const block of blockData) {
119-
test(`${file.relativePath} - ${block.description}`, async (t) => {
119+
test(`${file.relativePath} - ${block.description}`, async () => {
120120
// Run rescript-editor-analysis and capture output
121121
const analysisOutput = await new Promise((resolve, reject) => {
122122
const analysisCmd = spawn(
@@ -153,7 +153,14 @@ resFiles.forEach((file) => {
153153
});
154154
});
155155

156-
t.assert.snapshot(analysisOutput.stdout);
156+
// Construct snapshot path
157+
const snapshotDir = path.join(testFilesDir, "__snapshots__");
158+
await fs.mkdir(snapshotDir, { recursive: true }); // Ensure snapshot dir exists
159+
const snapshotFileName = `${file.relativePath}_${block.description.replace(/\\s+/g, "_")}.snap`;
160+
const snapshotPath = path.join(snapshotDir, snapshotFileName);
161+
162+
// Use Vitest's expect().toMatchFileSnapshot()
163+
await expect(analysisOutput.stdout).toMatchFileSnapshot(snapshotPath);
157164
});
158165
}
159166
});

tests/analysis_new_tests/tests/test.js.snapshot

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Complete /Users/nojaf/Projects/rescript/tests/analysis_new_tests/tests/test_files/.build/RecordFieldCompletions_2.res 1:45
2+
posCursor:[1:45] posNoWhite:[1:44] Found expr:[1:8->1:45]
3+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
4+
Resolved opens 1 Stdlib
5+
[{
6+
"label": "name",
7+
"kind": 5,
8+
"tags": [],
9+
"detail": "string",
10+
"documentation": {"kind": "markdown", "value": "```rescript\nname: string\n```\n\n```rescript\ntype \\\"nestedTestRecord.nested\" = {\n name: string,\n oneMoreLevel: {here: bool},\n}\n```"}
11+
}, {
12+
"label": "oneMoreLevel",
13+
"kind": 5,
14+
"tags": [],
15+
"detail": "\\\"nestedTestRecord.nested.oneMoreLevel\"",
16+
"documentation": {"kind": "markdown", "value": "```rescript\noneMoreLevel: \\\"nestedTestRecord.nested.oneMoreLevel\"\n```\n\n```rescript\ntype \\\"nestedTestRecord.nested\" = {\n name: string,\n oneMoreLevel: {here: bool},\n}\n```"}
17+
}]
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Complete /Users/nojaf/Projects/rescript/tests/analysis_new_tests/tests/test_files/.build/RecordFieldCompletions_1.res 1:38
2+
posCursor:[1:38] posNoWhite:[1:37] Found expr:[1:8->1:38]
3+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
4+
Resolved opens 1 Stdlib
5+
[{
6+
"label": "test",
7+
"kind": 5,
8+
"tags": [],
9+
"detail": "bool",
10+
"documentation": {"kind": "markdown", "value": "```rescript\ntest: bool\n```\n\n```rescript\ntype nestedTestRecord = {\n test: bool,\n nested: {name: string, oneMoreLevel: {here: bool}},\n}\n```"}
11+
}, {
12+
"label": "nested",
13+
"kind": 5,
14+
"tags": [],
15+
"detail": "\\\"nestedTestRecord.nested\"",
16+
"documentation": {"kind": "markdown", "value": "```rescript\nnested: \\\"nestedTestRecord.nested\"\n```\n\n```rescript\ntype nestedTestRecord = {\n test: bool,\n nested: {name: string, oneMoreLevel: {here: bool}},\n}\n```"}
17+
}]
18+

0 commit comments

Comments
 (0)