|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { execSync, exec, ChildProcess } from 'node:child_process'; |
| 3 | +import { fileURLToPath } from 'node:url'; |
| 4 | +import waitPort from 'wait-port'; |
| 5 | +import { debugChildProcess, getFreePort, terminate, test } from './utils.js'; |
| 6 | +import { rm } from 'node:fs/promises'; |
| 7 | + |
| 8 | +const waku = fileURLToPath( |
| 9 | + new URL('../packages/waku/dist/cli.js', import.meta.url), |
| 10 | +); |
| 11 | + |
| 12 | +const commands = [ |
| 13 | + { |
| 14 | + command: 'dev', |
| 15 | + }, |
| 16 | + { |
| 17 | + build: 'build', |
| 18 | + command: 'start', |
| 19 | + }, |
| 20 | +]; |
| 21 | + |
| 22 | +const cwd = fileURLToPath( |
| 23 | + new URL('./fixtures/rsc-css-modules', import.meta.url), |
| 24 | +); |
| 25 | + |
| 26 | +for (const { build, command } of commands) { |
| 27 | + test.describe(`rsc-css-modules: ${command}`, () => { |
| 28 | + let cp: ChildProcess; |
| 29 | + let port: number; |
| 30 | + test.beforeAll('remove cache', async () => { |
| 31 | + await rm(`${cwd}/dist`, { |
| 32 | + recursive: true, |
| 33 | + force: true, |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + test.beforeAll(async () => { |
| 38 | + if (build) { |
| 39 | + execSync(`node ${waku} ${build}`, { cwd }); |
| 40 | + } |
| 41 | + port = await getFreePort(); |
| 42 | + cp = exec(`node ${waku} ${command} --port ${port}`, { cwd }); |
| 43 | + debugChildProcess(cp, fileURLToPath(import.meta.url), [ |
| 44 | + /ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time/, |
| 45 | + ]); |
| 46 | + await waitPort({ port }); |
| 47 | + }); |
| 48 | + |
| 49 | + test.afterAll(async () => { |
| 50 | + await terminate(cp.pid!); |
| 51 | + }); |
| 52 | + |
| 53 | + test('css-modules classes', async ({ page }) => { |
| 54 | + await page.goto(`http://localhost:${port}/`); |
| 55 | + |
| 56 | + const wrapperClass = await page |
| 57 | + .getByTestId('app-wrapper') |
| 58 | + .getAttribute('class'); |
| 59 | + expect(wrapperClass).toContain('wrapper'); |
| 60 | + |
| 61 | + const appNameClass = await page |
| 62 | + .getByTestId('app-name') |
| 63 | + .getAttribute('class'); |
| 64 | + expect(appNameClass).toContain('text'); |
| 65 | + |
| 66 | + const clientcounterClass = await page |
| 67 | + .getByTestId('client-counter') |
| 68 | + .getAttribute('class'); |
| 69 | + expect(clientcounterClass).toContain('counterWrapper'); |
| 70 | + |
| 71 | + const incrementClass = await page |
| 72 | + .getByTestId('increment') |
| 73 | + .getAttribute('class'); |
| 74 | + expect(incrementClass).toContain('counterButton'); |
| 75 | + }); |
| 76 | + }); |
| 77 | +} |
0 commit comments