From d55bb76539b561faa53eac61f7a391ea509a9e8b Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 08:27:18 +0000 Subject: [PATCH 01/14] fix: wider compat TS types and CI checks to ensure correct type defs This PR improves our TS types further to make sure they are usable in a TS environment where ES Modules are the target output. Our use of `export =` is problematic this environment as TypeScript does not allow `export =` to be used and it errors. The fix for the type issues to avoid `export =` is to instead define the functions that you gain access to when you import Puppeteer as top level functions in our `types.d.ts` file. We can do this by declaring them explicitly in `src/node.ts`. These are then rolled into `lib/types.d.ts` at build time. The downside to this is that we have to keep those declarations in sync with the Puppeteer API; should we add a new method to the `Puppeteer` class, we must add it to the `nodes.ts` declarations. However, this could easily be automated by a small script that walks the AST and generates these. I will do that in a follow-up PR, but I consider this low risk given how rarely the very top level API of Puppeteer changes. The nice thing about this approach is we no longer need our script that hacks on changes to `lib/types.d.ts`. To avoid yet more releases to fix issues in one particular TS environment, this PR also includes a suite of example setups that we test on each CI run. Each sample folder contains `good.ts`, which should have no TS errors, and `bad.ts`, which should have some errors. The test first packs Puppeteer into a tar, and then installs it from that tar into each project. This should replicate how the published package behaves when it is installed. We then check that we get no errors on `good.ts`, and the expected errors on `bad.ts`. We have a variety of test projects that cover both TS and JS source code, and CJS and ESM imports and outputs. --- .github/workflows/main.yml | 4 + .github/workflows/publish-on-tag.yml | 4 +- .gitignore | 2 + package.json | 3 +- scripts/add-default-export-to-types.ts | 33 ---- scripts/test-ts-definition-files.ts | 176 ++++++++++++++++++ src/api-docs-entry.ts | 83 +++++++++ src/common/NetworkConditions.ts | 6 + test-ts-types/js-cjs-import-cjs-output/bad.js | 18 ++ .../js-cjs-import-cjs-output/good.js | 17 ++ .../js-cjs-import-cjs-output/package.json | 15 ++ .../js-cjs-import-cjs-output/tsconfig.json | 9 + test-ts-types/js-cjs-import-esm-output/bad.js | 18 ++ .../js-cjs-import-esm-output/good.js | 17 ++ .../js-cjs-import-esm-output/package.json | 15 ++ .../js-cjs-import-esm-output/tsconfig.json | 9 + test-ts-types/js-esm-import-cjs-output/bad.js | 18 ++ .../js-esm-import-cjs-output/good.js | 17 ++ .../js-esm-import-cjs-output/package.json | 15 ++ .../js-esm-import-cjs-output/tsconfig.json | 9 + test-ts-types/js-esm-import-esm-output/bad.js | 18 ++ .../js-esm-import-esm-output/good.js | 17 ++ .../js-esm-import-esm-output/package.json | 15 ++ .../js-esm-import-esm-output/tsconfig.json | 9 + test-ts-types/ts-cjs-import-cjs-output/bad.ts | 17 ++ .../ts-cjs-import-cjs-output/good.ts | 13 ++ .../ts-cjs-import-cjs-output/package.json | 15 ++ .../ts-cjs-import-cjs-output/tsconfig.json | 7 + test-ts-types/ts-esm-import-cjs-output/bad.ts | 18 ++ .../ts-esm-import-cjs-output/good.ts | 13 ++ .../ts-esm-import-cjs-output/package.json | 15 ++ .../ts-esm-import-cjs-output/tsconfig.json | 7 + test-ts-types/ts-esm-import-esm-output/bad.ts | 18 ++ .../ts-esm-import-esm-output/good.ts | 13 ++ .../ts-esm-import-esm-output/package.json | 15 ++ .../ts-esm-import-esm-output/tsconfig.json | 7 + 36 files changed, 670 insertions(+), 35 deletions(-) delete mode 100644 scripts/add-default-export-to-types.ts create mode 100644 scripts/test-ts-definition-files.ts create mode 100644 test-ts-types/js-cjs-import-cjs-output/bad.js create mode 100644 test-ts-types/js-cjs-import-cjs-output/good.js create mode 100644 test-ts-types/js-cjs-import-cjs-output/package.json create mode 100644 test-ts-types/js-cjs-import-cjs-output/tsconfig.json create mode 100644 test-ts-types/js-cjs-import-esm-output/bad.js create mode 100644 test-ts-types/js-cjs-import-esm-output/good.js create mode 100644 test-ts-types/js-cjs-import-esm-output/package.json create mode 100644 test-ts-types/js-cjs-import-esm-output/tsconfig.json create mode 100644 test-ts-types/js-esm-import-cjs-output/bad.js create mode 100644 test-ts-types/js-esm-import-cjs-output/good.js create mode 100644 test-ts-types/js-esm-import-cjs-output/package.json create mode 100644 test-ts-types/js-esm-import-cjs-output/tsconfig.json create mode 100644 test-ts-types/js-esm-import-esm-output/bad.js create mode 100644 test-ts-types/js-esm-import-esm-output/good.js create mode 100644 test-ts-types/js-esm-import-esm-output/package.json create mode 100644 test-ts-types/js-esm-import-esm-output/tsconfig.json create mode 100644 test-ts-types/ts-cjs-import-cjs-output/bad.ts create mode 100644 test-ts-types/ts-cjs-import-cjs-output/good.ts create mode 100644 test-ts-types/ts-cjs-import-cjs-output/package.json create mode 100644 test-ts-types/ts-cjs-import-cjs-output/tsconfig.json create mode 100644 test-ts-types/ts-esm-import-cjs-output/bad.ts create mode 100644 test-ts-types/ts-esm-import-cjs-output/good.ts create mode 100644 test-ts-types/ts-esm-import-cjs-output/package.json create mode 100644 test-ts-types/ts-esm-import-cjs-output/tsconfig.json create mode 100644 test-ts-types/ts-esm-import-esm-output/bad.ts create mode 100644 test-ts-types/ts-esm-import-esm-output/good.ts create mode 100644 test-ts-types/ts-esm-import-esm-output/package.json create mode 100644 test-ts-types/ts-esm-import-esm-output/tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8121a54d05760..37901a9257f9c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,6 +46,10 @@ jobs: npm run generate-docs npm run ensure-correct-devtools-protocol-revision + - name: Run check that types.d.ts file is valid and detects errors. + run: | + npm run test-types-file + - name: Run unit tests env: CHROMIUM: true diff --git a/.github/workflows/publish-on-tag.yml b/.github/workflows/publish-on-tag.yml index b16c1be3fb57b..3d9434677624b 100644 --- a/.github/workflows/publish-on-tag.yml +++ b/.github/workflows/publish-on-tag.yml @@ -3,7 +3,7 @@ name: publish-on-tag on: push: tags: - - '*' + - '*' jobs: publish: @@ -15,6 +15,8 @@ jobs: run: npm install - name: Build run: npm run build + - name: Test types.d.ts file is correct + run: npm run test-types-file - name: Publish puppeteer env: NPM_TOKEN: ${{secrets.NPM_TOKEN_PUPPETEER}} diff --git a/.gitignore b/.gitignore index f37bd118bfcd6..30e29ba3021e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /node_modules/ +test-ts-types/**/node_modules /test/output-chromium /test/output-firefox /test/test-user-data-dir* @@ -18,3 +19,4 @@ test/coverage.json temp/ puppeteer-core-*.tgz new-docs/ +puppeteer-*.tgz diff --git a/package.json b/package.json index ee41af3939ffc..c8ec001dd5c80 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,10 @@ "tsc-esm": "tsc -b src/tsconfig.esm.json", "apply-next-version": "node utils/apply_next_version.js", "test-install": "scripts/test-install.sh", - "generate-d-ts": "npm run tsc && api-extractor run --local --verbose && ts-node -s scripts/add-default-export-to-types.ts", + "generate-d-ts": "api-extractor run --local --verbose", "generate-docs": "npm run generate-d-ts && api-documenter markdown -i temp -o new-docs", "ensure-correct-devtools-protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package", + "test-types-file": "ts-node -s scripts/test-ts-definition-files.ts", "release": "node utils/remove_version_suffix.js && standard-version --commit-all" }, "files": [ diff --git a/scripts/add-default-export-to-types.ts b/scripts/add-default-export-to-types.ts deleted file mode 100644 index 13dc57832a2df..0000000000000 --- a/scripts/add-default-export-to-types.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2021 Google Inc. All rights reserved. - * - * 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 fs from 'fs'; -import path from 'path'; -import packageJson from '../package.json'; - -const typingsLocation = path.resolve(process.cwd(), packageJson.types); - -const fileContents = fs.readFileSync(typingsLocation, { encoding: 'utf-8' }); - -// Default to exposing the Node package as this is the majority of our use case. -// May need reworking in the future when we ship an officially supported browser -// bundle also. -const defaultExportCode = `declare const puppeteer: PuppeteerNode; -export = puppeteer;`; - -const newFileContents = fileContents + `\n${defaultExportCode}`; - -fs.writeFileSync(typingsLocation, newFileContents); diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts new file mode 100644 index 0000000000000..1d06592063222 --- /dev/null +++ b/scripts/test-ts-definition-files.ts @@ -0,0 +1,176 @@ +import { spawnSync, execSync } from 'child_process'; +import { version } from '../package.json'; +import path from 'path'; +const PROJECT_FOLDERS_ROOT = 'test-ts-types'; +const EXPECTED_ERRORS = new Map([ + [ + 'ts-esm-import-esm-output', + [ + "bad.ts(6,35): error TS2551: Property 'launh' does not exist on type", + "bad.ts(8,29): error TS2551: Property 'devics' does not exist on type", + 'bad.ts(12,39): error TS2554: Expected 0 arguments, but got 1.', + ], + ], + [ + 'ts-esm-import-cjs-output', + [ + "bad.ts(6,35): error TS2551: Property 'launh' does not exist on type", + "bad.ts(8,29): error TS2551: Property 'devics' does not exist on type", + 'bad.ts(12,39): error TS2554: Expected 0 arguments, but got 1.', + ], + ], + [ + 'ts-cjs-import-cjs-output', + [ + "bad.ts(5,35): error TS2551: Property 'launh' does not exist on type", + "bad.ts(7,29): error TS2551: Property 'devics' does not exist on type", + 'bad.ts(11,39): error TS2554: Expected 0 arguments, but got 1.', + ], + ], + [ + 'js-cjs-import-cjs-output', + [ + "bad.js(5,35): error TS2551: Property 'launh' does not exist on type", + "bad.js(7,29): error TS2551: Property 'devics' does not exist on type", + 'bad.js(11,39): error TS2554: Expected 0 arguments, but got 1.', + "bad.js(15,9): error TS2322: Type 'ElementHandle | null' is not assignable to type 'ElementHandle'", + ], + ], + [ + 'js-esm-import-cjs-output', + [ + "bad.js(5,35): error TS2551: Property 'launh' does not exist on type", + "bad.js(7,29): error TS2551: Property 'devics' does not exist on type", + 'bad.js(11,39): error TS2554: Expected 0 arguments, but got 1.', + "bad.js(15,9): error TS2322: Type 'ElementHandle | null' is not assignable to type 'ElementHandle'", + ], + ], + [ + 'js-cjs-import-esm-output', + [ + "bad.js(5,35): error TS2551: Property 'launh' does not exist on type", + "bad.js(7,29): error TS2551: Property 'devics' does not exist on type", + 'bad.js(11,39): error TS2554: Expected 0 arguments, but got 1.', + "bad.js(15,9): error TS2322: Type 'ElementHandle | null' is not assignable to type 'ElementHandle'", + ], + ], + [ + 'js-esm-import-esm-output', + [ + "bad.js(5,35): error TS2551: Property 'launh' does not exist on type", + "bad.js(7,29): error TS2551: Property 'devics' does not exist on type", + 'bad.js(11,39): error TS2554: Expected 0 arguments, but got 1.', + "bad.js(15,9): error TS2322: Type 'ElementHandle | null' is not assignable to type 'ElementHandle'", + ], + ], +]); +const PROJECT_FOLDERS = [...EXPECTED_ERRORS.keys()]; + +function packPuppeteer() { + console.log('Packing Puppeteer'); + const result = spawnSync('npm', ['pack'], { + encoding: 'utf-8', + }); + + if (result.status !== 0) { + console.log('Failed to pack Puppeteer', result.stderr); + process.exit(1); + } + + return `puppeteer-${version}.tgz`; +} + +const tar = packPuppeteer(); +const tarPath = path.join(process.cwd(), tar); + +function compileAndCatchErrors(projectLocation) { + let failed = false; + let tsErrorMesssage: string[] = []; + try { + execSync(`cd ${projectLocation} && npm run compile`, { + encoding: 'utf-8', + stdio: 'pipe', // means the output isn't logged by default + }); + } catch (error) { + // We expect to always get here, as each project has some typos to test if + // our types are used correctly to catch errors; + failed = true; + tsErrorMesssage = (error.stdout as string).split('\n'); + } + + if (!failed) { + console.error( + `Running tsc on ${projectLocation} succeeded without triggering the expected errors.` + ); + process.exit(1); + } + + return { + failed, + tsErrorMesssage, + }; +} + +function testProject(folder: string) { + console.log('\nTesting:', folder); + const projectLocation = path.join( + process.cwd(), + PROJECT_FOLDERS_ROOT, + folder + ); + const tarLocation = path.relative(projectLocation, tarPath); + console.log('===> Installing Puppeteer from tar file'); + execSync( + `cd ${projectLocation} && PUPPETEER_SKIP_DOWNLOAD=1 npm install ${tarLocation}`, + { encoding: 'utf-8' } + ); + console.log('===> Running compile to ensure expected errors only.'); + const result = compileAndCatchErrors(projectLocation); + const expectedErrors = EXPECTED_ERRORS.get(folder) || []; + if ( + result.tsErrorMesssage.find( + (line) => line.includes('good.ts') || line.includes('good.js') + ) + ) { + console.error( + `Error for ${projectLocation} contained unexpected failures in good.ts/good.js:\n${result.tsErrorMesssage}` + ); + process.exit(1); + } + const errorsInTsMessage = result.tsErrorMesssage.filter( + (line) => line.includes('bad.ts') || line.includes('bad.js') + ); + const expectedErrorsThatHaveOccurred = new Set(); + const unexpectedErrors = errorsInTsMessage.filter((message) => { + const isExpected = expectedErrors.some((expectedError) => { + const isExpected = message.startsWith(expectedError); + if (isExpected) { + expectedErrorsThatHaveOccurred.add(expectedError); + } + return isExpected; + }); + return !isExpected; + }); + + if (unexpectedErrors.length) { + console.error( + `${projectLocation} had unexpected TS errors: ${unexpectedErrors.join( + '\n' + )}` + ); + process.exit(1); + } + expectedErrors.forEach((expected) => { + if (!expectedErrorsThatHaveOccurred.has(expected)) { + console.error( + `${projectLocation} expected error that was not thrown: ${expected}` + ); + process.exit(1); + } + }); + console.log('===> ✅ Type checked correctly.'); +} + +PROJECT_FOLDERS.forEach((folder) => { + testProject(folder); +}); diff --git a/src/api-docs-entry.ts b/src/api-docs-entry.ts index d033a3ed7c36a..db910e1ee6bd4 100644 --- a/src/api-docs-entry.ts +++ b/src/api-docs-entry.ts @@ -14,6 +14,18 @@ * limitations under the License. */ +import { LaunchOptions, ChromeArgOptions } from './node/LaunchOptions.js'; +import { BrowserOptions } from './common/BrowserConnector.js'; +import { Product } from './common/Product.js'; +import { Browser } from './common/Browser.js'; +import { ConnectOptions } from './common/Puppeteer.js'; +import { DevicesMap } from './common/DeviceDescriptors.js'; +import { PuppeteerErrors } from './common/Errors.js'; +import { PredefinedNetworkConditions } from './common/NetworkConditions.js'; +import { CustomQueryHandler } from './common/QueryHandler.js'; +import type { Puppeteer } from './common/Puppeteer.js'; +import type { PuppeteerNode } from './node/Puppeteer.js'; + /* * This file re-exports any APIs that we want to have documentation generated * for. It is used by API Extractor to determine what parts of the system to @@ -62,4 +74,75 @@ export * from './common/PDFOptions.js'; export * from './common/TimeoutSettings.js'; export * from './common/LifecycleWatcher.js'; export * from './common/QueryHandler.js'; +export * from './common/NetworkConditions.js'; export * from 'devtools-protocol/types/protocol'; + +/* + * We maintain a namespace that emulates the API of the Puppeteer instance you + * get when you `import puppeteer from 'puppeteer'. + * + * We do this as a namespace because export = PuppeteerDefault where + * PuppeteerDefault is a namespace seems to make sure that the types work in + * both ESM and CJS contexts. + * + * This namespace must be kept in sync with the public API offered by the + * PuppeteerNode class. + */ + +/** + * @public + * {@inheritDoc PuppeteerNode.launch} + */ +export declare function launch( + options?: LaunchOptions & + ChromeArgOptions & + BrowserOptions & { + product?: Product; + extraPrefsFirefox?: Record; + } +): Promise; + +/** + * @public + * {@inheritDoc PuppeteerNode.connect} + */ +export declare function connect(options: ConnectOptions): Promise; + +/** + * @public + * {@inheritDoc Puppeteer.devices} + */ +export let devices: DevicesMap; +/** + * @public + */ +export let errors: PuppeteerErrors; +/** + * @public + */ +export let networkConditions: PredefinedNetworkConditions; + +/** + * @public + * {@inheritDoc Puppeteer.registerCustomQueryHandler} + */ +export declare function registerCustomQueryHandler( + name: string, + queryHandler: CustomQueryHandler +): void; + +/** + * @public + * {@inheritDoc Puppeteer.unregisterCustomQueryHandler} + */ +export declare function unregisterCustomQueryHandler(name: string): void; +/** + * @public + * {@inheritDoc Puppeteer.customQueryHandlerNames} + */ +export declare function customQueryHandlerNames(): string[]; +/** + * @public + * {@inheritDoc Puppeteer.clearCustomQueryHandlers} + */ +export declare function clearCustomQueryHandlers(): void; diff --git a/src/common/NetworkConditions.ts b/src/common/NetworkConditions.ts index c1a89f280bd01..9d03673c25ac4 100644 --- a/src/common/NetworkConditions.ts +++ b/src/common/NetworkConditions.ts @@ -16,8 +16,14 @@ import { NetworkConditions } from './NetworkManager.js'; +/** + * @public + */ export type PredefinedNetworkConditions = { [name: string]: NetworkConditions }; +/** + * @public + */ export const networkConditions: PredefinedNetworkConditions = { 'Slow 3G': { download: ((500 * 1000) / 8) * 0.8, diff --git a/test-ts-types/js-cjs-import-cjs-output/bad.js b/test-ts-types/js-cjs-import-cjs-output/bad.js new file mode 100644 index 0000000000000..be5127947cdb2 --- /dev/null +++ b/test-ts-types/js-cjs-import-cjs-output/bad.js @@ -0,0 +1,18 @@ +const puppeteer = require('puppeteer'); + +async function run() { + // Typo in "launch" + const browser = await puppeteer.launh(); + // Typo: "devices" + const devices = puppeteer.devics; + console.log(devices); + const browser2 = await puppeteer.launch(); + // 'foo' is invalid argument + const page = await browser2.newPage('foo'); + /** + * @type {puppeteer.ElementHandle} + */ + const div = await page.$('div'); + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/js-cjs-import-cjs-output/good.js b/test-ts-types/js-cjs-import-cjs-output/good.js new file mode 100644 index 0000000000000..f4663006078c8 --- /dev/null +++ b/test-ts-types/js-cjs-import-cjs-output/good.js @@ -0,0 +1,17 @@ +const puppeteer = require('puppeteer'); + +async function run() { + const browser = await puppeteer.launch(); + const devices = puppeteer.devices; + console.log(devices); + const page = await browser.newPage(); + const div = await page.$('div'); + if (div) { + /** + * @type {puppeteer.ElementHandle} + */ + const newDiv = div; + console.log('got a div!', newDiv); + } +} +run(); diff --git a/test-ts-types/js-cjs-import-cjs-output/package.json b/test-ts-types/js-cjs-import-cjs-output/package.json new file mode 100644 index 0000000000000..b358b51da6057 --- /dev/null +++ b/test-ts-types/js-cjs-import-cjs-output/package.json @@ -0,0 +1,15 @@ +{ + "name": "test-ts-types-ts-esm", + "version": "1.0.0", + "private": true, + "description": "Test project with TypeScript, ESM output", + "scripts": { + "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + }, + "devDependencies": { + "typescript": "^4.1.3" + }, + "dependencies": { + "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + } +} diff --git a/test-ts-types/js-cjs-import-cjs-output/tsconfig.json b/test-ts-types/js-cjs-import-cjs-output/tsconfig.json new file mode 100644 index 0000000000000..3bd1e2c0543cb --- /dev/null +++ b/test-ts-types/js-cjs-import-cjs-output/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "module": "commonjs", + "checkJs": true, + "allowJs": true, + "strict": true, + "noEmit": true + } +} diff --git a/test-ts-types/js-cjs-import-esm-output/bad.js b/test-ts-types/js-cjs-import-esm-output/bad.js new file mode 100644 index 0000000000000..be5127947cdb2 --- /dev/null +++ b/test-ts-types/js-cjs-import-esm-output/bad.js @@ -0,0 +1,18 @@ +const puppeteer = require('puppeteer'); + +async function run() { + // Typo in "launch" + const browser = await puppeteer.launh(); + // Typo: "devices" + const devices = puppeteer.devics; + console.log(devices); + const browser2 = await puppeteer.launch(); + // 'foo' is invalid argument + const page = await browser2.newPage('foo'); + /** + * @type {puppeteer.ElementHandle} + */ + const div = await page.$('div'); + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/js-cjs-import-esm-output/good.js b/test-ts-types/js-cjs-import-esm-output/good.js new file mode 100644 index 0000000000000..f4663006078c8 --- /dev/null +++ b/test-ts-types/js-cjs-import-esm-output/good.js @@ -0,0 +1,17 @@ +const puppeteer = require('puppeteer'); + +async function run() { + const browser = await puppeteer.launch(); + const devices = puppeteer.devices; + console.log(devices); + const page = await browser.newPage(); + const div = await page.$('div'); + if (div) { + /** + * @type {puppeteer.ElementHandle} + */ + const newDiv = div; + console.log('got a div!', newDiv); + } +} +run(); diff --git a/test-ts-types/js-cjs-import-esm-output/package.json b/test-ts-types/js-cjs-import-esm-output/package.json new file mode 100644 index 0000000000000..b358b51da6057 --- /dev/null +++ b/test-ts-types/js-cjs-import-esm-output/package.json @@ -0,0 +1,15 @@ +{ + "name": "test-ts-types-ts-esm", + "version": "1.0.0", + "private": true, + "description": "Test project with TypeScript, ESM output", + "scripts": { + "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + }, + "devDependencies": { + "typescript": "^4.1.3" + }, + "dependencies": { + "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + } +} diff --git a/test-ts-types/js-cjs-import-esm-output/tsconfig.json b/test-ts-types/js-cjs-import-esm-output/tsconfig.json new file mode 100644 index 0000000000000..6d59d3594223d --- /dev/null +++ b/test-ts-types/js-cjs-import-esm-output/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "module": "esnext", + "checkJs": true, + "allowJs": true, + "strict": true, + "noEmit": true + } +} diff --git a/test-ts-types/js-esm-import-cjs-output/bad.js b/test-ts-types/js-esm-import-cjs-output/bad.js new file mode 100644 index 0000000000000..ba7b56133d4fe --- /dev/null +++ b/test-ts-types/js-esm-import-cjs-output/bad.js @@ -0,0 +1,18 @@ +import * as puppeteer from 'puppeteer'; + +async function run() { + // Typo in "launch" + const browser = await puppeteer.launh(); + // Typo: "devices" + const devices = puppeteer.devics; + console.log(devices); + const browser2 = await puppeteer.launch(); + // 'foo' is invalid argument + const page = await browser2.newPage('foo'); + /** + * @type {puppeteer.ElementHandle} + */ + const div = await page.$('div'); + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/js-esm-import-cjs-output/good.js b/test-ts-types/js-esm-import-cjs-output/good.js new file mode 100644 index 0000000000000..544c43cf8bafb --- /dev/null +++ b/test-ts-types/js-esm-import-cjs-output/good.js @@ -0,0 +1,17 @@ +import * as puppeteer from 'puppeteer'; + +async function run() { + const browser = await puppeteer.launch(); + const devices = puppeteer.devices; + console.log(devices); + const page = await browser.newPage(); + const div = await page.$('div'); + if (div) { + /** + * @type {puppeteer.ElementHandle} + */ + const newDiv = div; + console.log('got a div!', newDiv); + } +} +run(); diff --git a/test-ts-types/js-esm-import-cjs-output/package.json b/test-ts-types/js-esm-import-cjs-output/package.json new file mode 100644 index 0000000000000..b358b51da6057 --- /dev/null +++ b/test-ts-types/js-esm-import-cjs-output/package.json @@ -0,0 +1,15 @@ +{ + "name": "test-ts-types-ts-esm", + "version": "1.0.0", + "private": true, + "description": "Test project with TypeScript, ESM output", + "scripts": { + "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + }, + "devDependencies": { + "typescript": "^4.1.3" + }, + "dependencies": { + "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + } +} diff --git a/test-ts-types/js-esm-import-cjs-output/tsconfig.json b/test-ts-types/js-esm-import-cjs-output/tsconfig.json new file mode 100644 index 0000000000000..3bd1e2c0543cb --- /dev/null +++ b/test-ts-types/js-esm-import-cjs-output/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "module": "commonjs", + "checkJs": true, + "allowJs": true, + "strict": true, + "noEmit": true + } +} diff --git a/test-ts-types/js-esm-import-esm-output/bad.js b/test-ts-types/js-esm-import-esm-output/bad.js new file mode 100644 index 0000000000000..ba7b56133d4fe --- /dev/null +++ b/test-ts-types/js-esm-import-esm-output/bad.js @@ -0,0 +1,18 @@ +import * as puppeteer from 'puppeteer'; + +async function run() { + // Typo in "launch" + const browser = await puppeteer.launh(); + // Typo: "devices" + const devices = puppeteer.devics; + console.log(devices); + const browser2 = await puppeteer.launch(); + // 'foo' is invalid argument + const page = await browser2.newPage('foo'); + /** + * @type {puppeteer.ElementHandle} + */ + const div = await page.$('div'); + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/js-esm-import-esm-output/good.js b/test-ts-types/js-esm-import-esm-output/good.js new file mode 100644 index 0000000000000..544c43cf8bafb --- /dev/null +++ b/test-ts-types/js-esm-import-esm-output/good.js @@ -0,0 +1,17 @@ +import * as puppeteer from 'puppeteer'; + +async function run() { + const browser = await puppeteer.launch(); + const devices = puppeteer.devices; + console.log(devices); + const page = await browser.newPage(); + const div = await page.$('div'); + if (div) { + /** + * @type {puppeteer.ElementHandle} + */ + const newDiv = div; + console.log('got a div!', newDiv); + } +} +run(); diff --git a/test-ts-types/js-esm-import-esm-output/package.json b/test-ts-types/js-esm-import-esm-output/package.json new file mode 100644 index 0000000000000..b358b51da6057 --- /dev/null +++ b/test-ts-types/js-esm-import-esm-output/package.json @@ -0,0 +1,15 @@ +{ + "name": "test-ts-types-ts-esm", + "version": "1.0.0", + "private": true, + "description": "Test project with TypeScript, ESM output", + "scripts": { + "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + }, + "devDependencies": { + "typescript": "^4.1.3" + }, + "dependencies": { + "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + } +} diff --git a/test-ts-types/js-esm-import-esm-output/tsconfig.json b/test-ts-types/js-esm-import-esm-output/tsconfig.json new file mode 100644 index 0000000000000..6d59d3594223d --- /dev/null +++ b/test-ts-types/js-esm-import-esm-output/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "module": "esnext", + "checkJs": true, + "allowJs": true, + "strict": true, + "noEmit": true + } +} diff --git a/test-ts-types/ts-cjs-import-cjs-output/bad.ts b/test-ts-types/ts-cjs-import-cjs-output/bad.ts new file mode 100644 index 0000000000000..9199f8aeea9d2 --- /dev/null +++ b/test-ts-types/ts-cjs-import-cjs-output/bad.ts @@ -0,0 +1,17 @@ +import puppeteer = require('puppeteer'); + +async function run() { + // Typo in "launch" + const browser = await puppeteer.launh(); + // Typo: "devices" + const devices = puppeteer.devics; + console.log(devices); + const browser2 = await puppeteer.launch(); + // 'foo' is invalid argument + const page = await browser2.newPage('foo'); + const div = (await page.$('div')) as puppeteer.ElementHandle< + HTMLAnchorElement + >; + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/ts-cjs-import-cjs-output/good.ts b/test-ts-types/ts-cjs-import-cjs-output/good.ts new file mode 100644 index 0000000000000..d055bf6f6a531 --- /dev/null +++ b/test-ts-types/ts-cjs-import-cjs-output/good.ts @@ -0,0 +1,13 @@ +import puppeteer = require('puppeteer'); + +async function run() { + const browser = await puppeteer.launch(); + const devices = puppeteer.devices; + console.log(devices); + const page = await browser.newPage(); + const div = (await page.$('div')) as puppeteer.ElementHandle< + HTMLAnchorElement + >; + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/ts-cjs-import-cjs-output/package.json b/test-ts-types/ts-cjs-import-cjs-output/package.json new file mode 100644 index 0000000000000..b358b51da6057 --- /dev/null +++ b/test-ts-types/ts-cjs-import-cjs-output/package.json @@ -0,0 +1,15 @@ +{ + "name": "test-ts-types-ts-esm", + "version": "1.0.0", + "private": true, + "description": "Test project with TypeScript, ESM output", + "scripts": { + "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + }, + "devDependencies": { + "typescript": "^4.1.3" + }, + "dependencies": { + "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + } +} diff --git a/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json b/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json new file mode 100644 index 0000000000000..a9d846231b1db --- /dev/null +++ b/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "commonjs", + "strict": true, + "noEmit": true + } +} diff --git a/test-ts-types/ts-esm-import-cjs-output/bad.ts b/test-ts-types/ts-esm-import-cjs-output/bad.ts new file mode 100644 index 0000000000000..4aeb970709652 --- /dev/null +++ b/test-ts-types/ts-esm-import-cjs-output/bad.ts @@ -0,0 +1,18 @@ +// eslint-disable-next-line import/extensions +import * as puppeteer from 'puppeteer'; + +async function run() { + // Typo in "launch" + const browser = await puppeteer.launh(); + // Typo: "devices" + const devices = puppeteer.devics; + console.log(devices); + const browser2 = await puppeteer.launch(); + // 'foo' is invalid argument + const page = await browser2.newPage('foo'); + const div = (await page.$('div')) as puppeteer.ElementHandle< + HTMLAnchorElement + >; + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/ts-esm-import-cjs-output/good.ts b/test-ts-types/ts-esm-import-cjs-output/good.ts new file mode 100644 index 0000000000000..ed7764140d8b6 --- /dev/null +++ b/test-ts-types/ts-esm-import-cjs-output/good.ts @@ -0,0 +1,13 @@ +// eslint-disable-next-line import/extensions +import * as puppeteer from 'puppeteer'; +import type { ElementHandle } from 'puppeteer'; + +async function run() { + const browser = await puppeteer.launch(); + const devices = puppeteer.devices; + console.log(devices); + const page = await browser.newPage(); + const div = (await page.$('div')) as ElementHandle; + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/ts-esm-import-cjs-output/package.json b/test-ts-types/ts-esm-import-cjs-output/package.json new file mode 100644 index 0000000000000..b358b51da6057 --- /dev/null +++ b/test-ts-types/ts-esm-import-cjs-output/package.json @@ -0,0 +1,15 @@ +{ + "name": "test-ts-types-ts-esm", + "version": "1.0.0", + "private": true, + "description": "Test project with TypeScript, ESM output", + "scripts": { + "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + }, + "devDependencies": { + "typescript": "^4.1.3" + }, + "dependencies": { + "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + } +} diff --git a/test-ts-types/ts-esm-import-cjs-output/tsconfig.json b/test-ts-types/ts-esm-import-cjs-output/tsconfig.json new file mode 100644 index 0000000000000..a9d846231b1db --- /dev/null +++ b/test-ts-types/ts-esm-import-cjs-output/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "commonjs", + "strict": true, + "noEmit": true + } +} diff --git a/test-ts-types/ts-esm-import-esm-output/bad.ts b/test-ts-types/ts-esm-import-esm-output/bad.ts new file mode 100644 index 0000000000000..4aeb970709652 --- /dev/null +++ b/test-ts-types/ts-esm-import-esm-output/bad.ts @@ -0,0 +1,18 @@ +// eslint-disable-next-line import/extensions +import * as puppeteer from 'puppeteer'; + +async function run() { + // Typo in "launch" + const browser = await puppeteer.launh(); + // Typo: "devices" + const devices = puppeteer.devics; + console.log(devices); + const browser2 = await puppeteer.launch(); + // 'foo' is invalid argument + const page = await browser2.newPage('foo'); + const div = (await page.$('div')) as puppeteer.ElementHandle< + HTMLAnchorElement + >; + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/ts-esm-import-esm-output/good.ts b/test-ts-types/ts-esm-import-esm-output/good.ts new file mode 100644 index 0000000000000..ed7764140d8b6 --- /dev/null +++ b/test-ts-types/ts-esm-import-esm-output/good.ts @@ -0,0 +1,13 @@ +// eslint-disable-next-line import/extensions +import * as puppeteer from 'puppeteer'; +import type { ElementHandle } from 'puppeteer'; + +async function run() { + const browser = await puppeteer.launch(); + const devices = puppeteer.devices; + console.log(devices); + const page = await browser.newPage(); + const div = (await page.$('div')) as ElementHandle; + console.log('got a div!', div); +} +run(); diff --git a/test-ts-types/ts-esm-import-esm-output/package.json b/test-ts-types/ts-esm-import-esm-output/package.json new file mode 100644 index 0000000000000..b358b51da6057 --- /dev/null +++ b/test-ts-types/ts-esm-import-esm-output/package.json @@ -0,0 +1,15 @@ +{ + "name": "test-ts-types-ts-esm", + "version": "1.0.0", + "private": true, + "description": "Test project with TypeScript, ESM output", + "scripts": { + "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + }, + "devDependencies": { + "typescript": "^4.1.3" + }, + "dependencies": { + "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + } +} diff --git a/test-ts-types/ts-esm-import-esm-output/tsconfig.json b/test-ts-types/ts-esm-import-esm-output/tsconfig.json new file mode 100644 index 0000000000000..bc8fc3aa48cfb --- /dev/null +++ b/test-ts-types/ts-esm-import-esm-output/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "esnext", + "strict": true, + "noEmit": true + } +} From 0225b912fc92b772d3e5a0a6d3010471fb4c3588 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 08:39:07 +0000 Subject: [PATCH 02/14] fix: ignore test files in eslint --- .eslintignore | 1 + src/api-docs-entry.ts | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintignore b/.eslintignore index f4c17fcc0f25e..112136a23142f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -12,3 +12,4 @@ lib/ utils/doclint/generate_types/test/test.ts vendor/ web-test-runner.config.mjs +test-ts-types/ diff --git a/src/api-docs-entry.ts b/src/api-docs-entry.ts index db910e1ee6bd4..63d87aff081dc 100644 --- a/src/api-docs-entry.ts +++ b/src/api-docs-entry.ts @@ -23,8 +23,6 @@ import { DevicesMap } from './common/DeviceDescriptors.js'; import { PuppeteerErrors } from './common/Errors.js'; import { PredefinedNetworkConditions } from './common/NetworkConditions.js'; import { CustomQueryHandler } from './common/QueryHandler.js'; -import type { Puppeteer } from './common/Puppeteer.js'; -import type { PuppeteerNode } from './node/Puppeteer.js'; /* * This file re-exports any APIs that we want to have documentation generated From a74c12e75a6ec03b50f91202fb900005513053e6 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 08:51:53 +0000 Subject: [PATCH 03/14] fix: name of tar file --- scripts/test-ts-definition-files.ts | 2 +- test-ts-types/js-cjs-import-cjs-output/package.json | 2 +- test-ts-types/js-cjs-import-esm-output/package.json | 2 +- test-ts-types/js-esm-import-cjs-output/package.json | 2 +- test-ts-types/js-esm-import-esm-output/package.json | 2 +- test-ts-types/ts-cjs-import-cjs-output/package.json | 2 +- test-ts-types/ts-esm-import-cjs-output/package.json | 2 +- test-ts-types/ts-esm-import-esm-output/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 1d06592063222..60e6df226d7cb 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -121,7 +121,7 @@ function testProject(folder: string) { const tarLocation = path.relative(projectLocation, tarPath); console.log('===> Installing Puppeteer from tar file'); execSync( - `cd ${projectLocation} && PUPPETEER_SKIP_DOWNLOAD=1 npm install ${tarLocation}`, + `cd ${projectLocation} && PUPPETEER_SKIP_DOWNLOAD=1 npm install --no-package-lock ${tarLocation}`, { encoding: 'utf-8' } ); console.log('===> Running compile to ensure expected errors only.'); diff --git a/test-ts-types/js-cjs-import-cjs-output/package.json b/test-ts-types/js-cjs-import-cjs-output/package.json index b358b51da6057..2be7f1642460b 100644 --- a/test-ts-types/js-cjs-import-cjs-output/package.json +++ b/test-ts-types/js-cjs-import-cjs-output/package.json @@ -10,6 +10,6 @@ "typescript": "^4.1.3" }, "dependencies": { - "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" } } diff --git a/test-ts-types/js-cjs-import-esm-output/package.json b/test-ts-types/js-cjs-import-esm-output/package.json index b358b51da6057..2be7f1642460b 100644 --- a/test-ts-types/js-cjs-import-esm-output/package.json +++ b/test-ts-types/js-cjs-import-esm-output/package.json @@ -10,6 +10,6 @@ "typescript": "^4.1.3" }, "dependencies": { - "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" } } diff --git a/test-ts-types/js-esm-import-cjs-output/package.json b/test-ts-types/js-esm-import-cjs-output/package.json index b358b51da6057..2be7f1642460b 100644 --- a/test-ts-types/js-esm-import-cjs-output/package.json +++ b/test-ts-types/js-esm-import-cjs-output/package.json @@ -10,6 +10,6 @@ "typescript": "^4.1.3" }, "dependencies": { - "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" } } diff --git a/test-ts-types/js-esm-import-esm-output/package.json b/test-ts-types/js-esm-import-esm-output/package.json index b358b51da6057..2be7f1642460b 100644 --- a/test-ts-types/js-esm-import-esm-output/package.json +++ b/test-ts-types/js-esm-import-esm-output/package.json @@ -10,6 +10,6 @@ "typescript": "^4.1.3" }, "dependencies": { - "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" } } diff --git a/test-ts-types/ts-cjs-import-cjs-output/package.json b/test-ts-types/ts-cjs-import-cjs-output/package.json index b358b51da6057..2be7f1642460b 100644 --- a/test-ts-types/ts-cjs-import-cjs-output/package.json +++ b/test-ts-types/ts-cjs-import-cjs-output/package.json @@ -10,6 +10,6 @@ "typescript": "^4.1.3" }, "dependencies": { - "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" } } diff --git a/test-ts-types/ts-esm-import-cjs-output/package.json b/test-ts-types/ts-esm-import-cjs-output/package.json index b358b51da6057..2be7f1642460b 100644 --- a/test-ts-types/ts-esm-import-cjs-output/package.json +++ b/test-ts-types/ts-esm-import-cjs-output/package.json @@ -10,6 +10,6 @@ "typescript": "^4.1.3" }, "dependencies": { - "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" } } diff --git a/test-ts-types/ts-esm-import-esm-output/package.json b/test-ts-types/ts-esm-import-esm-output/package.json index b358b51da6057..2be7f1642460b 100644 --- a/test-ts-types/ts-esm-import-esm-output/package.json +++ b/test-ts-types/ts-esm-import-esm-output/package.json @@ -10,6 +10,6 @@ "typescript": "^4.1.3" }, "dependencies": { - "puppeteer": "file:../../puppeteer-7.0.5-post.tgz" + "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" } } From 15638f1a6307a57c12d7c21d31d1a44c4c9a6a32 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 08:52:30 +0000 Subject: [PATCH 04/14] fix: log result --- scripts/test-ts-definition-files.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 60e6df226d7cb..2734b79d2d239 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -86,8 +86,9 @@ const tarPath = path.join(process.cwd(), tar); function compileAndCatchErrors(projectLocation) { let failed = false; let tsErrorMesssage: string[] = []; + let result; try { - execSync(`cd ${projectLocation} && npm run compile`, { + result = execSync(`cd ${projectLocation} && npm run compile`, { encoding: 'utf-8', stdio: 'pipe', // means the output isn't logged by default }); @@ -102,6 +103,7 @@ function compileAndCatchErrors(projectLocation) { console.error( `Running tsc on ${projectLocation} succeeded without triggering the expected errors.` ); + console.log(result); process.exit(1); } From 6ab6504f94dfad748acaef77fcba819995622aae Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 09:07:12 +0000 Subject: [PATCH 05/14] fix: debugging failures --- scripts/test-ts-definition-files.ts | 14 +++++++------- .../js-cjs-import-cjs-output/package.json | 3 --- .../js-cjs-import-cjs-output/tsconfig.json | 3 ++- .../js-cjs-import-esm-output/tsconfig.json | 3 ++- .../js-esm-import-cjs-output/tsconfig.json | 3 ++- .../js-esm-import-esm-output/tsconfig.json | 3 ++- .../ts-cjs-import-cjs-output/tsconfig.json | 3 ++- .../ts-esm-import-cjs-output/tsconfig.json | 3 ++- .../ts-esm-import-esm-output/tsconfig.json | 3 ++- 9 files changed, 21 insertions(+), 17 deletions(-) diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 2734b79d2d239..7a96528d11340 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -28,7 +28,7 @@ const EXPECTED_ERRORS = new Map([ ], ], [ - 'js-cjs-import-cjs-output', + 'js-esm-import-cjs-output', [ "bad.js(5,35): error TS2551: Property 'launh' does not exist on type", "bad.js(7,29): error TS2551: Property 'devics' does not exist on type", @@ -37,7 +37,7 @@ const EXPECTED_ERRORS = new Map([ ], ], [ - 'js-esm-import-cjs-output', + 'js-cjs-import-esm-output', [ "bad.js(5,35): error TS2551: Property 'launh' does not exist on type", "bad.js(7,29): error TS2551: Property 'devics' does not exist on type", @@ -46,7 +46,7 @@ const EXPECTED_ERRORS = new Map([ ], ], [ - 'js-cjs-import-esm-output', + 'js-esm-import-esm-output', [ "bad.js(5,35): error TS2551: Property 'launh' does not exist on type", "bad.js(7,29): error TS2551: Property 'devics' does not exist on type", @@ -55,7 +55,7 @@ const EXPECTED_ERRORS = new Map([ ], ], [ - 'js-esm-import-esm-output', + 'js-cjs-import-cjs-output', [ "bad.js(5,35): error TS2551: Property 'launh' does not exist on type", "bad.js(7,29): error TS2551: Property 'devics' does not exist on type", @@ -88,7 +88,7 @@ function compileAndCatchErrors(projectLocation) { let tsErrorMesssage: string[] = []; let result; try { - result = execSync(`cd ${projectLocation} && npm run compile`, { + result = execSync(`cd ${projectLocation} && npm run compile -- --verbose`, { encoding: 'utf-8', stdio: 'pipe', // means the output isn't logged by default }); @@ -131,7 +131,7 @@ function testProject(folder: string) { const expectedErrors = EXPECTED_ERRORS.get(folder) || []; if ( result.tsErrorMesssage.find( - (line) => line.includes('good.ts') || line.includes('good.js') + (line) => line.includes('good.ts(') || line.includes('good.js(') ) ) { console.error( @@ -140,7 +140,7 @@ function testProject(folder: string) { process.exit(1); } const errorsInTsMessage = result.tsErrorMesssage.filter( - (line) => line.includes('bad.ts') || line.includes('bad.js') + (line) => line.includes('bad.ts(') || line.includes('bad.js(') ); const expectedErrorsThatHaveOccurred = new Set(); const unexpectedErrors = errorsInTsMessage.filter((message) => { diff --git a/test-ts-types/js-cjs-import-cjs-output/package.json b/test-ts-types/js-cjs-import-cjs-output/package.json index 2be7f1642460b..bc17b0ec35b7d 100644 --- a/test-ts-types/js-cjs-import-cjs-output/package.json +++ b/test-ts-types/js-cjs-import-cjs-output/package.json @@ -6,9 +6,6 @@ "scripts": { "compile": "../../node_modules/.bin/tsc --build tsconfig.json" }, - "devDependencies": { - "typescript": "^4.1.3" - }, "dependencies": { "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" } diff --git a/test-ts-types/js-cjs-import-cjs-output/tsconfig.json b/test-ts-types/js-cjs-import-cjs-output/tsconfig.json index 3bd1e2c0543cb..4eb48533ddd61 100644 --- a/test-ts-types/js-cjs-import-cjs-output/tsconfig.json +++ b/test-ts-types/js-cjs-import-cjs-output/tsconfig.json @@ -5,5 +5,6 @@ "allowJs": true, "strict": true, "noEmit": true - } + }, + "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-cjs-import-esm-output/tsconfig.json b/test-ts-types/js-cjs-import-esm-output/tsconfig.json index 6d59d3594223d..47cc4bb64bfd2 100644 --- a/test-ts-types/js-cjs-import-esm-output/tsconfig.json +++ b/test-ts-types/js-cjs-import-esm-output/tsconfig.json @@ -5,5 +5,6 @@ "allowJs": true, "strict": true, "noEmit": true - } + }, + "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-esm-import-cjs-output/tsconfig.json b/test-ts-types/js-esm-import-cjs-output/tsconfig.json index 3bd1e2c0543cb..4eb48533ddd61 100644 --- a/test-ts-types/js-esm-import-cjs-output/tsconfig.json +++ b/test-ts-types/js-esm-import-cjs-output/tsconfig.json @@ -5,5 +5,6 @@ "allowJs": true, "strict": true, "noEmit": true - } + }, + "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-esm-import-esm-output/tsconfig.json b/test-ts-types/js-esm-import-esm-output/tsconfig.json index 6d59d3594223d..47cc4bb64bfd2 100644 --- a/test-ts-types/js-esm-import-esm-output/tsconfig.json +++ b/test-ts-types/js-esm-import-esm-output/tsconfig.json @@ -5,5 +5,6 @@ "allowJs": true, "strict": true, "noEmit": true - } + }, + "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json b/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json index a9d846231b1db..8c50a6cd90b73 100644 --- a/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json +++ b/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json @@ -3,5 +3,6 @@ "module": "commonjs", "strict": true, "noEmit": true - } + }, + "files": ["good.ts", "bad.ts"] } diff --git a/test-ts-types/ts-esm-import-cjs-output/tsconfig.json b/test-ts-types/ts-esm-import-cjs-output/tsconfig.json index a9d846231b1db..8c50a6cd90b73 100644 --- a/test-ts-types/ts-esm-import-cjs-output/tsconfig.json +++ b/test-ts-types/ts-esm-import-cjs-output/tsconfig.json @@ -3,5 +3,6 @@ "module": "commonjs", "strict": true, "noEmit": true - } + }, + "files": ["good.ts", "bad.ts"] } diff --git a/test-ts-types/ts-esm-import-esm-output/tsconfig.json b/test-ts-types/ts-esm-import-esm-output/tsconfig.json index bc8fc3aa48cfb..59c5d8f67ffad 100644 --- a/test-ts-types/ts-esm-import-esm-output/tsconfig.json +++ b/test-ts-types/ts-esm-import-esm-output/tsconfig.json @@ -3,5 +3,6 @@ "module": "esnext", "strict": true, "noEmit": true - } + }, + "files": ["good.ts", "bad.ts"] } From bdd56169a58004243b01e44b74f24cefbc05530a Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 09:18:46 +0000 Subject: [PATCH 06/14] fix: tsconfig issues --- test-ts-types/js-cjs-import-cjs-output/tsconfig.json | 2 +- test-ts-types/js-cjs-import-esm-output/tsconfig.json | 2 +- test-ts-types/js-esm-import-cjs-output/tsconfig.json | 2 +- test-ts-types/js-esm-import-esm-output/tsconfig.json | 2 +- test-ts-types/ts-cjs-import-cjs-output/tsconfig.json | 2 +- test-ts-types/ts-esm-import-cjs-output/tsconfig.json | 2 +- test-ts-types/ts-esm-import-esm-output/tsconfig.json | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test-ts-types/js-cjs-import-cjs-output/tsconfig.json b/test-ts-types/js-cjs-import-cjs-output/tsconfig.json index 4eb48533ddd61..520a89f147b85 100644 --- a/test-ts-types/js-cjs-import-cjs-output/tsconfig.json +++ b/test-ts-types/js-cjs-import-cjs-output/tsconfig.json @@ -4,7 +4,7 @@ "checkJs": true, "allowJs": true, "strict": true, - "noEmit": true + "outDir": "dist" }, "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-cjs-import-esm-output/tsconfig.json b/test-ts-types/js-cjs-import-esm-output/tsconfig.json index 47cc4bb64bfd2..58aae3b93cbd6 100644 --- a/test-ts-types/js-cjs-import-esm-output/tsconfig.json +++ b/test-ts-types/js-cjs-import-esm-output/tsconfig.json @@ -4,7 +4,7 @@ "checkJs": true, "allowJs": true, "strict": true, - "noEmit": true + "outDir": "dist" }, "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-esm-import-cjs-output/tsconfig.json b/test-ts-types/js-esm-import-cjs-output/tsconfig.json index 4eb48533ddd61..520a89f147b85 100644 --- a/test-ts-types/js-esm-import-cjs-output/tsconfig.json +++ b/test-ts-types/js-esm-import-cjs-output/tsconfig.json @@ -4,7 +4,7 @@ "checkJs": true, "allowJs": true, "strict": true, - "noEmit": true + "outDir": "dist" }, "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-esm-import-esm-output/tsconfig.json b/test-ts-types/js-esm-import-esm-output/tsconfig.json index 47cc4bb64bfd2..58aae3b93cbd6 100644 --- a/test-ts-types/js-esm-import-esm-output/tsconfig.json +++ b/test-ts-types/js-esm-import-esm-output/tsconfig.json @@ -4,7 +4,7 @@ "checkJs": true, "allowJs": true, "strict": true, - "noEmit": true + "outDir": "dist" }, "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json b/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json index 8c50a6cd90b73..7bd626989d31c 100644 --- a/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json +++ b/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "commonjs", "strict": true, - "noEmit": true + "outDir": "dist" }, "files": ["good.ts", "bad.ts"] } diff --git a/test-ts-types/ts-esm-import-cjs-output/tsconfig.json b/test-ts-types/ts-esm-import-cjs-output/tsconfig.json index 8c50a6cd90b73..7bd626989d31c 100644 --- a/test-ts-types/ts-esm-import-cjs-output/tsconfig.json +++ b/test-ts-types/ts-esm-import-cjs-output/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "commonjs", "strict": true, - "noEmit": true + "outDir": "dist" }, "files": ["good.ts", "bad.ts"] } diff --git a/test-ts-types/ts-esm-import-esm-output/tsconfig.json b/test-ts-types/ts-esm-import-esm-output/tsconfig.json index 59c5d8f67ffad..f0ec5a1241938 100644 --- a/test-ts-types/ts-esm-import-esm-output/tsconfig.json +++ b/test-ts-types/ts-esm-import-esm-output/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "esnext", "strict": true, - "noEmit": true + "outDir": "dist" }, "files": ["good.ts", "bad.ts"] } From cba064ed1c491a092fea374ee88c6ed135d5059d Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 09:28:39 +0000 Subject: [PATCH 07/14] fix: do not use --build flag --- .gitignore | 1 + scripts/test-ts-definition-files.ts | 6 +++--- test-ts-types/js-cjs-import-cjs-output/package.json | 2 +- test-ts-types/js-cjs-import-esm-output/package.json | 2 +- test-ts-types/js-esm-import-cjs-output/package.json | 2 +- test-ts-types/js-esm-import-esm-output/package.json | 2 +- test-ts-types/ts-cjs-import-cjs-output/package.json | 2 +- test-ts-types/ts-esm-import-cjs-output/package.json | 2 +- test-ts-types/ts-esm-import-esm-output/package.json | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 30e29ba3021e8..f0dc23c33077a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /node_modules/ test-ts-types/**/node_modules +test-ts-types/**/dist/ /test/output-chromium /test/output-firefox /test/test-user-data-dir* diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 7a96528d11340..66d6991f011fb 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -88,7 +88,7 @@ function compileAndCatchErrors(projectLocation) { let tsErrorMesssage: string[] = []; let result; try { - result = execSync(`cd ${projectLocation} && npm run compile -- --verbose`, { + result = execSync(`cd ${projectLocation} && npm run compile`, { encoding: 'utf-8', stdio: 'pipe', // means the output isn't logged by default }); @@ -131,7 +131,7 @@ function testProject(folder: string) { const expectedErrors = EXPECTED_ERRORS.get(folder) || []; if ( result.tsErrorMesssage.find( - (line) => line.includes('good.ts(') || line.includes('good.js(') + (line) => line.includes('good.ts') || line.includes('good.js') ) ) { console.error( @@ -140,7 +140,7 @@ function testProject(folder: string) { process.exit(1); } const errorsInTsMessage = result.tsErrorMesssage.filter( - (line) => line.includes('bad.ts(') || line.includes('bad.js(') + (line) => line.includes('bad.ts') || line.includes('bad.js') ); const expectedErrorsThatHaveOccurred = new Set(); const unexpectedErrors = errorsInTsMessage.filter((message) => { diff --git a/test-ts-types/js-cjs-import-cjs-output/package.json b/test-ts-types/js-cjs-import-cjs-output/package.json index bc17b0ec35b7d..3c0d055e27700 100644 --- a/test-ts-types/js-cjs-import-cjs-output/package.json +++ b/test-ts-types/js-cjs-import-cjs-output/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Test project with TypeScript, ESM output", "scripts": { - "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + "compile": "../../node_modules/.bin/tsc" }, "dependencies": { "puppeteer": "file:../../puppeteer-7.0.4-post.tgz" diff --git a/test-ts-types/js-cjs-import-esm-output/package.json b/test-ts-types/js-cjs-import-esm-output/package.json index 2be7f1642460b..27d6b18b8a420 100644 --- a/test-ts-types/js-cjs-import-esm-output/package.json +++ b/test-ts-types/js-cjs-import-esm-output/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Test project with TypeScript, ESM output", "scripts": { - "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + "compile": "../../node_modules/.bin/tsc" }, "devDependencies": { "typescript": "^4.1.3" diff --git a/test-ts-types/js-esm-import-cjs-output/package.json b/test-ts-types/js-esm-import-cjs-output/package.json index 2be7f1642460b..27d6b18b8a420 100644 --- a/test-ts-types/js-esm-import-cjs-output/package.json +++ b/test-ts-types/js-esm-import-cjs-output/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Test project with TypeScript, ESM output", "scripts": { - "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + "compile": "../../node_modules/.bin/tsc" }, "devDependencies": { "typescript": "^4.1.3" diff --git a/test-ts-types/js-esm-import-esm-output/package.json b/test-ts-types/js-esm-import-esm-output/package.json index 2be7f1642460b..27d6b18b8a420 100644 --- a/test-ts-types/js-esm-import-esm-output/package.json +++ b/test-ts-types/js-esm-import-esm-output/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Test project with TypeScript, ESM output", "scripts": { - "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + "compile": "../../node_modules/.bin/tsc" }, "devDependencies": { "typescript": "^4.1.3" diff --git a/test-ts-types/ts-cjs-import-cjs-output/package.json b/test-ts-types/ts-cjs-import-cjs-output/package.json index 2be7f1642460b..27d6b18b8a420 100644 --- a/test-ts-types/ts-cjs-import-cjs-output/package.json +++ b/test-ts-types/ts-cjs-import-cjs-output/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Test project with TypeScript, ESM output", "scripts": { - "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + "compile": "../../node_modules/.bin/tsc" }, "devDependencies": { "typescript": "^4.1.3" diff --git a/test-ts-types/ts-esm-import-cjs-output/package.json b/test-ts-types/ts-esm-import-cjs-output/package.json index 2be7f1642460b..27d6b18b8a420 100644 --- a/test-ts-types/ts-esm-import-cjs-output/package.json +++ b/test-ts-types/ts-esm-import-cjs-output/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Test project with TypeScript, ESM output", "scripts": { - "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + "compile": "../../node_modules/.bin/tsc" }, "devDependencies": { "typescript": "^4.1.3" diff --git a/test-ts-types/ts-esm-import-esm-output/package.json b/test-ts-types/ts-esm-import-esm-output/package.json index 2be7f1642460b..27d6b18b8a420 100644 --- a/test-ts-types/ts-esm-import-esm-output/package.json +++ b/test-ts-types/ts-esm-import-esm-output/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Test project with TypeScript, ESM output", "scripts": { - "compile": "../../node_modules/.bin/tsc --build tsconfig.json" + "compile": "../../node_modules/.bin/tsc" }, "devDependencies": { "typescript": "^4.1.3" From cc5df4f505d3e4345fc72e2d25d10a29c78cb06b Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 09:44:36 +0000 Subject: [PATCH 08/14] fix: module resolution --- scripts/test-ts-definition-files.ts | 4 +++- test-ts-types/js-cjs-import-cjs-output/tsconfig.json | 3 ++- test-ts-types/js-cjs-import-esm-output/tsconfig.json | 3 ++- test-ts-types/js-esm-import-cjs-output/tsconfig.json | 3 ++- test-ts-types/js-esm-import-esm-output/tsconfig.json | 3 ++- test-ts-types/ts-cjs-import-cjs-output/tsconfig.json | 3 ++- test-ts-types/ts-esm-import-cjs-output/tsconfig.json | 3 ++- test-ts-types/ts-esm-import-esm-output/tsconfig.json | 3 ++- 8 files changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 66d6991f011fb..08d93cc606205 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -135,7 +135,9 @@ function testProject(folder: string) { ) ) { console.error( - `Error for ${projectLocation} contained unexpected failures in good.ts/good.js:\n${result.tsErrorMesssage}` + `Error for ${projectLocation} contained unexpected failures in good.ts/good.js:\n${result.tsErrorMesssage.join( + '\n' + )}` ); process.exit(1); } diff --git a/test-ts-types/js-cjs-import-cjs-output/tsconfig.json b/test-ts-types/js-cjs-import-cjs-output/tsconfig.json index 520a89f147b85..2889972c4b81b 100644 --- a/test-ts-types/js-cjs-import-cjs-output/tsconfig.json +++ b/test-ts-types/js-cjs-import-cjs-output/tsconfig.json @@ -4,7 +4,8 @@ "checkJs": true, "allowJs": true, "strict": true, - "outDir": "dist" + "outDir": "dist", + "moduleResolution": "node" }, "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-cjs-import-esm-output/tsconfig.json b/test-ts-types/js-cjs-import-esm-output/tsconfig.json index 58aae3b93cbd6..e2ce292bf3e0c 100644 --- a/test-ts-types/js-cjs-import-esm-output/tsconfig.json +++ b/test-ts-types/js-cjs-import-esm-output/tsconfig.json @@ -4,7 +4,8 @@ "checkJs": true, "allowJs": true, "strict": true, - "outDir": "dist" + "outDir": "dist", + "moduleResolution": "node" }, "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-esm-import-cjs-output/tsconfig.json b/test-ts-types/js-esm-import-cjs-output/tsconfig.json index 520a89f147b85..2889972c4b81b 100644 --- a/test-ts-types/js-esm-import-cjs-output/tsconfig.json +++ b/test-ts-types/js-esm-import-cjs-output/tsconfig.json @@ -4,7 +4,8 @@ "checkJs": true, "allowJs": true, "strict": true, - "outDir": "dist" + "outDir": "dist", + "moduleResolution": "node" }, "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/js-esm-import-esm-output/tsconfig.json b/test-ts-types/js-esm-import-esm-output/tsconfig.json index 58aae3b93cbd6..e2ce292bf3e0c 100644 --- a/test-ts-types/js-esm-import-esm-output/tsconfig.json +++ b/test-ts-types/js-esm-import-esm-output/tsconfig.json @@ -4,7 +4,8 @@ "checkJs": true, "allowJs": true, "strict": true, - "outDir": "dist" + "outDir": "dist", + "moduleResolution": "node" }, "files": ["good.js", "bad.js"] } diff --git a/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json b/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json index 7bd626989d31c..a417e47c143ed 100644 --- a/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json +++ b/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "strict": true, - "outDir": "dist" + "outDir": "dist", + "moduleResolution": "node" }, "files": ["good.ts", "bad.ts"] } diff --git a/test-ts-types/ts-esm-import-cjs-output/tsconfig.json b/test-ts-types/ts-esm-import-cjs-output/tsconfig.json index 7bd626989d31c..a417e47c143ed 100644 --- a/test-ts-types/ts-esm-import-cjs-output/tsconfig.json +++ b/test-ts-types/ts-esm-import-cjs-output/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "strict": true, - "outDir": "dist" + "outDir": "dist", + "moduleResolution": "node" }, "files": ["good.ts", "bad.ts"] } diff --git a/test-ts-types/ts-esm-import-esm-output/tsconfig.json b/test-ts-types/ts-esm-import-esm-output/tsconfig.json index f0ec5a1241938..f9e9bb5f878b0 100644 --- a/test-ts-types/ts-esm-import-esm-output/tsconfig.json +++ b/test-ts-types/ts-esm-import-esm-output/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "esnext", "strict": true, - "outDir": "dist" + "outDir": "dist", + "moduleResolution": "node" }, "files": ["good.ts", "bad.ts"] } From 0d4b73f7766eb7011d4b209a91cb1cbbe8f96a6b Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 09:44:49 +0000 Subject: [PATCH 09/14] chore: purposefully broken commit to test CI failures --- src/api-docs-entry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api-docs-entry.ts b/src/api-docs-entry.ts index 63d87aff081dc..9582d661fa7de 100644 --- a/src/api-docs-entry.ts +++ b/src/api-docs-entry.ts @@ -110,7 +110,7 @@ export declare function connect(options: ConnectOptions): Promise; * @public * {@inheritDoc Puppeteer.devices} */ -export let devices: DevicesMap; +export let goodevices: DevicesMap; /** * @public */ From eb527622327bd98ab4be73b269c04705fdbb6230 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 10:01:42 +0000 Subject: [PATCH 10/14] chore: undo purposeful break --- src/api-docs-entry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api-docs-entry.ts b/src/api-docs-entry.ts index 9582d661fa7de..63d87aff081dc 100644 --- a/src/api-docs-entry.ts +++ b/src/api-docs-entry.ts @@ -110,7 +110,7 @@ export declare function connect(options: ConnectOptions): Promise; * @public * {@inheritDoc Puppeteer.devices} */ -export let goodevices: DevicesMap; +export let devices: DevicesMap; /** * @public */ From ba42ea88e500da362aee4f5ddca5d147ee43f291 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 10:13:28 +0000 Subject: [PATCH 11/14] chore: review comments --- .github/workflows/main.yml | 3 --- .github/workflows/publish-on-tag.yml | 2 -- scripts/test-ts-definition-files.ts | 7 ++++++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 37901a9257f9c..cb916f6ab8207 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,9 +45,6 @@ jobs: npm run lint npm run generate-docs npm run ensure-correct-devtools-protocol-revision - - - name: Run check that types.d.ts file is valid and detects errors. - run: | npm run test-types-file - name: Run unit tests diff --git a/.github/workflows/publish-on-tag.yml b/.github/workflows/publish-on-tag.yml index 3d9434677624b..dc2140ab2aff4 100644 --- a/.github/workflows/publish-on-tag.yml +++ b/.github/workflows/publish-on-tag.yml @@ -15,8 +15,6 @@ jobs: run: npm install - name: Build run: npm run build - - name: Test types.d.ts file is correct - run: npm run test-types-file - name: Publish puppeteer env: NPM_TOKEN: ${{secrets.NPM_TOKEN_PUPPETEER}} diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 08d93cc606205..54a784624022b 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -114,6 +114,11 @@ function compileAndCatchErrors(projectLocation) { } function testProject(folder: string) { + if (folder.includes(' ')) { + console.error('Test project folders may not contain spaces.'); + process.exit(1); + } + console.log('\nTesting:', folder); const projectLocation = path.join( process.cwd(), @@ -172,7 +177,7 @@ function testProject(folder: string) { process.exit(1); } }); - console.log('===> ✅ Type checked correctly.'); + console.log('===> ✅ Type-checked correctly.'); } PROJECT_FOLDERS.forEach((folder) => { From 44a93e29b0af22cbc426f0487ae59ea37414ae2a Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 10:14:27 +0000 Subject: [PATCH 12/14] chore: escape spaces --- scripts/test-ts-definition-files.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 54a784624022b..8f8cd929f77d9 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -114,17 +114,11 @@ function compileAndCatchErrors(projectLocation) { } function testProject(folder: string) { - if (folder.includes(' ')) { - console.error('Test project folders may not contain spaces.'); - process.exit(1); - } - console.log('\nTesting:', folder); - const projectLocation = path.join( - process.cwd(), - PROJECT_FOLDERS_ROOT, - folder - ); + const projectLocation = path + .join(process.cwd(), PROJECT_FOLDERS_ROOT, folder) + .replace(/(\s+)/g, '\\$1'); // Escape spaces in the path. + const tarLocation = path.relative(projectLocation, tarPath); console.log('===> Installing Puppeteer from tar file'); execSync( From 986a1db554e5d21d61cd22c2ec40d5bfca206b6f Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 11:04:49 +0000 Subject: [PATCH 13/14] chore: swap to spawn --- scripts/test-ts-definition-files.ts | 57 +++++++++++++++++------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 8f8cd929f77d9..72482de776333 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -1,4 +1,4 @@ -import { spawnSync, execSync } from 'child_process'; +import { spawnSync } from 'child_process'; import { version } from '../package.json'; import path from 'path'; const PROJECT_FOLDERS_ROOT = 'test-ts-types'; @@ -83,48 +83,57 @@ function packPuppeteer() { const tar = packPuppeteer(); const tarPath = path.join(process.cwd(), tar); +function cdIntoProjectAndRunCommand(projectLocation: string, command: string) { + return spawnSync( + 'sh', + ['-c', [`cd "${projectLocation}"`, command].join('; ')], + { encoding: 'utf-8', stdio: 'pipe' } + ); +} + function compileAndCatchErrors(projectLocation) { - let failed = false; - let tsErrorMesssage: string[] = []; - let result; - try { - result = execSync(`cd ${projectLocation} && npm run compile`, { - encoding: 'utf-8', - stdio: 'pipe', // means the output isn't logged by default - }); - } catch (error) { - // We expect to always get here, as each project has some typos to test if - // our types are used correctly to catch errors; - failed = true; - tsErrorMesssage = (error.stdout as string).split('\n'); - } + const { status, stdout, stderr } = cdIntoProjectAndRunCommand( + projectLocation, + 'npm run compile' + ); + const tsErrorMesssage = stdout.split('\n'); - if (!failed) { + if (status === 0) { console.error( `Running tsc on ${projectLocation} succeeded without triggering the expected errors.` ); - console.log(result); + console.log(stdout, stderr); process.exit(1); } return { - failed, tsErrorMesssage, }; } function testProject(folder: string) { console.log('\nTesting:', folder); - const projectLocation = path - .join(process.cwd(), PROJECT_FOLDERS_ROOT, folder) - .replace(/(\s+)/g, '\\$1'); // Escape spaces in the path. + const projectLocation = path.join( + process.cwd(), + PROJECT_FOLDERS_ROOT, + folder + ); const tarLocation = path.relative(projectLocation, tarPath); console.log('===> Installing Puppeteer from tar file'); - execSync( - `cd ${projectLocation} && PUPPETEER_SKIP_DOWNLOAD=1 npm install --no-package-lock ${tarLocation}`, - { encoding: 'utf-8' } + const { status, stderr, stdout } = cdIntoProjectAndRunCommand( + projectLocation, + `PUPPETEER_SKIP_DOWNLOAD=1 npm install --no-package-lock "${tarLocation}"` ); + + if (status > 0) { + console.error( + 'Installing the tar file unexpectedly failed', + stdout, + stderr + ); + process.exit(status); + } console.log('===> Running compile to ensure expected errors only.'); const result = compileAndCatchErrors(projectLocation); const expectedErrors = EXPECTED_ERRORS.get(folder) || []; From 37ca85bff77a8b7568ac5045dd6e49ccb5e37c98 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 10 Feb 2021 11:48:43 +0000 Subject: [PATCH 14/14] chore: spawnSync better --- scripts/test-ts-definition-files.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts index 72482de776333..d9f15133a681e 100644 --- a/scripts/test-ts-definition-files.ts +++ b/scripts/test-ts-definition-files.ts @@ -83,19 +83,11 @@ function packPuppeteer() { const tar = packPuppeteer(); const tarPath = path.join(process.cwd(), tar); -function cdIntoProjectAndRunCommand(projectLocation: string, command: string) { - return spawnSync( - 'sh', - ['-c', [`cd "${projectLocation}"`, command].join('; ')], - { encoding: 'utf-8', stdio: 'pipe' } - ); -} - function compileAndCatchErrors(projectLocation) { - const { status, stdout, stderr } = cdIntoProjectAndRunCommand( - projectLocation, - 'npm run compile' - ); + const { status, stdout, stderr } = spawnSync('npm', ['run', 'compile'], { + cwd: projectLocation, + encoding: 'utf-8', + }); const tsErrorMesssage = stdout.split('\n'); if (status === 0) { @@ -121,9 +113,16 @@ function testProject(folder: string) { const tarLocation = path.relative(projectLocation, tarPath); console.log('===> Installing Puppeteer from tar file'); - const { status, stderr, stdout } = cdIntoProjectAndRunCommand( - projectLocation, - `PUPPETEER_SKIP_DOWNLOAD=1 npm install --no-package-lock "${tarLocation}"` + const { status, stderr, stdout } = spawnSync( + 'npm', + ['install', '--no-package-lock', tarLocation], + { + env: { + PUPPETEER_SKIP_DOWNLOAD: '1', + }, + cwd: projectLocation, + encoding: 'utf-8', + } ); if (status > 0) {