diff --git a/index.js b/index.js index 6fc8e9d..6dbdfcf 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ import { readFileSync } from 'node:fs' import { readFile } from 'node:fs/promises' +import { fileURLToPath } from 'node:url' import Ajv04 from 'ajv-draft-04' import addFormats from 'ajv-formats' import Ajv2020 from 'ajv/dist/2020.js' @@ -14,7 +15,7 @@ const ajvVersions = { const inlinedRefs = 'x-inlined-refs' function localFile (file) { - return new URL(file, import.meta.url).pathname + return fileURLToPath(new URL(file, import.meta.url)) } function importJSON (file) { diff --git a/test/check-versions.js b/test/check-versions.js index 032fb9d..dfd50f8 100644 --- a/test/check-versions.js +++ b/test/check-versions.js @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert/strict' import { createHash } from 'node:crypto' import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' import { readdir } from 'node:fs/promises' import { test } from 'node:test' import { Validator } from '../index.js' @@ -8,8 +9,8 @@ import { Snapshot } from './snapshot.js' const supportedVersions = Validator.supportedVersions -function localPath (path) { - return new URL(path, import.meta.url).pathname +function localPath (fileName) { + return fileURLToPath(new URL(fileName, import.meta.url)) } const snapShotFile = localPath('snapshots-check-versions.json') diff --git a/test/validation-refs.test.js b/test/validation-refs.test.js index 4e9a82a..d294170 100644 --- a/test/validation-refs.test.js +++ b/test/validation-refs.test.js @@ -1,13 +1,14 @@ import { strict as assert } from 'node:assert/strict' import { test } from 'node:test' +import { fileURLToPath } from 'node:url' import { Validator } from '../index.js' -function localFile (file) { - return new URL(file, import.meta.url).pathname +function localPath (fileName) { + return fileURLToPath(new URL(fileName, import.meta.url)) } -const invalidRefsSpec = localFile('./validation/invalid-refs.yaml') -const recursiveRefsSpec = localFile('./validation/openapi-recursive.v3.json') +const invalidRefsSpec = localPath('./validation/invalid-refs.yaml') +const recursiveRefsSpec = localPath('./validation/openapi-recursive.v3.json') test('invalid refs in YAML fail validation', async (t) => { const validator = new Validator() diff --git a/test/validation.test.js b/test/validation.test.js index a4f2478..e70c14b 100644 --- a/test/validation.test.js +++ b/test/validation.test.js @@ -1,11 +1,12 @@ import { strict as assert } from 'node:assert/strict' import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' import { readFile } from 'node:fs/promises' import { test } from 'node:test' import { Validator } from '../index.js' -function localFile (file) { - return new URL(file, import.meta.url).pathname +function localFile (path) { + return fileURLToPath(new URL(path, import.meta.url)) } function importJSON (file) {