1+ import * as fs from 'fs' ;
2+ import * as os from 'os' ;
3+ import * as path from 'path' ;
4+ import type { Page } from '@playwright/test' ;
5+ import { _electron , test as base } from '@playwright/test' ;
6+ import { downloadAndUnzipVSCode } from '@vscode/test-electron/out/download' ;
7+
8+ export { expect } from '@playwright/test' ;
9+
10+ export type TestOptions = {
11+ vscodeVersion : string ;
12+ } ;
13+
14+ type TestFixtures = TestOptions & {
15+ page : Page ;
16+ createTmpDir : ( ) => Promise < string > ;
17+ } ;
18+
19+ export const MaxTimeout = 10000 ;
20+
21+ let testProjectPath : string ;
22+ export const test = base . extend < TestFixtures > ( {
23+ vscodeVersion : [ 'insiders' , { option : true } ] ,
24+ page : async ( { vscodeVersion, createTmpDir } , use ) => {
25+ const defaultCachePath = await createTmpDir ( ) ;
26+ const vscodePath = await downloadAndUnzipVSCode ( vscodeVersion ) ;
27+ testProjectPath = path . join ( __dirname , '..' , '..' , '..' ) ;
28+
29+ const electronApp = await _electron . launch ( {
30+ executablePath : vscodePath ,
31+ // Got it from https://github.com/gitkraken/vscode-gitlens/blob/main/tests/e2e/specs/baseTest.ts
32+ args : [
33+ '--no-sandbox' ,
34+ '--disable-gpu-sandbox' ,
35+ '--disable-updates' ,
36+ '--skip-welcome' ,
37+ '--skip-release-notes' ,
38+ '--disable-workspace-trust' ,
39+ `--extensionDevelopmentPath=${ path . join ( __dirname , '..' , '..' , '..' ) } ` ,
40+ `--extensions-dir=${ path . join ( defaultCachePath , 'extensions' ) } ` ,
41+ `--user-data-dir=${ path . join ( defaultCachePath , 'user-data' ) } ` ,
42+ testProjectPath ,
43+ ] ,
44+ } ) ;
45+
46+ const page = await electronApp . firstWindow ( ) ;
47+
48+ await use ( page ) ;
49+
50+ await electronApp . close ( ) ;
51+
52+ const logPath = path . join ( defaultCachePath , 'user-data' ) ;
53+ if ( fs . existsSync ( logPath ) ) {
54+ const logOutputPath = test . info ( ) . outputPath ( 'vscode-logs' ) ;
55+ await fs . promises . cp ( logPath , logOutputPath , { recursive : true } ) ;
56+ }
57+ } ,
58+
59+ // eslint-disable-next-line no-empty-pattern
60+ createTmpDir : async ( { } , use ) => {
61+ const tempDirs : string [ ] = [ ] ;
62+ await use ( async ( ) => {
63+ const tempDir = await fs . promises . realpath ( await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , 'gltest-' ) ) ) ;
64+ tempDirs . push ( tempDir ) ;
65+ return tempDir ;
66+ } ) ;
67+ for ( const tempDir of tempDirs ) {
68+ await fs . promises . rm ( tempDir , { recursive : true } ) ;
69+ }
70+ } ,
71+ } ) ;
0 commit comments