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

This commit is contained in:
Max Schmitt 2022-08-09 20:06:06 +02:00 committed by GitHub
parent 5dea817355
commit e725b5f8a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 13 deletions

View File

@ -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

View File

@ -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';

View File

@ -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>;

View File

@ -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:

View File

@ -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');
});

View File

@ -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>;

View File

@ -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;

View File

@ -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';