Skip to content

Commit ee56dcf

Browse files
committed
Refactor Playwright tests to use init function for script injection and update test structure
1 parent 7e29afa commit ee56dcf

10 files changed

+28
-46
lines changed

Diff for: packages/runtime/e2e/complex.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { test, expect } from '@playwright/test'
22
import { readFileSync } from 'fs'
33
import { dirname, resolve } from 'path'
44
import { fileURLToPath } from 'url'
5+
import init from './init'
56

67
const __filename = fileURLToPath(import.meta.url)
78
const __dirname = dirname(__filename)
89

910
test('complex', async ({ page }) => {
10-
await page.addScriptTag({ path: resolve(__dirname, '../dist/global.min.js') })
11-
11+
await init(page)
1212
/**
1313
* <p class="block font:bold">
1414
* <p class="block font:bold italic">

Diff for: packages/runtime/e2e/global-extends.test.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { test, expect } from '@playwright/test'
2-
import { dirname, resolve } from 'path'
3-
import { fileURLToPath } from 'url'
4-
5-
const __filename = fileURLToPath(import.meta.url)
6-
const __dirname = dirname(__filename)
2+
import init from './init'
73

84
test('extends', async ({ page }) => {
95
await page.evaluate(() => {
@@ -20,7 +16,7 @@ test('extends', async ({ page }) => {
2016
}]
2117
}
2218
})
23-
await page.addScriptTag({ path: resolve(__dirname, '../dist/global.min.js') })
19+
await init(page)
2420
expect(await page.evaluate(() => globalThis.masterCSSConfigs)).toBeDefined()
2521
expect(await page.evaluate(() => globalThis.runtimeCSS.variables.primary)).toBeDefined()
2622
expect(await page.evaluate(() => globalThis.runtimeCSS.variables.secondary)).toBeDefined()

Diff for: packages/runtime/e2e/init.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ import { Config } from '@master/css'
22
import { Page } from '@playwright/test'
33
import { dirname, resolve } from 'path'
44
import { fileURLToPath } from 'url'
5-
// @ts-expect-error
6-
import { css_beautify } from 'js-beautify/js/lib/beautify-css.js'
75

86
const __filename = fileURLToPath(import.meta.url)
97
const __dirname = dirname(__filename)
108

11-
export default async function init(page: Page, text: string, config?: Config) {
9+
export default async function init(page: Page, text?: string, config?: Config) {
1210
await page.evaluate(({ config, text }) => {
1311
if (config) window.masterCSSConfig = config
1412
const style = document.createElement('style')
1513
style.id = 'master'
16-
style.textContent = text
14+
if (text) style.textContent = text
1715
document.head.appendChild(style)
1816
}, { config, text })
1917
await page.addScriptTag({ path: resolve(__dirname, '../dist/global.min.js') })

Diff for: packages/runtime/e2e/keyframes.test.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { test, expect } from '@playwright/test'
2-
import { dirname, resolve } from 'path'
3-
import { fileURLToPath } from 'url'
4-
5-
const __filename = fileURLToPath(import.meta.url)
6-
const __dirname = dirname(__filename)
2+
import init from './init'
73

84
test('expects the animation output', async ({ page }) => {
9-
await page.addScriptTag({ path: resolve(__dirname, '../dist/global.min.js') })
5+
await init(page)
106
await page.evaluate(() => {
117
globalThis.runtimeCSS.refresh({})
128
const p = document.createElement('p')

Diff for: packages/runtime/e2e/progressive.test.ts

-22
This file was deleted.

Diff for: packages/runtime/e2e/progressive/basic.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test, expect } from '@playwright/test'
2+
import init from '../init'
3+
4+
test('progressive', async ({ page }) => {
5+
await init(page)
6+
await page.evaluate(() => {
7+
globalThis.runtimeCSS.destroy()
8+
})
9+
expect(await page.evaluate(() => {
10+
globalThis.runtimeCSS.destroy()
11+
return document.getElementById('master')
12+
})).toBeDefined()
13+
})

Diff for: packages/runtime/e2e/default-mode-host.test.ts renamed to packages/runtime/e2e/progressive/default-mode-host.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from '@playwright/test'
22
// @ts-expect-error
33
import { css_beautify } from 'js-beautify/js/lib/beautify-css.js'
4-
import init from './init'
4+
import init from '../init'
55

66
test('prerender', async ({ page }) => {
77
const text = css_beautify(`

Diff for: packages/runtime/e2e/default-mode.test.ts renamed to packages/runtime/e2e/progressive/default-mode.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from '@playwright/test'
22
// @ts-expect-error
33
import { css_beautify } from 'js-beautify/js/lib/beautify-css.js'
4-
import init from './init'
4+
import init from '../init'
55

66
test('prerender', async ({ page }) => {
77
const text = css_beautify(`

Diff for: packages/runtime/e2e/media-mode.test.ts renamed to packages/runtime/e2e/progressive/media-mode.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from '@playwright/test'
22
// @ts-expect-error
33
import { css_beautify } from 'js-beautify/js/lib/beautify-css.js'
4-
import init from './init'
4+
import init from '../init'
55

66
test('prerender', async ({ page }) => {
77
const text = css_beautify(`

Diff for: packages/runtime/e2e/variables.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { test, expect } from '@playwright/test'
22
import { dirname, resolve } from 'path'
33
import { fileURLToPath } from 'url'
4+
import init from './init'
45

56
const __filename = fileURLToPath(import.meta.url)
67
const __dirname = dirname(__filename)
@@ -34,7 +35,7 @@ const variables = {
3435
}
3536

3637
test.beforeEach(async ({ page }) => {
37-
await page.addScriptTag({ path: resolve(__dirname, '../dist/global.min.js') })
38+
await init(page)
3839
await page.evaluate((variables) => globalThis.runtimeCSS.refresh({ variables }), variables)
3940
})
4041

@@ -143,12 +144,12 @@ const expectLayers = (
143144
layers: {
144145
theme?: string
145146
styles?: string
146-
normal?: string
147+
general?: string
147148
keyframe?: string
148149
}
149150
) => {
150151
if (layers.theme) expect(cssText).toContain(`@layer theme{${layers.theme ?? ''}}`)
151152
if (layers.styles) expect(cssText).toContain(`@layer styles{${layers.styles ?? ''}}`)
152-
if (layers.normal) expect(cssText).toContain(`@layer general{${layers.normal ?? ''}}`)
153+
if (layers.general) expect(cssText).toContain(`@layer general{${layers.general ?? ''}}`)
153154
if (layers.keyframe) expect(cssText).toContain(`${layers.keyframe ?? ''}`)
154155
}

0 commit comments

Comments
 (0)