Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(esm): fix TS type check with NodeNext mode (#16340)

Max Schmitte725b5f8a978
diff --git a/packages/playwright-core/types/structs.d.ts b/packages/playwright-core/types/structs.d.ts
index 0f9afa5bdd..eadbb2de01 100644
--- a/packages/playwright-core/types/structs.d.ts
+++ b/packages/playwright-core/types/structs.d.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { JSHandle, ElementHandle, Frame, Page, BrowserContext } from 'playwright-core';
+import { JSHandle, ElementHandle, Frame, Page, BrowserContext } from './types';
/**
* Can be converted to JSON
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index 4f73d2ebfc..6c4fe958b0 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { Protocol } from 'playwright-core/types/protocol';
import { ChildProcess } from 'child_process';
import { EventEmitter } from 'events';
import { Readable } from 'stream';
import { ReadStream } from 'fs';
-import { Serializable, EvaluationArgument, PageFunction, PageFunctionOn, SmartHandle, ElementHandleForTag, BindingSource } from 'playwright-core/types/structs';
+import { Protocol } from './protocol';
+import { Serializable, EvaluationArgument, PageFunction, PageFunctionOn, SmartHandle, ElementHandleForTag, BindingSource } from './structs';
type PageWaitForSelectorOptionsNotHidden = PageWaitForSelectorOptions & {
state?: 'visible'|'attached';
diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts
index 8a81e12060..dbdebf6645 100644
--- a/packages/playwright-test/types/test.d.ts
+++ b/packages/playwright-test/types/test.d.ts
@@ -3042,8 +3042,8 @@ export interface PlaywrightTestArgs {
export type PlaywrightTestProject<TestArgs = {}, WorkerArgs = {}> = Project<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
export type PlaywrightTestConfig<TestArgs = {}, WorkerArgs = {}> = Config<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
-import type * as expectType from '@playwright/test/types/expect-types';
-import type { Suite } from '@playwright/test/types/testReporter';
+import type * as expectType from './expect-types';
+import type { Suite } from './testReporter';
type AsymmetricMatcher = Record<string, any>;
diff --git a/packages/playwright-test/types/testReporter.d.ts b/packages/playwright-test/types/testReporter.d.ts
index ec1a2b1b73..cc3a731b22 100644
--- a/packages/playwright-test/types/testReporter.d.ts
+++ b/packages/playwright-test/types/testReporter.d.ts
@@ -15,8 +15,8 @@
* limitations under the License.
*/
-import type { FullConfig, FullProject, TestStatus, TestError, Metadata } from '@playwright/test';
-export type { FullConfig, TestStatus, TestError } from '@playwright/test';
+import type { FullConfig, FullProject, TestStatus, TestError, Metadata } from './test';
+export type { FullConfig, TestStatus, TestError } from './test';
/**
* `Suite` is a group of tests. All tests in Playwright Test form the following hierarchy:
diff --git a/tests/installation/typescript-types.spec.ts b/tests/installation/typescript-types.spec.ts
index 5db62d2f80..26748d722e 100755
--- a/tests/installation/typescript-types.spec.ts
+++ b/tests/installation/typescript-types.spec.ts
@@ -35,3 +35,26 @@ test('typescript types should work', async ({ exec, tsc, writeFiles }) => {
await tsc('playwright-test-types.ts');
});
+
+test('typescript types should work with module: NodeNext', async ({ exec, tsc, writeFiles }) => {
+ // module: NodeNext got added in TypeScript 4.7
+ await exec('npm i --foreground-scripts [email protected] @types/node@18');
+ const libraryPackages = [
+ 'playwright',
+ 'playwright-core',
+ 'playwright-firefox',
+ 'playwright-webkit',
+ 'playwright-chromium',
+ ];
+ await exec('npm i @playwright/test', ...libraryPackages, { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
+
+ for (const libraryPackage of libraryPackages) {
+ const filename = libraryPackage + '.ts';
+ await writeFiles({
+ [filename]: `import { Page } from '${libraryPackage}';`,
+ });
+ await exec('npx', '-p', '[email protected]', 'tsc', '--module nodenext', filename);
+ }
+
+ await exec('npx', '-p', '[email protected]', 'tsc', '--module nodenext', 'playwright-test-types.ts');
+});
diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts
index 507fbc6ec4..6d1ccfc937 100644
--- a/utils/generate_types/overrides-test.d.ts
+++ b/utils/generate_types/overrides-test.d.ts
@@ -252,8 +252,8 @@ export interface PlaywrightTestArgs {
export type PlaywrightTestProject<TestArgs = {}, WorkerArgs = {}> = Project<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
export type PlaywrightTestConfig<TestArgs = {}, WorkerArgs = {}> = Config<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
-import type * as expectType from '@playwright/test/types/expect-types';
-import type { Suite } from '@playwright/test/types/testReporter';
+import type * as expectType from './expect-types';
+import type { Suite } from './testReporter';
type AsymmetricMatcher = Record<string, any>;
diff --git a/utils/generate_types/overrides-testReporter.d.ts b/utils/generate_types/overrides-testReporter.d.ts
index 0461cbb5c6..019417fb95 100644
--- a/utils/generate_types/overrides-testReporter.d.ts
+++ b/utils/generate_types/overrides-testReporter.d.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import type { FullConfig, FullProject, TestStatus, TestError, Metadata } from '@playwright/test';
-export type { FullConfig, TestStatus, TestError } from '@playwright/test';
+import type { FullConfig, FullProject, TestStatus, TestError, Metadata } from './test';
+export type { FullConfig, TestStatus, TestError } from './test';
export interface Suite {
project(): FullProject | undefined;
diff --git a/utils/generate_types/overrides.d.ts b/utils/generate_types/overrides.d.ts
index ddf7d3528b..4c9ab930dc 100644
--- a/utils/generate_types/overrides.d.ts
+++ b/utils/generate_types/overrides.d.ts
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { Protocol } from 'playwright-core/types/protocol';
import { ChildProcess } from 'child_process';
import { EventEmitter } from 'events';
import { Readable } from 'stream';
import { ReadStream } from 'fs';
-import { Serializable, EvaluationArgument, PageFunction, PageFunctionOn, SmartHandle, ElementHandleForTag, BindingSource } from 'playwright-core/types/structs';
+import { Protocol } from './protocol';
+import { Serializable, EvaluationArgument, PageFunction, PageFunctionOn, SmartHandle, ElementHandleForTag, BindingSource } from './structs';
type PageWaitForSelectorOptionsNotHidden = PageWaitForSelectorOptions & {
state?: 'visible'|'attached';