From 34b9d518648d19630aaad2e7cfecff14c332f29b Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Thu, 3 Dec 2026 14:07:51 +0800 Subject: [PATCH 1/2] fix: make the tests pass on Windows --- .../__tests__/transports/github.test.mjs | 20 +++++++++++-------- packages/core/src/utils/loaders.mjs | 9 +++++++-- .../src/html/utils/__tests__/config.test.mjs | 6 ++++-- packages/typedoc/src/__tests__/index.test.mjs | 7 ++++--- 4 files changed, 27 insertions(+), 15 deletions(-) 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..f52ffa3ab 100644 --- a/packages/core/src/utils/loaders.mjs +++ b/packages/core/src/utils/loaders.mjs @@ -59,10 +59,15 @@ export const resolveSpecifier = (specifier, filePath) => { export const importFromURL = async url => { const useJSONAssertion = extname(String(url)) === '.json'; - const parsed = toParsedURL(url); + // An absolute Windows path parses as a URL with its drive letter as the + // protocol, so check for one first + const target = + typeof url === 'string' && isAbsolute(url) + ? pathToFileURL(url) + : (toParsedURL(url) ?? pathToFileURL(join(process.cwd(), String(url)))); const imported = await import( - parsed ?? pathToFileURL(isAbsolute(url) ? url : join(process.cwd(), url)), + target, useJSONAssertion ? { with: { type: 'json' } } : {} ); 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'], From e765f62bcbc4689c804b574d8af5b5addf3869e7 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 4 Dec 2026 07:28:55 +0800 Subject: [PATCH 2/2] fix: update --- packages/core/src/utils/loaders.mjs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/core/src/utils/loaders.mjs b/packages/core/src/utils/loaders.mjs index f52ffa3ab..83f3922d4 100644 --- a/packages/core/src/utils/loaders.mjs +++ b/packages/core/src/utils/loaders.mjs @@ -57,19 +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' } } : {}; + + let target = toParsedURL(url); // An absolute Windows path parses as a URL with its drive letter as the // protocol, so check for one first - const target = - typeof url === 'string' && isAbsolute(url) - ? pathToFileURL(url) - : (toParsedURL(url) ?? pathToFileURL(join(process.cwd(), String(url)))); + if (typeof url === 'string' && isAbsolute(url)) { + target = pathToFileURL(url); + } else if (!target) { + target = pathToFileURL(join(process.cwd(), String(url))); + } - const imported = await import( - target, - useJSONAssertion ? { with: { type: 'json' } } : {} - ); + const imported = await import(target, options); return imported.default ?? imported; };