49 lines
2.4 KiB
JavaScript
49 lines
2.4 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readFile } from 'node:fs/promises'
|
|
|
|
const readMain = path => readFile(new URL('../' + path, import.meta.url), 'utf8')
|
|
const readChild = path => readFile(new URL('../../sansheng-better-sidebar/' + path, import.meta.url), 'utf8')
|
|
|
|
test('bettersidebar 拆包:主插件提供工作台服务,不再直接探测 betterSidebar', async () => {
|
|
const source = await readMain('src/client/index.js')
|
|
assert.match(source, /ctx\.provide\('sanshengWorkbench'/)
|
|
assert.match(source, /attachRightTabOpener/)
|
|
assert.match(source, /releaseNativeRightTab/)
|
|
assert.match(source, /restoreNativeRightTab/)
|
|
assert.match(source, /function tryOpenRightTab/)
|
|
assert.doesNotMatch(source, /get\('betterSidebar'\)/)
|
|
assert.doesNotMatch(source, /bs\.registerTab/)
|
|
const built = await readMain('client.js')
|
|
assert.match(built, /sanshengWorkbench/)
|
|
assert.doesNotMatch(built, /get\("betterSidebar"\)|get\('betterSidebar'\)/)
|
|
})
|
|
|
|
test('bettersidebar 拆包:子插件清单、服务端入口与构建产物齐全', async () => {
|
|
const pkg = JSON.parse(await readChild('package.json'))
|
|
assert.equal(pkg.name, 'dsh-sansheng-liubu-better-sidebar')
|
|
assert.equal(pkg.exports['./client'], './client.js')
|
|
assert.equal(pkg.dsh.client.platform, 'web')
|
|
assert.ok(pkg.dsh.client.inject.includes('dsh-sansheng-liubu'))
|
|
assert.equal(pkg.dsh.bundle.patch, './cordis.patch.yml')
|
|
const patch = await readChild('cordis.patch.yml')
|
|
assert.match(patch, /id: sansheng-better-sidebar/)
|
|
assert.match(patch, /name: 'dsh-sansheng-liubu-better-sidebar'/)
|
|
const server = await readChild('index.js')
|
|
assert.match(server, /export const inject = \[\]/)
|
|
assert.match(server, /export function apply/)
|
|
})
|
|
|
|
test('bettersidebar 拆包:子插件向 Better Sidebar 注册同一工作台并先释放原生回退', async () => {
|
|
const source = await readChild('src/client/index.js')
|
|
assert.match(source, /export const inject = \['betterSidebar', 'sanshengWorkbench'\]/)
|
|
assert.match(source, /bs\.registerTab/)
|
|
assert.match(source, /single: true/)
|
|
assert.match(source, /bs\.openTab/)
|
|
assert.match(source, /releaseNativeRightTab/)
|
|
assert.match(source, /restoreNativeFallback/)
|
|
const built = await readChild('client.js')
|
|
assert.match(built, /id: "dsh-sansheng-liubu-better-sidebar"/)
|
|
assert.match(built, /var inject = \["betterSidebar", "sanshengWorkbench"\]/)
|
|
})
|