← Back to Discord Forum

how to only run .TS tests?

I just noticed my npx playwright test command is running tests twice - one from the .ts file and once again via the compiled .js file.

Is there a way to configure playwright to only pay attention to the .ts files?

This thread is trying to answer question "Is there a way to configure playwright to only pay attention to the .ts files?"

2 replies

There shouldn’t be a need to compile to JS files for playwright tests. They can stay as TS files and run fine.

That being said to answer your question


Using testMatch in your playwright config is what you are looking for.

Thanks @butchmayhew - In my case there are other files nearby and/or IDEs that try to compile things. I have a tsconfig to prevent emitting but somehow these JS files are still compiled sometimes.


Sure, you can configure Playwright to only consider .ts files as test files. This is done by modifying the testConfig.testMatch option in the playwright.config.ts file.

By default, Playwright runs .test.(js|ts|mjs) and .spec.(js|ts|mjs) files. But you can change this. Say your .ts test files are in a "tests" directory and follow a "example.spec.ts" naming pattern. You can set testConfig.testMatch to 'tests/**/*.spec.ts'. This tells Playwright to only run .ts test files that match this pattern.

Here's how you can do this in your playwright.config.ts file:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  // Other configuration options...

  testConfig: {
    // Other test configuration options...

    // Specify the glob pattern for .ts test files
    testMatch: 'tests/**/*.spec.ts',

Now, when you run tests with Playwright, it will only consider and execute the .ts test files that match the specified glob pattern.

Remember, this information is based on the context provided. If there are other ways to configure Playwright for this purpose that aren't mentioned here, I'm not aware of them.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.