Skip to content

Commit

Permalink
refactor: add createVscodeTest
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Mar 4, 2024
1 parent cbd1485 commit dd5dba5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
18 changes: 10 additions & 8 deletions test-e2e/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { vscodeTest } from '@hiogawa/vscode-e2e/vitest'
import { beforeEach } from 'vitest'
import { beforeAll } from 'vitest'
import { createVscodeTest } from './helper'

beforeEach(({ task }) => {
task.meta.vscodeExtensionPath = '.'
task.meta.vscodeWorkspacePath = './samples/e2e'
task.meta.vscodeTrace = 'on'

// Vitst extension doesn't work with CI flag
// Vitst extension doesn't work with CI flag
beforeAll(() => {
delete process.env.CI
delete process.env.GITHUB_ACTIONS
})

const vscodeTest = createVscodeTest({
extensionPath: '.',
workspacePath: './samples/e2e',
trace: true,
})

vscodeTest('basic', async ({ page }) => {
// open test explorer
await page.getByRole('tab', { name: 'Testing' }).locator('a').click()
Expand Down
31 changes: 31 additions & 0 deletions test-e2e/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { launch } from '@hiogawa/vscode-e2e'
import { test } from 'vitest'
import type { Page } from 'playwright'

export function createVscodeTest({
extensionPath,
workspacePath,
trace,
}: {
extensionPath?: string;

Check failure on line 10 in test-e2e/helper.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected separator (;)
workspacePath?: string;

Check failure on line 11 in test-e2e/helper.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected separator (;)
trace?: boolean;

Check failure on line 12 in test-e2e/helper.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected separator (;)
}) {
return test.extend<{ page: Page }>({
page: async ({ task }, use) => {
const { app } = await launch({
extensionPath,
workspacePath,
})
const page = await app.firstWindow()
if (trace) {

Check failure on line 21 in test-e2e/helper.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unnecessary { after 'if' condition
await page.context().tracing.start({ screenshots: true, snapshots: true })
}
await use(page)
if (trace) {

Check failure on line 25 in test-e2e/helper.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unnecessary { after 'if' condition
await page.context().tracing.stop({ path: `test-results/${task.id}/basic.zip` })
}
await app.close()
},
})
}

0 comments on commit dd5dba5

Please sign in to comment.