runtime-manager-extract.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
  2. import { tmpdir } from 'node:os'
  3. import { join } from 'node:path'
  4. import * as tar from 'tar'
  5. import { afterEach, describe, expect, it } from 'vitest'
  6. describe('desktop runtime archive extraction', () => {
  7. let tempRoot: string | null = null
  8. afterEach(() => {
  9. if (tempRoot) rmSync(tempRoot, { recursive: true, force: true })
  10. tempRoot = null
  11. })
  12. it('extracts gzip tar archives through the Node tar library', async () => {
  13. tempRoot = mkdtempSync(join(tmpdir(), 'hermes-runtime-extract-'))
  14. const source = join(tempRoot, 'source')
  15. const target = join(tempRoot, 'target')
  16. const archive = join(tempRoot, 'runtime.tar.gz.download')
  17. mkdirSync(join(source, 'python', 'Scripts'), { recursive: true })
  18. writeFileSync(join(source, 'python', 'Scripts', 'hermes.exe'), 'launcher', 'utf-8')
  19. await tar.c({
  20. file: archive,
  21. cwd: source,
  22. gzip: true,
  23. }, ['python'])
  24. mkdirSync(target)
  25. const { extractTarGzipArchive } = await import('../../packages/desktop/src/main/runtime-archive')
  26. await extractTarGzipArchive(archive, target)
  27. expect(readFileSync(join(target, 'python', 'Scripts', 'hermes.exe'), 'utf-8')).toBe('launcher')
  28. })
  29. })
粤ICP备19079148号