built-package.spec.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { execFile } from 'node:child_process'
  2. import { existsSync } from 'node:fs'
  3. import { fileURLToPath } from 'node:url'
  4. import { promisify } from 'node:util'
  5. import { describe, expect, it } from 'vitest'
  6. const repoRoot = fileURLToPath(new URL('../../../../', import.meta.url))
  7. const builtBundle = fileURLToPath(new URL('../lib/index.js', import.meta.url))
  8. const execFileAsync = promisify(execFile)
  9. const probe = String.raw`
  10. import { resolve } from 'node:path';
  11. import { pathToFileURL } from 'node:url';
  12. const load = path => import(pathToFileURL(resolve(path)).href);
  13. const [{ Context }, { default: SessionStore }, { default: Sqlite }] = await Promise.all([
  14. load('vendor/cordis/lib/index.js'),
  15. load('packages/core/session/lib/index.js'),
  16. load('packages/session/session-persistence-sqlite/lib/index.js'),
  17. ]);
  18. const ctx = new Context();
  19. await ctx.plugin(SessionStore);
  20. await ctx.plugin(Sqlite, { path: ':memory:' });
  21. console.log(JSON.stringify(await ctx.sessionPersistence.list()));
  22. await ctx.fiber.dispose();
  23. `
  24. describe.skipIf(!existsSync(builtBundle))('SQLite built package', () => {
  25. it('loads packaged SQL resources from the published entry', async () => {
  26. const { stdout, stderr } = await execFileAsync(process.execPath, ['--input-type=module', '-e', probe], {
  27. cwd: repoRoot,
  28. timeout: 15_000,
  29. })
  30. expect(stderr).toBe('')
  31. expect(JSON.parse(stdout) as unknown).toEqual([])
  32. })
  33. })