Skip to content

Commit

Permalink
fix(esm): fix TS type check with NodeNext mode (#16340)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Aug 9, 2022
1 parent 5dea817 commit e725b5f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/playwright-core/types/structs.d.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/types/types.d.ts
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-test/types/test.d.ts
Expand Up @@ -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>;

Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-test/types/testReporter.d.ts
Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions tests/installation/typescript-types.spec.ts
Expand Up @@ -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 typescript@4.7 @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', 'typescript@4.7', 'tsc', '--module nodenext', filename);
}

await exec('npx', '-p', 'typescript@4.7', 'tsc', '--module nodenext', 'playwright-test-types.ts');
});
4 changes: 2 additions & 2 deletions utils/generate_types/overrides-test.d.ts
Expand Up @@ -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>;

Expand Down
4 changes: 2 additions & 2 deletions utils/generate_types/overrides-testReporter.d.ts
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions utils/generate_types/overrides.d.ts
Expand Up @@ -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';
Expand Down

0 comments on commit e725b5f

Please sign in to comment.