mirror of
https://github.com/fancive/obsidian-parallel-reader.git
synced 2026-07-22 06:53:43 +00:00
build: remove __test barrel from production bundle
Tests now load src/test-exports.ts via esbuild buildSync instead of importing __test from the production main.js. This removes ~60 internal symbols and all test-only module code from the shipped plugin bundle. Change-Id: I2caf5232f6894c7514215e1751f2e268b74d7dc4
This commit is contained in:
parent
0bf5ab12b1
commit
f5f974fd74
4 changed files with 26 additions and 13 deletions
2
main.ts
2
main.ts
|
|
@ -32,7 +32,6 @@ import { createRafThrottledHandler, visibleTopProbeY } from './src/scroll';
|
|||
import { cacheEntryMatches, DEFAULT_SETTINGS, normalizeSettings } from './src/settings';
|
||||
import { ParallelReaderSettingTab } from './src/settings-tab';
|
||||
import type { StreamProgress } from './src/streaming';
|
||||
import * as testExports from './src/test-exports';
|
||||
import type {
|
||||
CacheEntry,
|
||||
ObsidianEditorWithCm,
|
||||
|
|
@ -690,4 +689,3 @@ class ParallelReaderPlugin extends Plugin {
|
|||
}
|
||||
|
||||
export default ParallelReaderPlugin;
|
||||
export const __test = testExports;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
const assert = require('assert');
|
||||
require('./obsidian-mock');
|
||||
const { assert, t } = require('./test-setup');
|
||||
|
||||
const { GenerationJobAlreadyRunningError, GenerationJobCancelledError, GenerationJobManager, classifyGenerationError } =
|
||||
require('../main.js').__test;
|
||||
t;
|
||||
|
||||
async function testSingleFlightAndCleanup() {
|
||||
const manager = new GenerationJobManager();
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
const assert = require('assert');
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
require('./obsidian-mock');
|
||||
|
||||
const plugin = require('../main.js');
|
||||
const t = plugin.__test;
|
||||
|
||||
assert.ok(t, 'test helpers should be exported');
|
||||
const { assert, t } = require('./test-setup');
|
||||
const mainSource = fs.readFileSync(path.join(__dirname, '..', 'main.ts'), 'utf8');
|
||||
const viewSource = fs.readFileSync(path.join(__dirname, '..', 'src', 'view.ts'), 'utf8');
|
||||
assert.ok(!/\basync\s+onOpen\s*\(/.test(viewSource), 'ParallelReaderView.onOpen should not be async without await');
|
||||
|
|
|
|||
|
|
@ -1,8 +1,30 @@
|
|||
const assert = require('assert');
|
||||
const esbuild = require('esbuild');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { EventEmitter } = require('events');
|
||||
|
||||
// Load obsidian mock first — hooks Module._load so that require('obsidian')
|
||||
// returns the mock for both us and the esbuild-bundled test-exports module.
|
||||
const { getRequestUrlMock, setRequestUrlMock } = require('./obsidian-mock');
|
||||
|
||||
const t = require('../main.js').__test;
|
||||
// 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, '..');
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'parallel-reader-test-setup-'));
|
||||
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'],
|
||||
});
|
||||
|
||||
const t = require(outfile);
|
||||
|
||||
function openAiCardsResponse(cards) {
|
||||
const json = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue