fix playwright being imported before toImpl could be registered (#3632)

This commit is contained in:
Joel Einbinder 2020-08-26 02:52:23 -07:00 committed by GitHub
parent a6b9922eb8
commit f9eeb2984a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 6 deletions

View File

@ -22,7 +22,7 @@ import * as pirates from 'pirates';
import * as babel from '@babel/core';
import * as sourceMapSupport from 'source-map-support';
const version = 1;
const version = 2;
const cacheDir = path.join(os.tmpdir(), 'playwright-transform-cache');
const sourceMaps: Map<string, string> = new Map();
@ -59,8 +59,9 @@ export function installTransform(): () => void {
const result = babel.transformFileSync(filename, {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript'],
['@babel/preset-env', { targets: {node: 'current'} }],
['@babel/preset-typescript', { onlyRemoveTypeImports: true }],
],
sourceMaps: true,
});
if (result.code) {

View File

@ -0,0 +1,4 @@
global.foo = true;
module.exports = {
abc: 123
};

View File

@ -0,0 +1,11 @@
import '../../';
import { abc } from "./global-foo";
it('should find global foo', () => {
expect(global['foo']).toBe(true);
});
it('should work with type annotations', () => {
const x: number = 5;
expect(x).toBe(5);
});

View File

@ -76,6 +76,11 @@ it('should collect stdio', async() => {
expect(stderr).toEqual([{ text: 'stderr text' }, { buffer: Buffer.from('stderr buffer').toString('base64') }]);
});
it('should work with typescript', async() => {
const result = await runTest('typescript.ts');
expect(result.exitCode).toBe(0);
});
async function runTest(filePath: string, timeout = 10000) {
const outputDir = path.join(__dirname, 'test-results')
await removeFolderAsync(outputDir).catch(e => {});

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { options } from '../playwright.fixtures';
import { ChromiumBrowserContext, ChromiumBrowser } from "../../types/types";
import type { ChromiumBrowserContext, ChromiumBrowser } from "../../types/types";
it.skip(!options.CHROMIUM)('should work', async function({page}) {
const client = await (page.context() as ChromiumBrowserContext).newCDPSession(page);

View File

@ -16,7 +16,7 @@
import { options } from '../playwright.fixtures';
import { registerFixture } from '../../test-runner';
import {ElectronApplication, ElectronLauncher, ElectronPage} from '../../electron-types';
import type {ElectronApplication, ElectronLauncher, ElectronPage} from '../../electron-types';
import path from 'path';
const electronName = process.platform === 'win32' ? 'electron.cmd' : 'electron';

View File

@ -18,7 +18,7 @@ import fs from 'fs';
import path from 'path';
import os from 'os';
import childProcess from 'child_process';
import { LaunchOptions, BrowserType, Browser, BrowserContext, Page, BrowserServer } from '../index';
import type { LaunchOptions, BrowserType, Browser, BrowserContext, Page, BrowserServer } from '../index';
import { TestServer } from '../utils/testserver';
import { Connection } from '../lib/client/connection';
import { Transport } from '../lib/protocol/transport';