Hello dear community,
I have a react/typescript app that uses relative imports like import Login from 'components/auth/login'
Unfortunately, when I install playwright-ct to do component testing, I get this error:
[vite]: Rollup failed to resolve import "components/auth/login"
This means playwright internal vite does not play nicely with my app config. I have searched for a solution, but haven't found any. Would you plz help me on this ?
Here is a summary of my files:
tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"downlevelIteration": true,
"lib": ["dom", "dom.iterable", "esnext"],
"types": ["vite/client", "vite-plugin-svgr/client", "node"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": "./src"
},
"include": ["src"]
}
playwright-ct.config.ts
import { defineConfig, devices } from '@playwright/experimental-ct-react'
export default defineConfig({
testDir: './',
snapshotDir: './__snapshots__',
timeout: 10 * 1000,
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
trace: 'on-first-retry',
ctPort: 3100,
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
})
This thread is trying to answer question "How can I resolve the compatibility issue between playwright-ct and my React/Typescript app that uses relative imports?"
Having the same issue, tried moving component test files to it's own tests
folder with it's own tsconfig.json
file as mentioned here: https://playwright.dev/docs/test-typescript#tsconfig-path-mapping
Still seeing the same error.
Update, was able to figure this out thanks to this github comment: https://github.com/microsoft/playwright/issues/27993#issuecomment-1798979310 It would be great if there was something in the docs talking about doing alias's differently for component testiing.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].