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

[Bug]: HTML report confuses files from different projects #33554

Open
gofr opened this issue Nov 12, 2024 · 0 comments · May be fixed by #33600
Open

[Bug]: HTML report confuses files from different projects #33554

gofr opened this issue Nov 12, 2024 · 0 comments · May be fixed by #33600
Assignees
Labels

Comments

@gofr
Copy link

gofr commented Nov 12, 2024

Version

1.48.2

Steps to reproduce

playwright.config.ts:

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

export default defineConfig({
  reporter: [['html', { open: 'always' }]],
  projects: [
    { name: 'a', testDir: './tests/a' },
    { name: 'b', testDir: './tests/b' },
  ],
});

Two identical files tests/a/test.spec.ts and tests/b/test.spec.ts:

import { test, expect } from '@playwright/test';

test('nothing', async () => {
  expect(true).toBe(true)
});

Run the tests...

Expected behavior

Two passing tests under two separate file headers.

Actual behavior

Running those tests results in an HTML report that looks like this:

Image

Both tests are listed under the same file header, even though they're from different files in different projects.

Additional context

I believe the problem is caused here:

const fileName = this._relativeLocation(fileSuite.location)!.file;
// Preserve file ids computed off the testDir.
const relativeFile = path.relative(testDir, fileSuite.location!.file);
const fileId = calculateSha1(toPosixPath(relativeFile)).slice(0, 20);

The fileId is calculated based only on the file path relative to its project's testDir. But projects can have different testDirs. This gives the same fileId to all files in all projects with the same path relative to their project "root".

It seems to me like using fileName instead of relativeFile as the argument to calculateSha1() would fix it. But I'm not sure what the significance is of the comment on line 247.


It's also possible to get the opposite problem if I add a third project in the above config like this:

{ name: 'c', testDir: './', testMatch: '**/tests/a/**/*.spec.ts' }

Running tests for projects a and c causes the tests for project a and c to be listed under different file headers even though they're from the same file. I think this is less problematic.

Environment

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    Container: Yes
  npmPackages:
    @playwright/test: ^1.48.2 => 1.48.2

(Some info omitted because I don't think it's relevant.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants