playwright-watch
                                
                                 playwright-watch copied to clipboard
                                
                                    playwright-watch copied to clipboard
                            
                            
                            
                        `yarn test:watch` at the very first run executes test twice
Dockerfile
FROM mcr.microsoft.com/playwright:focal
ENV LANG C.UTF-8
WORKDIR /app
RUN yarn install
User pwuser
RUN npx playwright install
package.json
{
  "scripts": {
    "test": "playwright test",
    "test:watch": "playwright-watch exec yarn test"
  },
  "devDependencies": {
    "@playwright/test": "^1.16.2",
    "@types/node": "^16.11.6",
    "playwright-watch": "^1.3.21",
  }
}
foo.spec.ts
import { expect, test } from "@playwright/test"
test.describe("yarn test:watch", () => {
  test.beforeAll(async () => {
    console.log("beforeAll:")
  })
  test.afterAll(async () => {
    console.log("afterAll:")
  })
  test("test1", async ({ page }) => {
    expect(true).toBe(true)
  })
})
making sure yarn test only runs once for foo.spec.ts
pwuser@309e51291d88:/app$ yarn test
yarn run v1.22.10
warning package.json: No license field
$ playwright test
Using config at /app/playwright.config.ts
Running 1 test using 1 worker
beforeAll:
  ✓  tests/foo.spec.ts:23:3 › yarn test:watch › test1 (288ms)
afterAll:
  1 passed (621ms)
Done in 1.00s.
yarn test:watch runs the test twice on the initial run
Notice
- Using config at /app/playwright.config.ts
- beforeAll
- afterAll
They are output twice.
💾  HERE, I saved foo.spec.ts to run again
After that, it only runs once on a save.
pwuser@309e51291d88:/app$ yarn test:watch
yarn run v1.22.10
warning package.json: No license field
$ playwright-watch exec yarn test
warning package.json: No license field
warning package.json: No license field
$ playwright test
$ playwright test
Using config at /app/playwright.config.ts
Using config at /app/playwright.config.ts
Running 1 test using 1 worker
[Error: ENOENT: no such file or directory, scandir '/app/test-results'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: '/app/test-results'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
beforeAll:
  ✓  tests/foo.spec.ts:23:3 › yarn test:watch › test1 (309ms)
afterAll:
  1 passed (644ms)
warning package.json: No license field // <= 💾  HERE, I saved foo.spec.ts to run again
$ playwright test
Using config at /app/playwright.config.ts
Running 1 test using 1 worker
beforeAll:
  ✓  tests/foo.spec.ts:23:3 › yarn test:watch › test1 (308ms)
afterAll:
  1 passed (637ms)
Thank you for your reporting. Please try simply npx playwright-watch exec echo changed, and see if it executes twice?
pwuser@07be25028166:/app$ npx playwright-watch exec echo changed
changed
changed
Think it's probably when you save it triggered by .spec.ts source file and dist file which compiles by tsc at the same time. Write a playwright.config.js file to match only the source one or dist.
playwright.config.js
testMatch: ".*spec\.ts"
testMatch: ".*spec.ts"
(vscode corrects me .*spec\.ts to .*spec.ts)
With this config, I see
=================
 no tests found.
=================
Changing that to this ran tests.
testMatch: "*spec.ts"
However, it wasn't really the case as I did more tests. It seems when there are multiple spec.ts files, the initial run gets multiplied by the number of the files. (whether or not you have that testMatch part) e.g. if you had 2 spec.ts files, you get each test file run 2 times
Does it happen on your environment?
Okay, I'll look into it, thank you very much.
same issue here, tests are launched twice in watch mode.
$ yarn test:watch reserv
yarn run v1.22.17
$ playwright-watch exec yarn test reserv
$ playwright test reserv
$ playwright test reserv
Using config at /Users/.../apps/demo-e2e/playwright.config.ts
Using config at /Users/.../apps/demo-e2e/playwright.config.ts
Running 1 test using 1 worker
Running 1 test using 1 worker
I can also confirm the issue only happens when there is multiple test files. (In my case 2 test files)
I happened to me, the first time it launch as many as test file I have in Typescript
Reproduction repo: https://github.com/leosuncin/redux-offline-example
I'm seeing similar issue in a project right now, producing 4 duplicate entries:
npx playwright-watch exec echo changed
changed
changed
changed
changed
Following this PR. I see similar behaviour:
$ npx playwright-watch exec echo changed
changed
changed
changed
changed
changed