Skip to content

Commit 09bfa0d

Browse files
committed
Fixes for running on windows
1 parent ea36d45 commit 09bfa0d

9 files changed

+130
-125
lines changed

src/__snapshots__/coverage-map-service.test.js.snap

Lines changed: 80 additions & 80 deletions
Large diffs are not rendered by default.

src/__snapshots__/test-coverage-evaluation-plugin.test.js.snap

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`TestCoverageEvaluationPlugin > both branches of a branching keyword 1`] = `
44
{
5-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
5+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
66
"b": {
77
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/type": [
88
1,
@@ -76,7 +76,7 @@ exports[`TestCoverageEvaluationPlugin > both branches of a branching keyword 1`]
7676
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#",
7777
},
7878
},
79-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
79+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
8080
"s": {
8181
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 2,
8282
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/type": 2,
@@ -109,7 +109,7 @@ exports[`TestCoverageEvaluationPlugin > both branches of a branching keyword 1`]
109109

110110
exports[`TestCoverageEvaluationPlugin > embedded schema 1`] = `
111111
{
112-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
112+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
113113
"b": {
114114
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/$defs/foo/type": [
115115
0,
@@ -233,7 +233,7 @@ exports[`TestCoverageEvaluationPlugin > embedded schema 1`] = `
233233
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/properties/foo",
234234
},
235235
},
236-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
236+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
237237
"s": {
238238
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 1,
239239
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/$defs/foo": 1,
@@ -310,7 +310,7 @@ exports[`TestCoverageEvaluationPlugin > embedded schema 1`] = `
310310

311311
exports[`TestCoverageEvaluationPlugin > failing branching keyword 1`] = `
312312
{
313-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
313+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
314314
"b": {
315315
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/type": [
316316
1,
@@ -384,7 +384,7 @@ exports[`TestCoverageEvaluationPlugin > failing branching keyword 1`] = `
384384
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#",
385385
},
386386
},
387-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
387+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
388388
"s": {
389389
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 1,
390390
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/type": 1,
@@ -417,7 +417,7 @@ exports[`TestCoverageEvaluationPlugin > failing branching keyword 1`] = `
417417

418418
exports[`TestCoverageEvaluationPlugin > non-branching keyword 1`] = `
419419
{
420-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
420+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
421421
"b": {},
422422
"branchMap": {},
423423
"f": {
@@ -449,7 +449,7 @@ exports[`TestCoverageEvaluationPlugin > non-branching keyword 1`] = `
449449
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#",
450450
},
451451
},
452-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
452+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
453453
"s": {
454454
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 1,
455455
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/title": 1,
@@ -482,7 +482,7 @@ exports[`TestCoverageEvaluationPlugin > non-branching keyword 1`] = `
482482

483483
exports[`TestCoverageEvaluationPlugin > non-statement keyword 1`] = `
484484
{
485-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
485+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
486486
"b": {},
487487
"branchMap": {},
488488
"f": {
@@ -514,7 +514,7 @@ exports[`TestCoverageEvaluationPlugin > non-statement keyword 1`] = `
514514
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#",
515515
},
516516
},
517-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
517+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
518518
"s": {
519519
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 1,
520520
},
@@ -536,7 +536,7 @@ exports[`TestCoverageEvaluationPlugin > non-statement keyword 1`] = `
536536

537537
exports[`TestCoverageEvaluationPlugin > passing branching keyword 1`] = `
538538
{
539-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
539+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
540540
"b": {
541541
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/type": [
542542
0,
@@ -610,7 +610,7 @@ exports[`TestCoverageEvaluationPlugin > passing branching keyword 1`] = `
610610
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#",
611611
},
612612
},
613-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
613+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
614614
"s": {
615615
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 1,
616616
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/type": 1,
@@ -643,7 +643,7 @@ exports[`TestCoverageEvaluationPlugin > passing branching keyword 1`] = `
643643

644644
exports[`TestCoverageEvaluationPlugin > reference to a non-file schema 1`] = `
645645
{
646-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
646+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
647647
"b": {},
648648
"branchMap": {},
649649
"f": {
@@ -675,7 +675,7 @@ exports[`TestCoverageEvaluationPlugin > reference to a non-file schema 1`] = `
675675
"name": "https://example.com/subject#",
676676
},
677677
},
678-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
678+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
679679
"s": {
680680
"https://example.com/subject#": 1,
681681
"https://example.com/subject#/$ref": 1,
@@ -708,7 +708,7 @@ exports[`TestCoverageEvaluationPlugin > reference to a non-file schema 1`] = `
708708

709709
exports[`TestCoverageEvaluationPlugin > root schema 1`] = `
710710
{
711-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
711+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
712712
"b": {},
713713
"branchMap": {},
714714
"f": {
@@ -740,7 +740,7 @@ exports[`TestCoverageEvaluationPlugin > root schema 1`] = `
740740
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#",
741741
},
742742
},
743-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
743+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
744744
"s": {
745745
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 1,
746746
},
@@ -762,7 +762,7 @@ exports[`TestCoverageEvaluationPlugin > root schema 1`] = `
762762

763763
exports[`TestCoverageEvaluationPlugin > sub-schema 1`] = `
764764
{
765-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
765+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
766766
"b": {},
767767
"branchMap": {},
768768
"f": {
@@ -819,7 +819,7 @@ exports[`TestCoverageEvaluationPlugin > sub-schema 1`] = `
819819
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/properties/foo",
820820
},
821821
},
822-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
822+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
823823
"s": {
824824
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 1,
825825
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/properties": 1,
@@ -863,7 +863,7 @@ exports[`TestCoverageEvaluationPlugin > sub-schema 1`] = `
863863

864864
exports[`TestCoverageEvaluationPlugin > sub-schema that isn't evaluated 1`] = `
865865
{
866-
"/.test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
866+
".test-coverage-evaluation-plugin-fixtures/subject.schema.json": {
867867
"b": {},
868868
"branchMap": {},
869869
"f": {
@@ -920,7 +920,7 @@ exports[`TestCoverageEvaluationPlugin > sub-schema that isn't evaluated 1`] = `
920920
"name": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/properties/foo",
921921
},
922922
},
923-
"path": "/.test-coverage-evaluation-plugin-fixtures/subject.schema.json",
923+
"path": ".test-coverage-evaluation-plugin-fixtures/subject.schema.json",
924924
"s": {
925925
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#": 1,
926926
".test-coverage-evaluation-plugin-fixtures/subject.schema.json#/properties": 1,

src/coverage-map-service.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFile } from "node:fs/promises";
22
import { extname } from "node:path";
3+
import { pathToFileURL } from "node:url";
34
import { compile, getKeyword, getSchema } from "@hyperjump/json-schema/experimental";
45
import { jrefTypeOf, Reference } from "@hyperjump/browser/jref";
56
import * as JsonPointer from "@hyperjump/json-pointer";
@@ -40,7 +41,8 @@ export class CoverageMapService {
4041

4142
/** @type (schemaPath: string) => Promise<string> */
4243
async addFromFile(schemaPath) {
43-
const schema = await getSchema(schemaPath);
44+
const schemaUri = pathToFileURL(schemaPath).toString();
45+
const schema = await getSchema(schemaUri);
4446
const compiledSchema = await compile(schema);
4547
const tree = await this.#parseToAst(schemaPath);
4648

src/test-coverage-evaluation-plugin.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("TestCoverageEvaluationPlugin", () => {
4343
"$schema": "https://json-schema.org/draft/2020-12/schema"
4444
}`);
4545
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
46-
await validate(fixturePath, 42, { plugins: [testCoveragePlugin] });
46+
await validate(`${fixtureDirectory}/subject.schema.json`, 42, { plugins: [testCoveragePlugin] });
4747

4848
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
4949
});
@@ -54,7 +54,7 @@ describe("TestCoverageEvaluationPlugin", () => {
5454
"type": "number"
5555
}`);
5656
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
57-
await validate(fixturePath, 42, { plugins: [testCoveragePlugin] });
57+
await validate(`${fixtureDirectory}/subject.schema.json`, 42, { plugins: [testCoveragePlugin] });
5858

5959
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
6060
});
@@ -65,7 +65,7 @@ describe("TestCoverageEvaluationPlugin", () => {
6565
"type": "number"
6666
}`);
6767
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
68-
await validate(fixturePath, "foo", { plugins: [testCoveragePlugin] });
68+
await validate(`${fixtureDirectory}/subject.schema.json`, "foo", { plugins: [testCoveragePlugin] });
6969

7070
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
7171
});
@@ -76,8 +76,8 @@ describe("TestCoverageEvaluationPlugin", () => {
7676
"type": "number"
7777
}`);
7878
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
79-
await validate(fixturePath, 42, { plugins: [testCoveragePlugin] });
80-
await validate(fixturePath, "foo", { plugins: [testCoveragePlugin] });
79+
await validate(`${fixtureDirectory}/subject.schema.json`, 42, { plugins: [testCoveragePlugin] });
80+
await validate(`${fixtureDirectory}/subject.schema.json`, "foo", { plugins: [testCoveragePlugin] });
8181

8282
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
8383
});
@@ -88,7 +88,7 @@ describe("TestCoverageEvaluationPlugin", () => {
8888
"title": "Foo"
8989
}`);
9090
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
91-
await validate(fixturePath, 42, { plugins: [testCoveragePlugin] });
91+
await validate(`${fixtureDirectory}/subject.schema.json`, 42, { plugins: [testCoveragePlugin] });
9292

9393
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
9494
});
@@ -99,7 +99,7 @@ describe("TestCoverageEvaluationPlugin", () => {
9999
"$comment": "Foo"
100100
}`);
101101
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
102-
await validate(fixturePath, 42, { plugins: [testCoveragePlugin] });
102+
await validate(`${fixtureDirectory}/subject.schema.json`, 42, { plugins: [testCoveragePlugin] });
103103

104104
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
105105
});
@@ -112,7 +112,7 @@ describe("TestCoverageEvaluationPlugin", () => {
112112
}
113113
}`);
114114
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
115-
await validate(fixturePath, { foo: 42 }, { plugins: [testCoveragePlugin] });
115+
await validate(`${fixtureDirectory}/subject.schema.json`, { foo: 42 }, { plugins: [testCoveragePlugin] });
116116

