[Bug]: Overwriting .env files interrupts tests when using the VSCode Playwright extension #34344
Description
Version
1.49.1
Steps to reproduce
Start new project ( I use Windows 11 machine) with:
npm init playwright@latest --yes '--' '--quiet' '--browser=chromium'
Make sure that you have Playwright Extension installed (tested on Playwright Test for VSCode v1.1.12)
Add test:
import { expect, test } from '@playwright/test';
import * as fs from 'fs';
test('test broken plugin', async ({ page }) => {
fs.writeFileSync('.env', '');
console.log('Go to website');
await page.goto('http://playwright.dev');
console.log('Do the stuff');
await expect(page.getByText('playwright').first()).toBeInViewport();
});
Run test form VSCode using Playwright Test for VSCode extension:
Expected behavior
Test should finish successfully, like when commenting line: fs.writeFileSync('.env', '');
Actual behavior
Test is interrupted:
Additional context
-
Running tests in the console works fine:
-
Renaming the file so it no longer matches the
**.env*
pattern
If you rename the file so it does not match the**.env*
pattern (e.g.,.my-env
), the test passes when triggered from VSCode with the Playwright extension.This issue is likely related to the watcher implementation in the VSCode Playwright extension:
Source code reference
Introduced in this PR:
#403 -
Why does this scenario matter?
- Using dotenv allows you to override
.env
files and reload them at runtime. - However, when the Playwright extension in VSCode watches files matching
**.env*
, it prevents this behavior, creating a big inconsistency compared to running tests from the terminal.
- Using dotenv allows you to override
Environment
VSCode with Playwright Test for VSCode v1.1.12
System:
OS: Windows 11
CPU: (16) x64 11th Gen Intel(R) Core(TM)
Memory: 43.39 GB / 63.71 GB
Binaries:
Node: 20.11.0 - \nodejs\node.EXE
npm: 10.4.0 - \nodejs\npm.CMD
IDEs:
VSCode: 1.95.3 - \Microsoft VS Code\bin\code.CMD
Browsers:
Edge: Chromium (127.0.2651.74)
npmPackages:
@playwright/test: ^1.49.0