diff --git a/packages/core/src/logger/__tests__/transports/github.test.mjs b/packages/core/src/logger/__tests__/transports/github.test.mjs index 82b669fa1..8eda7464d 100644 --- a/packages/core/src/logger/__tests__/transports/github.test.mjs +++ b/packages/core/src/logger/__tests__/transports/github.test.mjs @@ -1,3 +1,4 @@ +import { EOL } from 'node:os'; import { describe, it } from 'node:test'; import { LogLevel } from '../../constants.mjs'; @@ -24,7 +25,7 @@ describe('github', () => { t.assert.nthCalledWith( process.stdout.write, 1, - '::debug::[00:00:00.000] \x1B[34mDEBUG\x1B[39m: Test message\n' + '::debug::[00:00:00.000] \x1B[34mDEBUG\x1B[39m: Test message' + EOL ); }); @@ -47,7 +48,7 @@ describe('github', () => { t.assert.nthCalledWith( process.stdout.write, 1, - '::notice ::[00:00:00.000] \x1B[32mINFO\x1B[39m: Test message\n' + '::notice ::[00:00:00.000] \x1B[32mINFO\x1B[39m: Test message' + EOL ); }); @@ -71,7 +72,7 @@ describe('github', () => { t.assert.nthCalledWith( process.stdout.write, 1, - '::error ::[00:00:00.000] \x1B[35mERROR\x1B[39m: Test message\n' + '::error ::[00:00:00.000] \x1B[35mERROR\x1B[39m: Test message' + EOL ); }); @@ -95,7 +96,7 @@ describe('github', () => { t.assert.nthCalledWith( process.stdout.write, 1, - '::error ::[00:00:00.000] \x1B[31mFATAL\x1B[39m: Test message\n' + '::error ::[00:00:00.000] \x1B[31mFATAL\x1B[39m: Test message' + EOL ); }); @@ -128,7 +129,8 @@ describe('github', () => { t.assert.nthCalledWith( process.stdout.write, 1, - '::notice file=test.md,line=1,endLine=1::[00:00:00.000] \x1B[32mINFO\x1B[39m: Test message\n' + '::notice file=test.md,line=1,endLine=1::[00:00:00.000] \x1B[32mINFO\x1B[39m: Test message' + + EOL ); }); @@ -162,7 +164,8 @@ describe('github', () => { t.assert.nthCalledWith( process.stdout.write, 1, - '::notice file=a%2Cb%3Ac%25.md,line=1,endLine=2::[00:00:00.000] \x1B[32mINFO\x1B[39m: 100%25: a, b%0D%0Ac\n' + '::notice file=a%2Cb%3Ac%25.md,line=1,endLine=2::[00:00:00.000] \x1B[32mINFO\x1B[39m: 100%25: a, b%0D%0Ac' + + EOL ); }); @@ -186,7 +189,8 @@ describe('github', () => { t.assert.nthCalledWith( process.stdout.write, 1, - '::notice ::[00:00:00.000] \x1B[32mINFO\x1B[39m (child1): Test message\n' + '::notice ::[00:00:00.000] \x1B[32mINFO\x1B[39m (child1): Test message' + + EOL ); }); @@ -210,7 +214,7 @@ describe('github', () => { t.assert.nthCalledWith( process.stdout.write, 1, - '::notice ::[00:00:00.000] INFO: Test message\n' + '::notice ::[00:00:00.000] INFO: Test message' + EOL ); }); }); diff --git a/packages/core/src/utils/loaders.mjs b/packages/core/src/utils/loaders.mjs index b2a7fe78a..83f3922d4 100644 --- a/packages/core/src/utils/loaders.mjs +++ b/packages/core/src/utils/loaders.mjs @@ -57,14 +57,20 @@ export const resolveSpecifier = (specifier, filePath) => { * @returns {Promise} The imported module */ export const importFromURL = async url => { - const useJSONAssertion = extname(String(url)) === '.json'; + const options = + extname(String(url)) === '.json' ? { with: { type: 'json' } } : {}; - const parsed = toParsedURL(url); + let target = toParsedURL(url); - const imported = await import( - parsed ?? pathToFileURL(isAbsolute(url) ? url : join(process.cwd(), url)), - useJSONAssertion ? { with: { type: 'json' } } : {} - ); + // An absolute Windows path parses as a URL with its drive letter as the + // protocol, so check for one first + if (typeof url === 'string' && isAbsolute(url)) { + target = pathToFileURL(url); + } else if (!target) { + target = pathToFileURL(join(process.cwd(), String(url))); + } + + const imported = await import(target, options); return imported.default ?? imported; }; diff --git a/packages/react/src/html/utils/__tests__/config.test.mjs b/packages/react/src/html/utils/__tests__/config.test.mjs index a4515e633..b55624c2a 100644 --- a/packages/react/src/html/utils/__tests__/config.test.mjs +++ b/packages/react/src/html/utils/__tests__/config.test.mjs @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { createRequire } from 'node:module'; import { describe, it, mock } from 'node:test'; -import { fileURLToPath } from 'node:url'; +import { fileURLToPath, pathToFileURL } from 'node:url'; import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs'; import { loadMarkdownPlugins } from '@doc-kit/core/utils/markdown/plugins.mjs'; @@ -12,7 +12,9 @@ const core = createRequire( fileURLToPath(import.meta.resolve('@doc-kit/core/package.json')) ); -mock.module(core.resolve('shiki/langs'), { +// `mock.module` resolves its specifier as a module URL, so the path +// `core.resolve` returns needs converting (an absolute one, on Windows) +mock.module(pathToFileURL(core.resolve('shiki/langs')).href, { exports: { bundledLanguagesInfo: [ { id: 'javascript', name: 'JavaScript', aliases: ['js'] }, diff --git a/packages/typedoc/src/__tests__/index.test.mjs b/packages/typedoc/src/__tests__/index.test.mjs index 00fc0625f..8074b5805 100644 --- a/packages/typedoc/src/__tests__/index.test.mjs +++ b/packages/typedoc/src/__tests__/index.test.mjs @@ -8,7 +8,8 @@ import { Application, OptionDefaults, ReflectionKind } from 'typedoc'; import { load } from '../index.mjs'; -const FIXTURES = join(import.meta.dirname, 'fixtures'); +// TypeDoc's entry point globs only accept posix path separators +const FIXTURES = join(import.meta.dirname, 'fixtures').replaceAll('\\', '/'); /** * Converts the fixture and writes it as doc-kit Markdown into a temporary @@ -22,8 +23,8 @@ const generateFixture = async options => { const app = await Application.bootstrapWithPlugins({ plugin: [load], - entryPoints: [join(FIXTURES, 'index.ts'), join(FIXTURES, 'utils.ts')], - tsconfig: join(FIXTURES, 'tsconfig.json'), + entryPoints: [`${FIXTURES}/index.ts`, `${FIXTURES}/utils.ts`], + tsconfig: `${FIXTURES}/tsconfig.json`, readme: 'none', logLevel: 'Error', blockTags: [...OptionDefaults.blockTags, '@kind'],