117117
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
118118
});
@@ -125,7 +125,7 @@ describe("TestCoverageEvaluationPlugin", () => {
125125
}
126126
}`);
127127
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
128-
await validate(fixturePath, 42, { plugins: [testCoveragePlugin] });
128+
await validate(`${fixtureDirectory}/subject.schema.json`, 42, { plugins: [testCoveragePlugin] });
129129

130130
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
131131
});
@@ -141,7 +141,7 @@ describe("TestCoverageEvaluationPlugin", () => {
141141
}
142142
}`);
143143
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
144-
await validate(fixturePath, { foo: 42 }, { plugins: [testCoveragePlugin] });
144+
await validate(`${fixtureDirectory}/subject.schema.json`, { foo: 42 }, { plugins: [testCoveragePlugin] });
145145

146146
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
147147
});
@@ -154,7 +154,7 @@ describe("TestCoverageEvaluationPlugin", () => {
154154
"$ref": "/foo"
155155
}`);
156156
const testCoveragePlugin = new TestCoverageEvaluationPlugin(coverageMapService);
157-
await validate(fixturePath, 42, { plugins: [testCoveragePlugin] });
157+
await validate(`${fixtureDirectory}/subject.schema.json`, 42, { plugins: [testCoveragePlugin] });
158158

159159
expect(censorCoverageMap(testCoveragePlugin.coverage)).toMatchSnapshot();
160160
});

src/test-utils.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { cwd } from "node:process";
2+
import { pathToFileURL } from "node:url";
23

34
/**
45
* @import { CoverageMapData } from "istanbul-lib-coverage"
56
*/
67

8+
const root = pathToFileURL(cwd()).toString();
9+
710
/** @type (coverageMap: CoverageMapData) => CoverageMapData */
811
export const censorCoverageMap = (coverageMap) => {
912
/** @type CoverageMapData */
1013
const censoredCoverageMap = {};
1114
for (const filePath in coverageMap) {
1215
const fileCoverageData = coverageMap[filePath];
1316

14-
const censoredFilePath = filePath.slice(cwd().length);
17+
const censoredFilePath = pathToFileURL(filePath).toString().slice(root.length + 1);
1518
censoredCoverageMap[censoredFilePath] = fileCoverageData;
1619

1720
for (const key in fileCoverageData) {
@@ -27,7 +30,7 @@ export const censorCoverageMap = (coverageMap) => {
2730
case "f":
2831
for (const schemaUri in fileCoverageData[key]) {
2932
if (schemaUri.startsWith("file:")) {
30-
const censoredSchemaUri = schemaUri.slice(cwd().length + 8);
33+
const censoredSchemaUri = schemaUri.slice(root.length + 1);
3134
fileCoverageData[key][censoredSchemaUri] = fileCoverageData[key][schemaUri];
3235
delete fileCoverageData[key][schemaUri];
3336

@@ -41,7 +44,7 @@ export const censorCoverageMap = (coverageMap) => {
4144
}
4245
}
4346
const [filePath] = Object.keys(coverageMap);
44-
const censoredFilePath = filePath.slice(cwd().length);
47+
const censoredFilePath = pathToFileURL(filePath).toString().slice(root.length + 1);
4548
coverageMap[filePath].path = censoredFilePath;
4649
return { [censoredFilePath]: coverageMap[filePath] };
4750
};

src/vitest/build-coverage-maps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync } from "node:fs";
22
import { readFile } from "node:fs/promises";
3-
import { resolve } from "node:path";
3+
import { join, resolve } from "node:path";
44
import { glob } from "tinyglobby";
55
import ignore from "ignore";
66
import { registerSchema } from "./json-schema-matchers.js";
@@ -14,7 +14,7 @@ import { FileCoverageMapService } from "./file-coverage-map-service.js";
1414
export const setup = async (projects) => {
1515
const config = projects.vitest.config;
1616

17-
const coverageService = new FileCoverageMapService(".json-schema-coverage/maps");
17+
const coverageService = new FileCoverageMapService(join(".json-schema-coverage", "maps"));
1818

1919
// If --project filter is set pick only roots of resolved projects
2020
const roots = config.project?.length

src/vitest/coverage-provider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class JsonSchemaCoverageProvider {
4040
globCache = new Map();
4141

4242
coverageFilesDirectory = ".json-schema-coverage";
43-
coverageService = new FileCoverageMapService(".json-schema-coverage/maps");
43+
coverageService = new FileCoverageMapService(path.join(".json-schema-coverage", "maps"));
4444

4545
/** @type CoverageProvider["initialize"] */
4646
initialize(ctx) {
@@ -65,7 +65,7 @@ class JsonSchemaCoverageProvider {
6565
reporter: resolveCoverageReporters(config.reporter || coverageConfigDefaults.reporter)
6666
};
6767

68-
const buildScriptPath = path.resolve(import.meta.dirname, "./build-coverage-maps.js");
68+
const buildScriptPath = path.resolve(import.meta.dirname, "build-coverage-maps.js");
6969
/** @type string[] */ (ctx.config.globalSetup).push(buildScriptPath);
7070
}
7171

src/vitest/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("Worksheet", () => {
6262
await addSchemaFile("subject.schema.json", `{
6363
"$schema": "https://json-schema.org/draft/2020-12/schema"
6464
}`);
65-
await expect(42).to.matchJsonSchema(fixturePath);
65+
await expect(42).to.matchJsonSchema(`${fixtureDirectory}/subject.schema.json`);
6666
});
6767

6868
test("match with registered schema's $id (yaml)", async () => {
@@ -78,7 +78,7 @@ $schema: 'https://json-schema.org/draft/2020-12/schema'
7878
await addSchemaFile("subject.schema.yaml", `
7979
$schema: 'https://json-schema.org/draft/2020-12/schema'
8080
`);
81-
await expect(42).to.matchJsonSchema(fixturePath);
81+
await expect(42).to.matchJsonSchema(`${fixtureDirectory}/subject.schema.yaml`);
8282
});
8383

8484
test("match with registered schema's $id (yml)", async () => {
@@ -94,7 +94,7 @@ $schema: 'https://json-schema.org/draft/2020-12/schema'
9494
await addSchemaFile("subject.schema.yml", `
9595
$schema: 'https://json-schema.org/draft/2020-12/schema'
9696
`);
97-
await expect(42).to.matchJsonSchema(fixturePath);
97+
await expect(42).to.matchJsonSchema(`${fixtureDirectory}/subject.schema.yml`);
9898
});
9999

100100
test("registered with draft-04 id", async () => {

0 commit comments

Comments
 (0)