Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarn test:watch at the very first run executes test twice #7

Open
github0013 opened this issue Oct 29, 2021 · 9 comments
Open

yarn test:watch at the very first run executes test twice #7

github0013 opened this issue Oct 29, 2021 · 9 comments

Comments

@github0013
Copy link

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)
@iamyoki
Copy link
Owner

iamyoki commented Oct 30, 2021

Thank you for your reporting. Please try simply npx playwright-watch exec echo changed, and see if it executes twice?

@github0013
Copy link
Author

pwuser@07be25028166:/app$ npx playwright-watch exec echo changed
changed
changed

@iamyoki
Copy link
Owner

iamyoki commented Nov 1, 2021

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"

@github0013
Copy link
Author

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?

@iamyoki
Copy link
Owner

iamyoki commented Nov 2, 2021

Okay, I'll look into it, thank you very much.

@deeeed
Copy link

deeeed commented Feb 6, 2022

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)

@leosuncin
Copy link

I happened to me, the first time it launch as many as test file I have in Typescript

asciicast

Reproduction repo: https://github.com/leosuncin/redux-offline-example

@HalfdanJ
Copy link

HalfdanJ commented Apr 2, 2023

I'm seeing similar issue in a project right now, producing 4 duplicate entries:

npx playwright-watch exec echo changed
changed
changed
changed
changed

@MrMurga
Copy link

MrMurga commented Apr 12, 2023

Following this PR. I see similar behaviour:

$ npx playwright-watch exec echo changed
changed
changed
changed
changed
changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants