question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] @playwright/test - Ignore .tsx files when running tests

See original GitHub issue

Asking this as a question rather than a bug report, as I hope I’m just doing something wrong in my configuration here. Was previously running Playwright tests via Jest, and am trying to switch to the official test runner. However, when executing npx playwright test, it fails with an SyntaxError: Unexpected token '<' when it attempts to parse a .tsx file that contains a React component. The tests themselves do not use or import React components, they just happen to be in same codebase.

All of my e2e-related code is consolidated under a test/e2e/ directory. Will try to share all of the relevant information that I can.

Environment

Our app is a Next.js app - React/TypeScript on the front-end, Express/TypeScript on server-side, all in one repo.

  1. OS - Fedora 35
  2. Node.js version - 16.13.0
  3. Playwright - @playwright/test 1.18.1

Configuration files

.babelrc

{
  "env": {
    "local": {
      "presets": ["next/babel"],
      "plugins": []
    },
    "development": {
      "presets": ["next/babel"],
      "plugins": []
    },
    "production": {
      "presets": ["next/babel"],
      "plugins": []
    },
    "test": {
      "presets": [["next/babel", { "preset-env": { "modules": "commonjs" } }]],
      "plugins": []
    }
  },
  "plugins": [
    ["@babel/plugin-proposal-decorators", { "legacy": true }]
  ]
}

playwright.config.ts

import { PlaywrightTestConfig } from "@playwright/test";
import { ENV_URLS } from "./server/constants";

const config: PlaywrightTestConfig = {
  globalSetup: require.resolve("test/e2e/setup"),
  use: {
    baseURL: ENV_URLS.local,
  },
  // have tried with/without these last two, no difference in error
  testMatch: "test/e2e/**/*.test.ts",
  testDir: "test/e2e", 
};

export default config;

package.json

{
   ...,
   "scripts": {
       ...,
       "test:e2e": "playwright test"
    }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "jsx": "preserve",
    "allowJs": true,
    "moduleResolution": "node",
    "noUnusedParameters": true,
    "allowSyntheticDefaultImports": true,
    "preserveConstEnums": true,
    "sourceMap": true,
    "skipLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "*": [
        "types/*"
      ]
    },
    "lib": [
      "dom",
      "es2016"
    ],
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": false,
    "noUnusedLocals": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "outDir": ".next/tsc-cache/",
    "incremental": true,
    "experimentalDecorators": true
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pavelfeldmancommented, Feb 11, 2022

Keeping the issue tracker healthy, so closing this one. Please feel free to open a new issue if this does not cover your use case and link this one.

1reaction
tylucaskelleycommented, Feb 7, 2022

Yes! Will make a note to do so when I get some free time. Will try to set up a test repo w/ our configuration + a file that hopefully causes the error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Playwright ONLY run tests from a specified folder and ignore ...
One way to do this is to create a project in your existing playwright config file and just add the testDir there, something...
Read more >
Configuring Jest
By default, Jest runs all tests and produces all errors into the ... no tests exist for this file and it's never required...
Read more >
Testing | Next.js
Learn how to set up Next.js with three commonly used testing tools — Cypress, Playwright, Jest, and React Testing Library.
Read more >
What You Need to Know About E2E Testing with Playwright
Test files run by default on Playwright, allowing multiple worker processes to run simultaneously. Tests can be conducted in a single file using ......
Read more >
playwright-community - Bountysource
'this.global.page' instance is undefined if tests are run with jest -t ... QUESTION: Will jest-playwright be supported, once playwright-test 1.0 is released ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found