Skip to content

Commit

Permalink
feat: split test from index
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifigueira committed Oct 20, 2023
1 parent 83f81c0 commit a194c82
Show file tree
Hide file tree
Showing 11 changed files with 7,241 additions and 20 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
!lib/**/*.mjs
# Include generated types and entrypoint.
!index.d.ts
!test.d.ts
!src/types/types.d.ts
!playwright/packages/playwright-core/types/types.d.ts
!playwright/packages/playwright/types/test.d.ts
Expand Down
5 changes: 4 additions & 1 deletion examples/todomvc-crx/src/todos.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from "playwright-crx";
import { Page, expect } from "playwright-crx/test";

export async function createTodos(page: Page) {

Expand All @@ -25,4 +25,7 @@ export async function createTodos(page: Page) {
await newTodo.fill(item);
await newTodo.press('Enter');
}

// assertions work too
await expect(page.getByTestId('todo-title')).toHaveText(TODO_ITEMS);
}
6 changes: 1 addition & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/

import type { Crx } from './src/types/types';
export type { Crx, CrxApplication, CrxRecorder } from './src/types/types';
export type { Page, Frame, BrowserContext, Worker, JSHandle, ElementHandle, Locator, BrowserType, CDPSession, Accessibility, ElectronApplication, Android, AndroidDevice, AndroidInput, AndroidSocket, AndroidWebView, APIRequest, APIRequestContext, APIResponse, Browser, BrowserServer, ConsoleMessage, Coverage, Dialog, Download, Electron, FileChooser, FrameLocator, Keyboard, Logger, Mouse, Request, Response, Route, Selectors, Touchscreen, Tracing, Video, WebError, WebSocket, BrowserContextOptions, ViewportSize, HTTPCredentials, Geolocation, LaunchOptions, ConnectOverCDPOptions, ConnectOptions, LocatorScreenshotOptions, Cookie, PageScreenshotOptions, ChromiumBrowserContext, ChromiumBrowser, FirefoxBrowser, WebKitBrowser, ChromiumCoverage } from './playwright/packages/playwright-core/types/types';
export type { expect, test } from './playwright/packages/playwright/types/test';
export * from './src/types/types';

export const crx: Crx;

export function _setUnderTest(): void;
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"examples:build:recorder": "npm run build --prefix ./examples/recorder-crx",
"examples:build": "npm run examples:build:todomvc && npm run examples:build:recorder",
"examples:clean": "rimraf ./examples/recorder-crx/dist && rimraf ./examples/todomvc-crx/dist",
"build:crx": "npm run pw:generate-injected && vite build",
"build:crx": "npm run pw:generate-injected && node ./utils/generate_test_types.js && vite build",
"build": "npm run pw:ci:bundles && npm run build:crx && npm run examples:build",
"clean": "npm run pw:clean && npm run examples:clean && rimraf ./lib"
},
Expand All @@ -33,8 +33,14 @@
".": {
"types": "./index.d.ts",
"import": "./lib/index.mjs",
"require": "./lib/index.umd.js",
"default": "./lib/index.umd.js"
"require": "./lib/index.js",
"default": "./lib/index.js"
},
"./test": {
"types": "./test.d.ts",
"import": "./lib/test.mjs",
"require": "./lib/test.js",
"default": "./lib/test.js"
},
"./package.json": "./package.json"
},
Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import './shims/global';
import './protocol/validator';

import { DispatcherConnection, RootDispatcher } from 'playwright-core/lib/server';
import { setUnderTest } from 'playwright-core/lib/utils';
import { CrxConnection } from './client/crxConnection';
import type { CrxPlaywright as CrxPlaywrightAPI } from './client/crxPlaywright';
import { CrxPlaywright } from './server/crxPlaywright';
import { CrxPlaywrightDispatcher } from './server/dispatchers/crxPlaywrightDispatcher';
export { expect, test } from '@playwright/test/lib/index';

const playwright = new CrxPlaywright();

Expand All @@ -48,6 +46,5 @@ clientConnection.onmessage = message => setImmediate(() => dispatcherConnection.
clientConnection.toImpl = (x: any) => x ? dispatcherConnection._dispatchers.get(x._guid)!._object : dispatcherConnection._dispatchers.get('');
(playwrightAPI as any)._toImpl = clientConnection.toImpl;

export const _setUnderTest = setUnderTest;
export const { _crx: crx } = playwrightAPI;
export default playwrightAPI;
18 changes: 18 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) Rui Figueira.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from '.';
export { expect, test } from '@playwright/test/lib/index';
Loading

0 comments on commit a194c82

Please sign in to comment.