-
Notifications
You must be signed in to change notification settings - Fork 33
test: setup playwright tests #437
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| LICENSE | ||
| assets/ | ||
| readme.md | ||
| tests/e2e/.generated/ | ||
| playwright-report/ | ||
| test-results/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { defineConfig, devices } from '@playwright/test' | ||
|
|
||
| export default defineConfig({ | ||
| testDir: './tests/e2e', | ||
| fullyParallel: true, | ||
| forbidOnly: Boolean(process.env.CI), | ||
| retries: 0, | ||
| workers: 1, | ||
| reporter: 'list', | ||
| globalSetup: './tests/e2e/global-setup.ts', | ||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| }, | ||
| ], | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { expect, test } from '@playwright/test' | ||
| import { readFileSync } from 'fs' | ||
| import type { UniwindContextType } from '../../src/core/types' | ||
| import { BUNDLE_PATH, CSS_PATH } from './global-setup' | ||
| import './window.d.ts' | ||
|
|
||
| // Load the compiled artifacts produced by global-setup.ts | ||
| const compiledCSS = readFileSync(CSS_PATH, 'utf-8') | ||
| const bundle = readFileSync(BUNDLE_PATH, 'utf-8') | ||
|
|
||
| /** | ||
| * Calls getWebStyles inside the browser context and returns the RN style object. | ||
| */ | ||
| async function getWebStyles( | ||
| page: import('@playwright/test').Page, | ||
| className: string, | ||
| context: UniwindContextType = { scopedTheme: null }, | ||
| ) { | ||
| return page.evaluate( | ||
| ([cls, ctx]) => { | ||
| return window.__uniwind.getWebStyles(cls, ctx) | ||
| }, | ||
| [className, context], | ||
| ) | ||
| } | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.setContent(` | ||
| <!DOCTYPE html> | ||
| <html class="light"> | ||
| <head> | ||
| <style>${compiledCSS}</style> | ||
| </head> | ||
| <body></body> | ||
| </html> | ||
| `) | ||
| await page.addScriptTag({ content: bundle }) | ||
| }) | ||
|
|
||
| test.describe('getWebStyles — background color', () => { | ||
| test('bg-red-500 → backgroundColor #fb2c36', async ({ page }) => { | ||
| const styles = await getWebStyles(page, 'bg-red-500') | ||
| expect(styles.backgroundColor).toBe('#fb2c36') | ||
| }) | ||
| }) | ||
|
|
||
| test.describe('getWebStyles — scoped theme', () => { | ||
| test('bg-background in dark theme → backgroundColor black', async ({ page }) => { | ||
| const styles = await getWebStyles(page, 'bg-background', { scopedTheme: 'dark' }) | ||
| expect(styles.backgroundColor).toBe('#000000') | ||
| }) | ||
|
|
||
| test('bg-background in light theme → backgroundColor white', async ({ page }) => { | ||
| const styles = await getWebStyles(page, 'bg-background', { scopedTheme: 'light' }) | ||
| expect(styles.backgroundColor).toBe('#ffffff') | ||
| }) | ||
| }) | ||
|
|
||
| test.describe('getWebStyles - html default styles', () => { | ||
| // TODO fix html default styles in getWebStyles | ||
| test.skip('text-base -> fontSize 16px', async ({ page }) => { | ||
| const styles = await getWebStyles(page, 'text-base') | ||
| expect(styles.fontSize).toBe('16px') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { build } from 'esbuild' | ||
| import { mkdirSync, readFileSync, writeFileSync } from 'fs' | ||
| import { resolve } from 'path' | ||
| import { Platform } from '../../src/common/consts' | ||
| import { compileVirtual } from '../../src/metro/compileVirtual' | ||
|
|
||
| // Playwright runs globalSetup with cwd = directory containing playwright.config.ts | ||
| // which is packages/uniwind/ | ||
| const ROOT = resolve(process.cwd()) | ||
Brentlok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const GENERATED_DIR = resolve(ROOT, 'tests/e2e/.generated') | ||
| export const CSS_PATH = resolve(GENERATED_DIR, 'uniwind.css') | ||
| export const BUNDLE_PATH = resolve(GENERATED_DIR, 'getWebStyles.iife.js') | ||
|
|
||
| export default async function globalSetup() { | ||
| mkdirSync(GENERATED_DIR, { recursive: true }) | ||
|
|
||
| // 1. Compile test.css → real Tailwind CSS for web | ||
| const cssPath = resolve(ROOT, 'tests/test.css') | ||
| const css = readFileSync(cssPath, 'utf-8') | ||
|
|
||
| const compiledCSS = await compileVirtual({ | ||
| css, | ||
| cssPath, | ||
| debug: false, | ||
| platform: Platform.Web, | ||
| themes: ['light', 'dark'], | ||
| polyfills: undefined, | ||
| }) | ||
|
|
||
| writeFileSync(CSS_PATH, compiledCSS, 'utf-8') | ||
| console.log(`[e2e setup] Compiled CSS written to ${CSS_PATH}`) | ||
|
|
||
| // 2. Bundle getWebStyles.ts into a browser IIFE via esbuild | ||
| // The bundle exports getWebStyles and getWebVariable as globals on window.__uniwind | ||
| const getWebStylesPath = resolve(ROOT, 'src/core/web/getWebStyles') | ||
| const entryContent = [ | ||
| `import { getWebStyles, getWebVariable } from ${JSON.stringify(getWebStylesPath)}`, | ||
| 'window.__uniwind = { getWebStyles, getWebVariable }', | ||
| ].join('\n') | ||
| const entryPath = resolve(GENERATED_DIR, '_entry.ts') | ||
| writeFileSync(entryPath, entryContent, 'utf-8') | ||
|
|
||
| await build({ | ||
| entryPoints: [entryPath], | ||
| bundle: true, | ||
| format: 'iife', | ||
| platform: 'browser', | ||
| outfile: BUNDLE_PATH, | ||
| // getWebStyles uses document/window at module load time, | ||
| // so we must NOT tree-shake the side-effectful top-level code | ||
| treeShaking: false, | ||
| // culori is an ESM-only package; esbuild handles it fine with bundle:true | ||
| mainFields: ['module', 'browser', 'main'], | ||
| conditions: ['browser', 'import', 'default'], | ||
| tsconfig: resolve(ROOT, 'tsconfig.json'), | ||
| logLevel: 'warning', | ||
| }) | ||
|
|
||
| console.log(`[e2e setup] Browser bundle written to ${BUNDLE_PATH}`) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type { getWebStyles, getWebVariable } from '../../src/core/web/getWebStyles' | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| __uniwind: { | ||
| getWebStyles: typeof getWebStyles | ||
| getWebVariable: typeof getWebVariable | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.