bundle-split.client.spec.ts 1.0 KB

12345678910111213141516171819202122
  1. import { existsSync, readFileSync } from 'node:fs'
  2. import { join, resolve } from 'node:path'
  3. import { describe, expect, it } from 'vitest'
  4. const packageRoot = resolve(import.meta.dirname, '..')
  5. const entryPath = join(packageRoot, 'lib/client.js')
  6. const terminalPath = join(packageRoot, 'lib/client.terminal.js')
  7. describe('terminal client artifacts', () => {
  8. it.skipIf(!existsSync(entryPath))('keeps xterm outside the startup bundle', () => {
  9. expect(existsSync(terminalPath)).toBe(true)
  10. const entry = readFileSync(entryPath, 'utf8')
  11. const terminal = readFileSync(terminalPath, 'utf8')
  12. expect([...entry.matchAll(/require\.async\("(\.\/client[^"/]*\.js)"\)/gu)].map(match => match[1]))
  13. .toEqual(['./client.terminal.js'])
  14. expect(entry).not.toMatch(/\brequire\("\.\/client[^"/]*\.js"\)/u)
  15. expect([...terminal.matchAll(/require\("(\.\/client[^"/]*\.js)"\)/gu)].map(match => match[1]))
  16. .toEqual([])
  17. expect(entry).not.toContain('/@xterm+xterm@')
  18. expect(terminal).toContain('/@xterm+xterm@')
  19. })
  20. })