@flint.fyi/rule-tester 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +13 -10
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import { isDeepStrictEqual } from "node:util";
|
|
3
3
|
import { CachedFactory } from "cached-factory";
|
|
4
4
|
import { resolve } from "pathe";
|
|
5
|
-
import { applyChangesToText, createDiskBackedLinterHost, createEphemeralLinterHost, createVFSLinterHost, formatReport, getPositionOfColumnAndLine, isSuggestionForFiles, parseOptions, processRuleReport, withRepositoryRoot } from "@flint.fyi/core";
|
|
5
|
+
import { applyChangesToText, createDiskBackedLinterHost, createEphemeralLinterHost, createVFSLinterHost, formatReport, getPositionOfColumnAndLine, isFileSystemCaseSensitive, isSuggestionForFiles, parseOptions, processRuleReport, withRepositoryRoot } from "@flint.fyi/core";
|
|
6
6
|
import { isTruthy, normalizePath, nullThrows, pathKey } from "@flint.fyi/utils";
|
|
7
7
|
//#region src/createOutput.ts
|
|
8
8
|
function createOutput(reports, testCaseNormalized) {
|
|
@@ -115,7 +115,7 @@ function resolveReportedSuggestions(reports, testCaseNormalized) {
|
|
|
115
115
|
function resolveReportedSuggestionForFiles(suggestionReported, suggestionExpected) {
|
|
116
116
|
if (!suggestionExpected) return {};
|
|
117
117
|
if (!isTestSuggestionForFiles(suggestionExpected)) throw new Error("This test case describes a suggestion to its own file, but the rule is reporting changes across files.");
|
|
118
|
-
assert.deepStrictEqual(Object.keys(suggestionReported.files).
|
|
118
|
+
assert.deepStrictEqual(Object.keys(suggestionReported.files).toSorted(), Object.keys(suggestionExpected.files).toSorted(), "Reported suggestion target paths must exactly match expected target paths.");
|
|
119
119
|
return Object.fromEntries(Object.entries(suggestionExpected.files).map(([filePath, suggestionCasesExpected]) => {
|
|
120
120
|
const changes = suggestionReported.files[filePath];
|
|
121
121
|
assert.ok(changes, `Expected reported suggestion "${suggestionReported.id}" to provide changes for target "${filePath}".`);
|
|
@@ -163,7 +163,7 @@ async function runTestCaseRule(fileFactories, linterHost, { options, rule }, { c
|
|
|
163
163
|
await ruleRuntime.teardown?.();
|
|
164
164
|
}
|
|
165
165
|
return {
|
|
166
|
-
languageReports: collectLanguageReports ? rule.language.getLanguageReports?.(file) ?? [] : [],
|
|
166
|
+
languageReports: collectLanguageReports ? rule.language.getLanguageReports?.(file, linterHost) ?? [] : [],
|
|
167
167
|
reports: reports.toSorted((a, b) => a.range.begin.raw - b.range.begin.raw || a.range.end.raw - b.range.end.raw)
|
|
168
168
|
};
|
|
169
169
|
}
|
|
@@ -175,17 +175,23 @@ var RuleTester = class {
|
|
|
175
175
|
#testerOptions;
|
|
176
176
|
constructor({ assertNoLanguageReports = true, defaults = {}, describe, diskBackedFSRoot, it, only, scope = globalThis, skip } = {}) {
|
|
177
177
|
const virtualRoot = diskBackedFSRoot == null ? void 0 : resolve(process.cwd(), diskBackedFSRoot, "_flint-rule-tester-virtual");
|
|
178
|
-
let baseHost = virtualRoot
|
|
178
|
+
let baseHost = virtualRoot == null ? void 0 : createEphemeralLinterHost(withRepositoryRoot(createDiskBackedLinterHost(virtualRoot), virtualRoot));
|
|
179
179
|
const { files: defaultFiles = {} } = defaults;
|
|
180
180
|
if (Object.keys(defaultFiles).length) {
|
|
181
|
-
const vfs = createVFSLinterHost(baseHost == null ? {
|
|
181
|
+
const vfs = createVFSLinterHost(baseHost == null ? {
|
|
182
|
+
caseSensitive: isFileSystemCaseSensitive(),
|
|
183
|
+
cwd: process.cwd()
|
|
184
|
+
} : { baseHost });
|
|
182
185
|
for (const [name, content] of Object.entries(defaultFiles)) {
|
|
183
186
|
const filePath = resolve(vfs.getCurrentDirectory(), name);
|
|
184
187
|
vfs.vfsUpsertFile(filePath, content);
|
|
185
188
|
}
|
|
186
189
|
baseHost = vfs;
|
|
187
190
|
}
|
|
188
|
-
this.#linterHost = createVFSLinterHost(baseHost == null ? {
|
|
191
|
+
this.#linterHost = createVFSLinterHost(baseHost == null ? {
|
|
192
|
+
caseSensitive: isFileSystemCaseSensitive(),
|
|
193
|
+
cwd: process.cwd()
|
|
194
|
+
} : { baseHost });
|
|
189
195
|
this.#fileFactories = new CachedFactory((language) => language.createFileFactory(this.#linterHost));
|
|
190
196
|
it = defaultTo(it, scope, "it");
|
|
191
197
|
if (!skip && "skip" in it && typeof it.skip === "function") skip = it.skip;
|
|
@@ -232,10 +238,7 @@ var RuleTester = class {
|
|
|
232
238
|
}
|
|
233
239
|
#itTestCase(testCase, seenTestCases, setup) {
|
|
234
240
|
let test = testCase.only ? this.#testerOptions.only : this.#testerOptions.it;
|
|
235
|
-
if (testCase.skip)
|
|
236
|
-
if ("skip" in test && typeof test.skip === "function") test = test.skip;
|
|
237
|
-
else test = this.#testerOptions.skip;
|
|
238
|
-
}
|
|
241
|
+
if (testCase.skip) test = "skip" in test && typeof test.skip === "function" ? test.skip : this.#testerOptions.skip;
|
|
239
242
|
test(testCase.name ?? ("files" in testCase ? JSON.stringify({
|
|
240
243
|
[testCase.fileName]: testCase.code,
|
|
241
244
|
...testCase.files
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flint.fyi/rule-tester",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "[Experimental] Rule unit tests for Flint.",
|
|
5
5
|
"homepage": "https://flint.fyi",
|
|
6
6
|
"repository": {
|
|
@@ -16,14 +16,15 @@
|
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"type": "module",
|
|
18
18
|
"exports": {
|
|
19
|
-
".": "./dist/index.mjs"
|
|
19
|
+
".": "./dist/index.mjs",
|
|
20
|
+
"./package.json": "./package.json"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|
|
22
23
|
"dist/"
|
|
23
24
|
],
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@flint.fyi/core": "^0.
|
|
26
|
-
"@flint.fyi/utils": "^0.16.
|
|
26
|
+
"@flint.fyi/core": "^0.28.0",
|
|
27
|
+
"@flint.fyi/utils": "^0.16.1",
|
|
27
28
|
"cached-factory": "^0.3.0",
|
|
28
29
|
"pathe": "^2.0.3"
|
|
29
30
|
},
|