Skip to content

Commit e1d40c4

Browse files
Merge pull request APIDevTools#179 from APIDevTools/text/unixify-paths
Unixify paths in tests
2 parents 914c164 + 6149143 commit e1d40c4

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

test/specs/error-source/error-source.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("Report correct error source and path for", () => {
3838
expect(err.errors).to.containSubset([
3939
{
4040
name: ResolverError.name,
41-
source: path.abs("specs/error-source/broken-external.json"),
41+
source: path.unixify(path.abs("specs/error-source/broken-external.json")),
4242
path: ["components", "schemas", "testSchema", "properties", "test"],
4343
message: message => typeof message === "string",
4444
},
@@ -56,13 +56,13 @@ describe("Report correct error source and path for", () => {
5656
expect(err.errors).to.containSubset([
5757
{
5858
name: MissingPointerError.name,
59-
source: path.abs("specs/error-source/invalid-external.json"),
59+
source: path.unixify(path.abs("specs/error-source/invalid-external.json")),
6060
path: ["foo", "bar"],
6161
message: message => typeof message === "string",
6262
},
6363
{
6464
name: ResolverError.name,
65-
source: path.abs("specs/error-source/broken-external.json"),
65+
source: path.unixify(path.abs("specs/error-source/broken-external.json")),
6666
path: ["components", "schemas", "testSchema", "properties", "test"],
6767
message: message => typeof message === "string",
6868
},
@@ -80,7 +80,7 @@ describe("Report correct error source and path for", () => {
8080
expect(err.errors).to.containSubset([
8181
{
8282
name: InvalidPointerError.name,
83-
source: path.abs("specs/error-source/invalid-pointer.json"),
83+
source: path.unixify(path.abs("specs/error-source/invalid-pointer.json")),
8484
path: ["foo", "baz"],
8585
message: message => typeof message === "string",
8686
},

test/specs/invalid-pointers/invalid-pointers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("Schema with invalid pointers", () => {
3636
name: InvalidPointerError.name,
3737
message: "Invalid $ref pointer \"f\". Pointers must begin with \"#/\"",
3838
path: ["foo"],
39-
source: path.abs("specs/invalid-pointers/invalid.json"),
39+
source: path.unixify(path.abs("specs/invalid-pointers/invalid.json")),
4040
}
4141
]);
4242
}

test/utils/path.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ function filesystemPathHelpers () {
3636
return file;
3737
},
3838

39+
/**
40+
* Returns the path with normalized, UNIX-like, slashes. Disk letter is lower-cased, if present.
41+
*/
42+
unixify (file) {
43+
return file.replace(/\\/g, "/").replace(/^[A-Z](?=:\/)/, (letter) => letter.toLowerCase());
44+
},
45+
3946
/**
4047
* Returns the path of a file in the "test" directory as a URL.
4148
* (e.g. "file://path/to/json-schema-ref-parser/test/files...")
@@ -111,6 +118,12 @@ function urlPathHelpers () {
111118
return testsDir + encodePath(file);
112119
},
113120

121+
/**
122+
* Does nothing. Needed to comply with Filesystem path helpers.
123+
*/
124+
unixify (file) {
125+
return file;
126+
},
114127
/**
115128
* Returns the path of a file in the "test" directory as an absolute URL.
116129
* (e.g. "http://localhost/test/files/...")

0 commit comments

Comments
 (0)