44 行
1.8 KiB
JavaScript
44 行
1.8 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { mkdtempSync, rmSync } from 'node:fs'
|
|
import { createRequire } from 'node:module'
|
|
import { tmpdir } from 'node:os'
|
|
import path from 'node:path'
|
|
import test from 'node:test'
|
|
|
|
const require = createRequire(import.meta.url)
|
|
const { createModuleSerializer } = require('../metro')
|
|
|
|
function context(cacheFile, moduleId, moduleType, moduleIndex, reset = false) {
|
|
return {
|
|
XUQM_MODULE_CACHE_FILE: cacheFile,
|
|
XUQM_MODULE_ID: moduleId,
|
|
XUQM_MODULE_INDEX: String(moduleIndex),
|
|
XUQM_MODULE_TYPE: moduleType,
|
|
XUQM_RESET_MODULE_CACHE: reset ? 'true' : 'false',
|
|
}
|
|
}
|
|
|
|
test('Metro module ranges share startup/common and isolate every app or buz', () => {
|
|
const directory = mkdtempSync(path.join(tmpdir(), 'xuqm-metro-'))
|
|
const cacheFile = path.join(directory, 'ids.json')
|
|
try {
|
|
const startup = createModuleSerializer(context(cacheFile, 'startup', 'startup', 0, true))
|
|
const startupFactory = startup.createModuleIdFactory()
|
|
assert.equal(startupFactory('/runtime/prelude.js'), 0)
|
|
|
|
const common = createModuleSerializer(context(cacheFile, 'common', 'common', 1))
|
|
assert.equal(common.processModuleFilter({ path: '/runtime/prelude.js' }), false)
|
|
const commonFactory = common.createModuleIdFactory()
|
|
assert.equal(commonFactory('/runtime/prelude.js'), 0)
|
|
assert.equal(commonFactory('/shared/common.ts'), 1)
|
|
|
|
const app = createModuleSerializer(context(cacheFile, 'app', 'app', 2))
|
|
const buz = createModuleSerializer(context(cacheFile, 'buz-a', 'buz', 3))
|
|
assert.equal(app.processModuleFilter({ path: '/shared/common.ts' }), false)
|
|
assert.equal(app.createModuleIdFactory()('/app/entry.ts'), 30_000_000)
|
|
assert.equal(buz.createModuleIdFactory()('/buz/entry.ts'), 40_000_000)
|
|
} finally {
|
|
rmSync(directory, { force: true, recursive: true })
|
|
}
|
|
})
|