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]: Playwright Test should export the Location interface #32680

Closed
jan-molak opened this issue Sep 18, 2024 · 1 comment · Fixed by #32687
Closed

[Bug]: Playwright Test should export the Location interface #32680

jan-molak opened this issue Sep 18, 2024 · 1 comment · Fixed by #32687
Assignees
Labels

Comments

@jan-molak
Copy link
Contributor

jan-molak commented Sep 18, 2024

Version

1.48.0-alpha-2024-09-18

Steps to reproduce

PR #32504 introduces an overridable location parameter for the test.step API, to be included in Playwright 1.48.0.

When testing the new test.step API using build 1.48.0-alpha-2024-09-18, I noticed that the Location type used by the location parameter is not exported from @playwright/test. This results in TypeScript throwing error TS2353: Object literal may only specify known properties, and 'file' does not exist in type 'Location'. during type checking, as TypeScript assumes that Location refers to Location type from lib-dom, rather than Playwright's Location interface.

To reproduce the error, write a Playwright Test script overriding the location parameter when calling the test.step API:

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

test.describe('Playwright Test', () => {

    test('should allow for the location to be overridden', async () => {

        await test.step(
            'my step',
            async () => { },
            { location: { file: 'my-file.ts', line: 42, column: 13 } }
        );
    });
});

Add a tsconfig.json file to your project, for example:

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "esModuleInterop": true,
    "strict": true,
    "skipLibCheck": true
  }
}

Run the TypeScript type checker:

npx tsc --noEmit && npx playwright test

Observe the below error in the output:

spec/repro.spec.ts:25:27 - error TS2353: Object literal may only specify known properties, and 'file' does not exist in type 'Location'.

25             { location: { file: 'my-file.ts', line: 42, column: 13 } }

Expected behavior

The Location type should be exported alongside other public interfaces of @playwright/test.
For example, it should be possible to do the following:

import { test, type TestInfo, type Location } from '@playwright/test'

I'd suggest moving the definition of Playwright's Location from testReporter.d.ts to playwright/types/test.d.ts since it's now part of the public API.

Actual behavior

The Location is not exported

Additional context

See #32504 and the corresponding feature request #30160 for more context

CC @dgozman, @osohyun0224, @vitalets, @WestonThayer

Environment

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 28.66 GB / 96.00 GB
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
  Languages:
    Bash: 3.2.57 - /bin/bash
@jan-molak
Copy link
Contributor Author

Thanks, @mxschmitt, I can confirm the Location interface works correctly in 1.48.0-alpha-2024-09-19. Great work 👍🏻

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.

2 participants