refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.
New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js
Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 07:21:03 +00:00
|
|
|
const assert = require('assert');
|
2026-04-27 11:57:28 +00:00
|
|
|
const esbuild = require('esbuild');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const os = require('os');
|
|
|
|
|
const path = require('path');
|
refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.
New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js
Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 07:21:03 +00:00
|
|
|
const { EventEmitter } = require('events');
|
2026-04-27 11:57:28 +00:00
|
|
|
|
2026-05-03 02:45:10 +00:00
|
|
|
// Polyfill Obsidian's `activeWindow` global for Node test runtime.
|
|
|
|
|
if (typeof globalThis.activeWindow === 'undefined') {
|
|
|
|
|
globalThis.activeWindow = globalThis;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 11:57:28 +00:00
|
|
|
// Load obsidian mock first — hooks Module._load so that require('obsidian')
|
|
|
|
|
// returns the mock for both us and the esbuild-bundled test-exports module.
|
2026-04-27 11:52:34 +00:00
|
|
|
const { getRequestUrlMock, setRequestUrlMock } = require('./obsidian-mock');
|
refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.
New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js
Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 07:21:03 +00:00
|
|
|
|
2026-04-27 11:57:28 +00:00
|
|
|
// Bundle test-exports.ts synchronously with obsidian marked as external.
|
|
|
|
|
// The bundled code will require('obsidian') at runtime, hitting our mock.
|
|
|
|
|
const repoRoot = path.join(__dirname, '..');
|
2026-05-15 16:22:31 +00:00
|
|
|
// Under c8, bundles must live inside the repo so c8 processes their coverage
|
|
|
|
|
// (it ignores scripts outside cwd before source-map remap). Otherwise /tmp.
|
|
|
|
|
const bundleParent = process.env.NODE_V8_COVERAGE
|
|
|
|
|
? fs.mkdirSync(path.join(repoRoot, '.test-bundles'), { recursive: true }) || path.join(repoRoot, '.test-bundles')
|
|
|
|
|
: os.tmpdir();
|
|
|
|
|
const tempDir = fs.mkdtempSync(path.join(bundleParent, 'parallel-reader-test-setup-'));
|
2026-04-27 11:57:28 +00:00
|
|
|
const outfile = path.join(tempDir, 'test-exports.cjs');
|
|
|
|
|
|
|
|
|
|
esbuild.buildSync({
|
|
|
|
|
entryPoints: [path.join(repoRoot, 'src/test-exports.ts')],
|
|
|
|
|
bundle: true,
|
|
|
|
|
platform: 'node',
|
|
|
|
|
format: 'cjs',
|
|
|
|
|
outfile,
|
|
|
|
|
external: ['obsidian'],
|
2026-05-15 16:22:31 +00:00
|
|
|
sourcemap: 'inline',
|
|
|
|
|
sourcesContent: true,
|
|
|
|
|
sourceRoot: repoRoot,
|
2026-04-27 11:57:28 +00:00
|
|
|
});
|
|
|
|
|
|
2026-05-15 16:22:31 +00:00
|
|
|
require('./coverage-sourcemap').fixInlineSourceMap(outfile, repoRoot);
|
|
|
|
|
|
2026-04-27 11:57:28 +00:00
|
|
|
const t = require(outfile);
|
refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.
New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js
Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 07:21:03 +00:00
|
|
|
|
2026-05-15 16:22:31 +00:00
|
|
|
// Clean up temp bundle on process exit. Skipped under c8 coverage:
|
|
|
|
|
// c8 reads V8 coverage at exit and needs the bundled file (with its
|
|
|
|
|
// inline source map) still on disk to remap back to src/*.ts.
|
2026-04-27 12:19:53 +00:00
|
|
|
process.on('exit', () => {
|
2026-05-15 16:22:31 +00:00
|
|
|
if (process.env.NODE_V8_COVERAGE) return;
|
2026-04-27 12:19:53 +00:00
|
|
|
try {
|
|
|
|
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
|
|
|
} catch (_) {
|
|
|
|
|
// Best-effort cleanup.
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.
New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js
Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 07:21:03 +00:00
|
|
|
function openAiCardsResponse(cards) {
|
|
|
|
|
const json = {
|
2026-04-27 11:53:35 +00:00
|
|
|
choices: [
|
|
|
|
|
{
|
|
|
|
|
message: {
|
|
|
|
|
content: JSON.stringify({ cards }),
|
|
|
|
|
},
|
refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.
New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js
Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 07:21:03 +00:00
|
|
|
},
|
2026-04-27 11:53:35 +00:00
|
|
|
],
|
refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.
New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js
Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 07:21:03 +00:00
|
|
|
};
|
|
|
|
|
return { status: 200, json, text: JSON.stringify(json) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const baseSettings = {
|
|
|
|
|
backend: 'api',
|
|
|
|
|
apiProvider: 'openai',
|
|
|
|
|
apiFormat: 'openai-chat',
|
|
|
|
|
apiBaseUrl: 'https://api.openai.com/v1',
|
|
|
|
|
apiAuthType: 'bearer',
|
|
|
|
|
apiKey: 'test-key',
|
|
|
|
|
apiMaxTokens: 4096,
|
|
|
|
|
model: 'openai/gpt-5.1',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
assert,
|
|
|
|
|
EventEmitter,
|
|
|
|
|
t,
|
|
|
|
|
baseSettings,
|
|
|
|
|
openAiCardsResponse,
|
2026-04-27 11:52:34 +00:00
|
|
|
getRequestUrlMock,
|
|
|
|
|
setRequestUrlMock,
|
refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.
New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js
Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 07:21:03 +00:00
|
|
|
};
|