Skip to content

Commit fa80229

Browse files
author
Simon Laden
committed
FISH-8908 - add e2e tests
1 parent 1140572 commit fa80229

12 files changed

Lines changed: 248 additions & 4 deletions

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@
712712
"watch": "tsc -watch -p ./",
713713
"pretest": "yarn run compile",
714714
"test": "node ./out/test/runTest.js",
715+
"test:e2e": "playwright test -c src/test/e2e/playwright.config.ts",
715716
"tslint": "tslint -t verbose src/**/*.ts"
716717
},
717718
"dependencies": {
@@ -733,17 +734,19 @@
733734
"xml2js": "^0.6.0"
734735
},
735736
"devDependencies": {
737+
"@playwright/test": "^1.47.2",
736738
"@types/fs-extra": "^11.0.1",
737739
"@types/glob": "^8.0.0",
738740
"@types/lodash": "^4.14.155",
739-
"@types/mocha": "^10.0.0",
741+
"@types/mocha": "10.0.8",
740742
"@types/node": "^22.5.4",
741743
"@types/vscode": "^1.93.0",
744+
"@vscode/test-electron": "^2.4.1",
742745
"glob": "^7.1.7",
743-
"mocha": "^10.0.0",
746+
"mocha": "10.7.3",
744747
"os": "^0.1.1",
748+
"playwright": "^1.47.2",
745749
"tslint": "^6.1.0",
746-
"typescript": "^5.0.3",
747-
"vscode-test": "^1.2.2"
750+
"typescript": "^5.0.3"
748751
}
749752
}

src/test/e2e/baseTest.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import fs from 'fs';
2+
import os from 'os';
3+
import 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/microsoft/vscode-test/blob/0ec222ef170e102244569064a12898fb203e5bb7/lib/runTest.ts#L126-L160
32+
args: [
33+
'--no-sandbox', // https://github.com/microsoft/vscode/issues/84238
34+
'--disable-gpu-sandbox', // https://github.com/microsoft/vscode-test/issues/221
35+
'--disable-updates', // https://github.com/microsoft/vscode-test/issues/120
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+
/*await page.context().tracing.start({
48+
screenshots: true,
49+
snapshots: true,
50+
title: test.info().title,
51+
});*/
52+
53+
await use(page);
54+
55+
/*const tracePath = test.info().outputPath('trace.zip');
56+
await page.context().tracing.stop({ path: tracePath });
57+
test.info().attachments.push({ name: 'trace', path: tracePath, contentType: 'application/zip' });*/
58+
await electronApp.close();
59+
60+
const logPath = path.join(defaultCachePath, 'user-data');
61+
if (fs.existsSync(logPath)) {
62+
const logOutputPath = test.info().outputPath('vscode-logs');
63+
await fs.promises.cp(logPath, logOutputPath, { recursive: true });
64+
}
65+
},
66+
// Next line is necessary because of how Playwright works. It expect a destructured pattern here:
67+
// https://github.com/microsoft/playwright/issues/14590#issuecomment-1911734641
68+
// https://github.com/microsoft/playwright/issues/21566#issuecomment-1464858235
69+
70+
// eslint-disable-next-line no-empty-pattern
71+
createTmpDir: async ({}, use) => {
72+
const tempDirs: string[] = [];
73+
await use(async () => {
74+
const tempDir = await fs.promises.realpath(await fs.promises.mkdtemp(path.join(os.tmpdir(), 'gltest-')));
75+
tempDirs.push(tempDir);
76+
return tempDir;
77+
});
78+
for (const tempDir of tempDirs) {
79+
await fs.promises.rm(tempDir, { recursive: true });
80+
}
81+
},
82+
});

src/test/e2e/playwright.config.js

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/e2e/playwright.config.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/e2e/playwright.config.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { defineConfig } from '@playwright/test';
2+
import type { TestOptions } from './baseTest.ts';
3+
4+
// eslint-disable-next-line import-x/no-default-export
5+
export default defineConfig<TestOptions>({
6+
use: {
7+
headless: true, // Ensure headless mode is enabled
8+
viewport: { width: 1920, height: 1080 },
9+
},
10+
reporter: 'list', // process.env.CI ? 'html' : 'list',
11+
timeout: 60000, // 1 minute
12+
workers: 2,
13+
expect: {
14+
timeout: 60000, // 1 minute
15+
},
16+
globalSetup: './setup',
17+
outputDir: '../../../out/test-results',
18+
projects: [
19+
{
20+
name: 'VSCode stable',
21+
use: {
22+
vscodeVersion: 'stable',
23+
},
24+
},
25+
{
26+
name: 'VSCode insiders',
27+
use: {
28+
vscodeVersion: 'insiders',
29+
},
30+
},
31+
],
32+
testMatch: '**/specs/*.test.ts'
33+
});

src/test/e2e/setup.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/e2e/setup.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/e2e/setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { downloadAndUnzipVSCode } from '@vscode/test-electron';
2+
3+
// eslint-disable-next-line import-x/no-default-export
4+
export default async () => {
5+
await downloadAndUnzipVSCode('insiders');
6+
await downloadAndUnzipVSCode('stable');
7+
};

src/test/e2e/specs/payara_install.test.js

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/e2e/specs/payara_install.test.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)