| 12345678910111213141516171819202122 |
- // @vitest-environment node
- import {expect,it} from 'vitest'
- import {build} from 'esbuild'
- import {mkdtemp,rm,readdir,readFile} from 'node:fs/promises'
- import {tmpdir} from 'node:os'
- import {join} from 'node:path'
- import {execFileSync} from 'node:child_process'
- // @ts-expect-error Build helper is plain JavaScript.
- import {browserRuntimeExternals,bundleBrowserRuntime} from '../../scripts/bundle-browser-runtime.mjs'
- it('imports the relocated browser runtime without the repository node_modules or copied Chromium caches',async()=>{
- const directory=await mkdtemp(join(tmpdir(),'yaoyao-browser-package-'))
- try{
- await build({stdin:{contents:'const {chromium}=await import("playwright"); console.log(JSON.stringify({path:chromium.executablePath(),version:(await import("playwright/package.json",{with:{type:"json"}})).default.version}))',resolveDir:process.cwd(),sourcefile:'browser-probe.mjs'},outfile:join(directory,'browser-probe.mjs'),bundle:true,platform:'node',format:'esm',target:'node24',external:browserRuntimeExternals})
- await bundleBrowserRuntime(directory)
- const result=JSON.parse(execFileSync(process.execPath,[join(directory,'browser-probe.mjs')],{cwd:directory,encoding:'utf8'}))
- const manifest=JSON.parse(await readFile(new URL('../../package.json',import.meta.url),'utf8'))
- expect(result.version).toBe(manifest.dependencies.playwright);expect(result.path).toContain('chromium')
- expect(await readdir(join(directory,'node_modules'))).toEqual(['playwright','playwright-core'])
- expect(await readdir(join(directory,'node_modules','playwright-core'))).not.toContain('.local-browsers')
- }finally{await rm(directory,{recursive:true,force:true})}
- },20000)
|