From 37ec3a6ae61a403800d3225d0f03d175cf0be977 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 26 May 2020 17:19:05 -0700 Subject: [PATCH] fix(types): properly export typescript types from packages (#2364) Drive-by: move package tests from `//test/installation-tests` to `//packages/installation-tests` Fix #2349 --- .github/workflows/tests.yml | 2 +- packages/README.md | 2 +- .../installation-tests/.gitignore | 0 .../installation-tests/README.md | 0 .../installation-tests/installation-tests.sh | 30 ++++++++++++++----- .../installation-tests/sanity.js | 0 packages/playwright-chromium/index.d.ts | 4 +-- packages/playwright-core/index.d.ts | 22 ++++++++++++++ packages/playwright-firefox/index.d.ts | 4 +-- packages/playwright-webkit/index.d.ts | 4 +-- packages/playwright/index.d.ts | 4 +-- 11 files changed, 55 insertions(+), 17 deletions(-) rename {test => packages}/installation-tests/.gitignore (100%) rename {test => packages}/installation-tests/README.md (100%) rename {test => packages}/installation-tests/installation-tests.sh (83%) rename {test => packages}/installation-tests/sanity.js (100%) create mode 100644 packages/playwright-core/index.d.ts diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ded9dcfa81..c9cc92172c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -283,7 +283,7 @@ jobs: node-version: ${{ matrix.node_version }} - uses: microsoft/playwright-github-action@v1 - run: npm ci - - run: bash test/installation-tests/installation-tests.sh + - run: bash packages/installation-tests/installation-tests.sh headful_linux: name: "Headful Linux" diff --git a/packages/README.md b/packages/README.md index b059cb8eb1..6333b66c6b 100644 --- a/packages/README.md +++ b/packages/README.md @@ -39,7 +39,7 @@ $ ls ./packages/playwright # inspect the folder ## Testing packages -To test packages, use [`//tests/installation-tests/installation-tests.sh`](../tests/installation-tests/installation-tests.sh). +To test packages, use [`//packages/installation-tests/installation-tests.sh`](./installation-tests/installation-tests.sh). ## Publishing packages diff --git a/test/installation-tests/.gitignore b/packages/installation-tests/.gitignore similarity index 100% rename from test/installation-tests/.gitignore rename to packages/installation-tests/.gitignore diff --git a/test/installation-tests/README.md b/packages/installation-tests/README.md similarity index 100% rename from test/installation-tests/README.md rename to packages/installation-tests/README.md diff --git a/test/installation-tests/installation-tests.sh b/packages/installation-tests/installation-tests.sh similarity index 83% rename from test/installation-tests/installation-tests.sh rename to packages/installation-tests/installation-tests.sh index 68045b1ace..4c4513d26e 100755 --- a/test/installation-tests/installation-tests.sh +++ b/packages/installation-tests/installation-tests.sh @@ -26,6 +26,7 @@ SANITY_JS="$(pwd -P)/../sanity.js" TEST_ROOT="$(pwd -P)" function run_tests { + test_typescript_types test_skip_browser_download test_playwright_global_installation_subsequent_installs test_playwright_should_work @@ -35,11 +36,32 @@ function run_tests { test_playwright_global_installation } +function test_typescript_types { + initialize_test "${FUNCNAME[0]}" + + # install all packages. + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_CORE_TGZ} + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ} + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_FIREFOX_TGZ} + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_WEBKIT_TGZ} + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_CHROMIUM_TGZ} + + # typecheck all packages. + for PKG_NAME in "playwright" \ + "playwright-core" \ + "playwright-firefox" \ + "playwright-chromium" \ + "playwright-webkit" + do + echo "Checking types of ${PKG_NAME}" + echo "import { Page } from '${PKG_NAME}';" > "${PKG_NAME}.ts" && tsc "${PKG_NAME}.ts" + done; +} + function test_playwright_global_installation { initialize_test "${FUNCNAME[0]}" local BROWSERS="$(pwd -P)/browsers" - PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_CORE_TGZ} PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_TGZ} if [[ ! -d "${BROWSERS}" ]]; then echo "Directory for shared browsers was not created!" @@ -61,7 +83,6 @@ function test_playwright_global_installation_subsequent_installs { local BROWSERS="$(pwd -P)/browsers" mkdir install-1 && pushd install-1 && npm init -y - PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_CORE_TGZ} PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_TGZ} # Note: the `npm install` would not actually crash, the error # is merely logged to the console. To reproduce the error, we should make @@ -74,7 +95,6 @@ function test_playwright_global_installation_subsequent_installs { function test_skip_browser_download { initialize_test "${FUNCNAME[0]}" - npm install ${PLAYWRIGHT_CORE_TGZ} OUTPUT=$(PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ}) if [[ "${OUTPUT}" != *"Skipping browsers download because"* ]]; then echo "missing log message that browsers download is skipped" @@ -90,7 +110,6 @@ function test_skip_browser_download { function test_playwright_should_work { initialize_test "${FUNCNAME[0]}" - npm install ${PLAYWRIGHT_CORE_TGZ} npm install ${PLAYWRIGHT_TGZ} cp ${SANITY_JS} . && node sanity.js playwright chromium firefox webkit } @@ -98,7 +117,6 @@ function test_playwright_should_work { function test_playwright_chromium_should_work { initialize_test "${FUNCNAME[0]}" - npm install ${PLAYWRIGHT_CORE_TGZ} npm install ${PLAYWRIGHT_CHROMIUM_TGZ} cp ${SANITY_JS} . && node sanity.js playwright-chromium chromium } @@ -106,7 +124,6 @@ function test_playwright_chromium_should_work { function test_playwright_webkit_should_work { initialize_test "${FUNCNAME[0]}" - npm install ${PLAYWRIGHT_CORE_TGZ} npm install ${PLAYWRIGHT_WEBKIT_TGZ} cp ${SANITY_JS} . && node sanity.js playwright-webkit webkit } @@ -114,7 +131,6 @@ function test_playwright_webkit_should_work { function test_playwright_firefox_should_work { initialize_test "${FUNCNAME[0]}" - npm install ${PLAYWRIGHT_CORE_TGZ} npm install ${PLAYWRIGHT_FIREFOX_TGZ} cp ${SANITY_JS} . && node sanity.js playwright-firefox firefox } diff --git a/test/installation-tests/sanity.js b/packages/installation-tests/sanity.js similarity index 100% rename from test/installation-tests/sanity.js rename to packages/installation-tests/sanity.js diff --git a/packages/playwright-chromium/index.d.ts b/packages/playwright-chromium/index.d.ts index 872acf1212..a5d8a610be 100644 --- a/packages/playwright-chromium/index.d.ts +++ b/packages/playwright-chromium/index.d.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as types from 'playwright-core/types/types'; +import * as types from './types/types'; -export * from 'playwright-core/types/types'; +export * from './types/types'; export const chromium: types.BrowserType; diff --git a/packages/playwright-core/index.d.ts b/packages/playwright-core/index.d.ts new file mode 100644 index 0000000000..4e7b270a07 --- /dev/null +++ b/packages/playwright-core/index.d.ts @@ -0,0 +1,22 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * 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. + */ + +import * as types from './types/types'; + +export * from './types/types'; +export const webkit: types.BrowserType; +export const chromium: types.BrowserType; +export const firefox: types.BrowserType; diff --git a/packages/playwright-firefox/index.d.ts b/packages/playwright-firefox/index.d.ts index 894df7d615..dc34fe5d12 100644 --- a/packages/playwright-firefox/index.d.ts +++ b/packages/playwright-firefox/index.d.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as types from 'playwright-core/types/types'; +import * as types from './types/types'; -export * from 'playwright-core/types/types'; +export * from './types/types'; export const firefox: types.BrowserType; diff --git a/packages/playwright-webkit/index.d.ts b/packages/playwright-webkit/index.d.ts index 45cbed44d9..6da7c60d11 100644 --- a/packages/playwright-webkit/index.d.ts +++ b/packages/playwright-webkit/index.d.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as types from 'playwright-core/types/types'; +import * as types from './types/types'; -export * from 'playwright-core/types/types'; +export * from './types/types'; export const webkit: types.BrowserType; diff --git a/packages/playwright/index.d.ts b/packages/playwright/index.d.ts index a5bc85a60f..4e7b270a07 100644 --- a/packages/playwright/index.d.ts +++ b/packages/playwright/index.d.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import * as types from 'playwright-core/types/types'; +import * as types from './types/types'; -export * from 'playwright-core/types/types'; +export * from './types/types'; export const webkit: types.BrowserType; export const chromium: types.BrowserType; export const firefox: types.BrowserType;