Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure context before opening page #71

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 16.x
- name: Install root project dependencies
run: yarn
- name: Install extensions dependencies
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/test-web",
"version": "0.0.38",
"version": "0.0.39",
"scripts": {
"install-extensions": "yarn --cwd=fs-provider && yarn --cwd=sample",
"compile": "tsc -p ./ && yarn compile-fs-provider",
Expand Down
21 changes: 14 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ export async function runTests(options: Options & { extensionTestsPath: string }

const endpoint = `http://${host}:${port}`;

console.log(`Opening browser on ${endpoint}...`);
const context = await openBrowser(endpoint, options);
if (context) {
const configContext = async (context: playwright.BrowserContext) => {
context.once('close', () => server.close());

type Severity = 'error' | 'warning' | 'info';
Expand Down Expand Up @@ -215,7 +213,11 @@ export async function runTests(options: Options & { extensionTestsPath: string }
e(new Error('Test failed'));
}
});
} else {

}
console.log(`Opening browser on ${endpoint}...`);
const context = await openBrowser(endpoint, options, configContext);
if (!context) {
server.close();
e(new Error('Can not run test as opening of browser failed.'));
}
Expand Down Expand Up @@ -253,9 +255,12 @@ export async function open(options: Options): Promise<Disposable> {
const server = await runServer(host, port, config);

const endpoint = `http://${host}:${port}`;
const context = await openBrowser(endpoint, options);
context?.once('close', () => server.close());

const configContext = async (context: playwright.BrowserContext) => {
context.once('close', () => server.close());
};

const context = await openBrowser(endpoint, options, configContext);
return {
dispose: () => {
server.close();
Expand All @@ -265,7 +270,7 @@ export async function open(options: Options): Promise<Disposable> {

}

async function openBrowser(endpoint: string, options: Options): Promise<playwright.BrowserContext | undefined> {
async function openBrowser(endpoint: string, options: Options, configureContext: (context: playwright.BrowserContext) => Promise<void>): Promise<playwright.BrowserContext | undefined> {
if (options.browserType === 'none') {
return undefined;
}
Expand Down Expand Up @@ -293,6 +298,8 @@ async function openBrowser(endpoint: string, options: Options): Promise<playwrig
context.grantPermissions(options.permissions);
}

await configureContext(context);

// forcefully close browser if last page is closed. workaround for https://github.com/microsoft/playwright/issues/2946
let openPages = 0;
context.on('page', page => {
Expand Down