don't use base fixture

This commit is contained in:
Ryan Rosello
2024-08-11 20:15:19 +10:00
parent 235f39717e
commit d85bfa39e1
20 changed files with 59 additions and 84 deletions

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect, Page } from '@playwright/test'
import { test, expect, Page } from '@playwright/test'
import {
getUtils,
TEST_COLORS,

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown } from './test-utils'
import { EngineCommand } from 'lang/std/artifactGraph'
import { uuidv4 } from 'lib/utils'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown } from './test-utils'
import { bracket } from 'lib/exampleKcl'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown } from './test-utils'
import { KCL_DEFAULT_LENGTH } from 'lib/constants'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown } from './test-utils'
test.beforeEach(async ({ context, page }) => {

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { uuidv4 } from 'lib/utils'
import { getUtils, setup, tearDown } from './test-utils'

View File

@ -1,48 +0,0 @@
import * as fs from 'fs'
import * as path from 'path'
import * as crypto from 'crypto'
import { test as baseTest } from '@playwright/test'
const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output')
export function generateUUID(): string {
return crypto.randomBytes(16).toString('hex')
}
export const test = baseTest.extend({
context: async ({ context }, use) => {
await context.addInitScript(() =>
window.addEventListener('beforeunload', () =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).collectIstanbulCoverage(
JSON.stringify((window as any).__coverage__)
)
)
)
await fs.promises.mkdir(istanbulCLIOutput, { recursive: true })
await context.exposeFunction(
'collectIstanbulCoverage',
(coverageJSON: string) => {
if (coverageJSON)
fs.writeFileSync(
path.join(
istanbulCLIOutput,
`playwright_coverage_${generateUUID()}.json`
),
coverageJSON
)
}
)
await use(context)
for (const page of context.pages()) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await page.evaluate(() =>
(window as any).collectIstanbulCoverage(
JSON.stringify((window as any).__coverage__)
)
)
}
},
})
export const expect = test.expect

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown } from './test-utils'
import { bracket } from 'lib/exampleKcl'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown } from './test-utils'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect, Page } from '@playwright/test'
import { test, expect, Page } from '@playwright/test'
import {
getMovementUtils,

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { secrets } from './secrets'
import { Paths, doExport, getUtils } from './test-utils'
import { Models } from '@kittycad/lib'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { commonPoints, getUtils, setup, tearDown } from './test-utils'

View File

@ -8,6 +8,8 @@ import {
import { EngineCommand } from 'lang/std/artifactGraph'
import os from 'os'
import fsp from 'fs/promises'
import * as fs from 'fs'
import * as path from 'path'
import pixelMatch from 'pixelmatch'
import { PNG } from 'pngjs'
import { Protocol } from 'playwright-core/types/protocol'
@ -17,6 +19,7 @@ import waitOn from 'wait-on'
import { secrets } from './secrets'
import { TEST_SETTINGS_KEY, TEST_SETTINGS } from './storageStates'
import * as TOML from '@iarna/toml'
import { uuidv4 } from 'lib/utils'
type TestColor = [number, number, number]
export const TEST_COLORS = {
@ -601,6 +604,16 @@ export async function tearDown(page: Page, testInfo: TestInfo) {
uploadThroughput: -1,
})
if (process.env.GENERATE_PLAYWRIGHT_COVERAGE) {
for (const activePage of page.context().pages()) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await activePage.evaluate(() =>
(window as any).collectIstanbulCoverage(
JSON.stringify((window as any).__coverage__)
)
)
}
}
// It seems it's best to give the browser about 3s to close things
// It's not super reliable but we have no real other choice for now
await page.waitForTimeout(3000)
@ -626,6 +639,34 @@ export async function setup(context: BrowserContext, page: Page) {
settings: TOML.stringify({ settings: TEST_SETTINGS }),
}
)
if (process.env.GENERATE_PLAYWRIGHT_COVERAGE) {
await context.addInitScript(() =>
window.addEventListener('beforeunload', () =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).collectIstanbulCoverage(
JSON.stringify((window as any).__coverage__)
)
)
)
const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output')
await fsp.mkdir(istanbulCLIOutput, { recursive: true })
await context.exposeFunction(
'collectIstanbulCoverage',
(coverageJSON: string) => {
if (coverageJSON) {
fs.writeFileSync(
path.join(
istanbulCLIOutput,
`playwright_coverage_${uuidv4()}.json`
),
coverageJSON
)
}
}
)
}
// kill animations, speeds up tests and reduced flakiness
await page.emulateMedia({ reducedMotion: 'reduce' })
}

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { EngineCommand } from 'lang/std/artifactGraph'
import { uuidv4 } from 'lib/utils'
import { getUtils, setup, tearDown } from './test-utils'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown, TEST_COLORS } from './test-utils'
import { XOR } from 'lib/utils'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown } from './test-utils'
import { uuidv4 } from 'lib/utils'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect, Page } from '@playwright/test'
import { test, expect, Page } from '@playwright/test'
import { deg, getUtils, setup, tearDown, wiggleMove } from './test-utils'
import { LineInputsType } from 'lang/std/sketchcombos'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { commonPoints, getUtils, setup, tearDown } from './test-utils'
import { Coords2d } from 'lang/std/sketch'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { getUtils, setup, tearDown } from './test-utils'
import { SaveSettingsPayload } from 'lib/settings/settingsTypes'
import { TEST_SETTINGS_KEY, TEST_SETTINGS_CORRUPTED } from './storageStates'

View File

@ -1,5 +1,4 @@
import { test } from './lib/base-fixture'
import { expect } from '@playwright/test'
import { test, expect } from '@playwright/test'
import {
doExport,