From e499515fd67df66af0b57419c40d8a9e6fed3a62 Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Mon, 27 Jun 2022 10:57:31 +0200 Subject: [PATCH] chore: add type tests (#8588) --- .eslintignore | 1 - .github/workflows/ci.yml | 3 +- .gitignore | 2 - .prettierignore | 1 - package.json | 3 +- scripts/test-ts-definition-files.ts | 217 ------------------ src/common/JSHandle.ts | 2 +- test-d/ElementHandle.test-d.ts | 158 +++++++++++++ test-d/JSHandle.test-d.ts | 84 +++++++ test-d/puppeteer.test-d.ts | 15 ++ test-d/tsconfig.json | 8 + 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 | 12 - .../js-cjs-import-cjs-output/tsconfig.json | 11 - 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 | 12 - .../js-cjs-import-esm-output/tsconfig.json | 11 - test-ts-types/js-esm-import-cjs-output/bad.js | 25 -- .../js-esm-import-cjs-output/good.js | 17 -- .../js-esm-import-cjs-output/package.json | 12 - .../js-esm-import-cjs-output/tsconfig.json | 11 - 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 | 12 - .../js-esm-import-esm-output/tsconfig.json | 11 - test-ts-types/ts-cjs-import-cjs-output/bad.ts | 17 -- .../ts-cjs-import-cjs-output/good.ts | 16 -- .../ts-cjs-import-cjs-output/package.json | 12 - .../ts-cjs-import-cjs-output/tsconfig.json | 9 - 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 | 12 - .../ts-esm-import-cjs-output/tsconfig.json | 9 - test-ts-types/ts-esm-import-esm-output/bad.ts | 30 --- .../ts-esm-import-esm-output/good.ts | 15 -- .../ts-esm-import-esm-output/package.json | 12 - .../ts-esm-import-esm-output/tsconfig.json | 9 - 39 files changed, 269 insertions(+), 636 deletions(-) delete mode 100644 scripts/test-ts-definition-files.ts create mode 100644 test-d/ElementHandle.test-d.ts create mode 100644 test-d/JSHandle.test-d.ts create mode 100644 test-d/puppeteer.test-d.ts create mode 100644 test-d/tsconfig.json delete mode 100644 test-ts-types/js-cjs-import-cjs-output/bad.js delete mode 100644 test-ts-types/js-cjs-import-cjs-output/good.js delete mode 100644 test-ts-types/js-cjs-import-cjs-output/package.json delete mode 100644 test-ts-types/js-cjs-import-cjs-output/tsconfig.json delete mode 100644 test-ts-types/js-cjs-import-esm-output/bad.js delete mode 100644 test-ts-types/js-cjs-import-esm-output/good.js delete mode 100644 test-ts-types/js-cjs-import-esm-output/package.json delete mode 100644 test-ts-types/js-cjs-import-esm-output/tsconfig.json delete mode 100644 test-ts-types/js-esm-import-cjs-output/bad.js delete mode 100644 test-ts-types/js-esm-import-cjs-output/good.js delete mode 100644 test-ts-types/js-esm-import-cjs-output/package.json delete mode 100644 test-ts-types/js-esm-import-cjs-output/tsconfig.json delete mode 100644 test-ts-types/js-esm-import-esm-output/bad.js delete mode 100644 test-ts-types/js-esm-import-esm-output/good.js delete mode 100644 test-ts-types/js-esm-import-esm-output/package.json delete mode 100644 test-ts-types/js-esm-import-esm-output/tsconfig.json delete mode 100644 test-ts-types/ts-cjs-import-cjs-output/bad.ts delete mode 100644 test-ts-types/ts-cjs-import-cjs-output/good.ts delete mode 100644 test-ts-types/ts-cjs-import-cjs-output/package.json delete mode 100644 test-ts-types/ts-cjs-import-cjs-output/tsconfig.json delete mode 100644 test-ts-types/ts-esm-import-cjs-output/bad.ts delete mode 100644 test-ts-types/ts-esm-import-cjs-output/good.ts delete mode 100644 test-ts-types/ts-esm-import-cjs-output/package.json delete mode 100644 test-ts-types/ts-esm-import-cjs-output/tsconfig.json delete mode 100644 test-ts-types/ts-esm-import-esm-output/bad.ts delete mode 100644 test-ts-types/ts-esm-import-esm-output/good.ts delete mode 100644 test-ts-types/ts-esm-import-esm-output/package.json delete mode 100644 test-ts-types/ts-esm-import-esm-output/tsconfig.json diff --git a/.eslintignore b/.eslintignore index 5de5cd4a647..dc03b7c0cd1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,6 +3,5 @@ build/ coverage/ doclint/ lib/ -test-ts-types/ tsconfig.tsbuildinfo vendor/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5273aca00e1..75f2c48c37d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,8 +55,7 @@ jobs: # See https://github.com/puppeteer/puppeteer/issues/7710 for more info # npm run generate:docs npm run test:protocol-revision - # TODO(jrandolf): Find a better way to test TypeScript source files. - # npm run test:types + npm run test:types - name: Run commit lint run: | diff --git a/.gitignore b/.gitignore index d6552444210..ee4a2d28f7f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,5 @@ node_modules/ package-lock.json puppeteer.api.json puppeteer*.tgz -test-ts-types/**/dist/ -test-ts-types/**/node_modules tsconfig.tsbuildinfo yarn.lock \ No newline at end of file diff --git a/.prettierignore b/.prettierignore index f6fdcd13fea..9ad8f10f582 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,7 +9,6 @@ lib/ node_modules/ package-lock.json package.json -test-ts-types/ test/assets/ tsconfig.tsbuildinfo vendor/ diff --git a/package.json b/package.json index f272313ba5c..115781395c4 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "test:pinned-deps": "ts-node -s scripts/ensure-pinned-deps", "test:install": "scripts/test-install.sh", "test:debug": "npm run build:test && mocha --inspect-brk", - "test:types": "ts-node -s scripts/test-ts-definition-files.ts", + "test:types": "tsc -b test-d", "prepublishOnly": "npm run build", "prepare": "node typescript-if-required.js && ([[ $HUSKY = 0 ]] || husky install)", "lint": "npm run build && npm run lint:eslint && npm run doc && npm run lint:prettier", @@ -126,6 +126,7 @@ "sinon": "14.0.0", "source-map-support": "0.5.21", "text-diff": "1.0.1", + "tsd": "0.21.0", "typescript": "4.7.2" } } diff --git a/scripts/test-ts-definition-files.ts b/scripts/test-ts-definition-files.ts deleted file mode 100644 index 89b7e408e9b..00000000000 --- a/scripts/test-ts-definition-files.ts +++ /dev/null @@ -1,217 +0,0 @@ -import {spawnSync} from 'child_process'; -import {version} from '../package.json'; -import path from 'path'; -import fs from 'fs'; -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.', - "bad.ts(20,5): error TS2345: Argument of type '(divElem: number) => any' is not assignable to parameter of type 'EvaluateFn'.", - "bad.ts(20,34): error TS2339: Property 'innerText' does not exist on type 'number'.", - "bad.ts(24,45): error TS2344: Type '(x: number) => string' does not satisfy the constraint 'EvaluateFn'.", - "bad.ts(27,34): error TS2339: Property 'innerText' does not exist on type 'number'.", - ], - ], - [ - '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-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'", - "bad.js(22,5): error TS2345: Argument of type '(divElem: number) => any' is not assignable to parameter of type 'EvaluateFn'.", - "bad.js(22,26): error TS2339: Property 'innerText' does not exist on type 'number'.", - ], - ], - [ - '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'", - ], - ], - [ - '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'", - ], - ], -]); -const PROJECT_FOLDERS = [...EXPECTED_ERRORS.keys()]; - -if (!process.env['CI']) { - console.log(`IMPORTANT: this script assumes you have compiled Puppeteer -and its types file before running. Make sure you have run: -=> npm run build:tsc && npm run generate:types -before executing this script locally.`); -} - -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); - } - - // Move from puppeteer-X.Y.Z.tgz to puppeteer.tgz so we don't have to update - // it when versions change. - const moveResult = spawnSync('mv', [ - `puppeteer-${version}.tgz`, - 'puppeteer.tgz', - ]); - if (moveResult.status !== 0) { - console.log('Failed to rename Puppeteer tar', moveResult.stderr); - process.exit(1); - } - - return `puppeteer.tgz`; -} - -const tar = packPuppeteer(); -const tarPath = path.join(process.cwd(), tar); - -function compileAndCatchErrors(projectLocation: string) { - const {status, stdout, stderr} = spawnSync('npm', ['run', 'compile'], { - cwd: projectLocation, - encoding: 'utf-8', - }); - const tsErrorMesssage = stdout.split('\n'); - - if (status === 0) { - console.error( - `Running tsc on ${projectLocation} succeeded without triggering the expected errors.` - ); - console.log(stdout, stderr); - process.exit(1); - } - - return { - 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('===> Clearing left over node_modules to ensure clean slate'); - try { - fs.rmdirSync(path.join(projectLocation, 'node_modules'), { - recursive: true, - }); - } catch (_error) { - // We don't care if this errors because if it did it's most likely because - // there was no node_modules folder, which is fine. - } - console.log('===> Installing Puppeteer from tar file', tarLocation); - const {status, stderr, stdout} = spawnSync('npm', ['install', tarLocation], { - env: { - ...process.env, - PUPPETEER_SKIP_DOWNLOAD: '1', - }, - cwd: projectLocation, - encoding: 'utf-8', - }); - - if (status) { - 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) || []; - if ( - result.tsErrorMesssage.find(line => { - return line.includes('good.ts') || line.includes('good.js'); - }) - ) { - console.error( - `Error for ${projectLocation} contained unexpected failures in good.ts/good.js:\n${result.tsErrorMesssage.join( - '\n' - )}` - ); - process.exit(1); - } - const errorsInTsMessage = result.tsErrorMesssage.filter(line => { - return 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/common/JSHandle.ts b/src/common/JSHandle.ts index f6eb085ef38..76e2afb03de 100644 --- a/src/common/JSHandle.ts +++ b/src/common/JSHandle.ts @@ -167,7 +167,7 @@ export class JSHandle { [this, ...Params] > >( - pageFunction: Func, + pageFunction: Func | string, ...args: Params ): // @ts-expect-error Circularity here is okay because we only need the return // type which doesn't use `this`. diff --git a/test-d/ElementHandle.test-d.ts b/test-d/ElementHandle.test-d.ts new file mode 100644 index 00000000000..8be91772074 --- /dev/null +++ b/test-d/ElementHandle.test-d.ts @@ -0,0 +1,158 @@ +import {expectNotType, expectType} from 'tsd'; +import {ElementHandle} from '../lib/esm/puppeteer/common/ElementHandle.js'; + +declare const handle: ElementHandle; + +{ + { + expectType | null>(await handle.$('a')); + expectNotType | null>(await handle.$('a')); + } + { + expectType | null>(await handle.$('div')); + expectNotType | null>(await handle.$('div')); + } + { + expectType | null>(await handle.$('some-custom')); + } +} + +{ + { + expectType[]>(await handle.$$('a')); + expectNotType[]>(await handle.$$('a')); + } + { + expectType[]>(await handle.$$('div')); + expectNotType[]>(await handle.$$('div')); + } + { + expectType[]>(await handle.$$('some-custom')); + } +} + +{ + expectType( + await handle.$eval( + 'a', + (element, int) => { + expectType(element); + expectType(int); + }, + 1 + ) + ); + expectType( + await handle.$eval( + 'div', + (element, int, str) => { + expectType(element); + expectType(int); + expectType(str); + }, + 1, + '' + ) + ); + expectType( + await handle.$eval( + 'a', + (element, value) => { + expectType(element); + return value; + }, + 1 + ) + ); + expectType( + await handle.$eval( + 'some-element', + (element, value) => { + expectType(element); + return value; + }, + 1 + ) + ); + expectType( + await handle.$eval('a', element => { + return element; + }) + ); + expectType(await handle.$eval('a', 'document')); +} + +{ + expectType( + await handle.$$eval( + 'a', + (elements, int) => { + expectType(elements); + expectType(int); + }, + 1 + ) + ); + expectType( + await handle.$$eval( + 'div', + (elements, int, str) => { + expectType(elements); + expectType(int); + expectType(str); + }, + 1, + '' + ) + ); + expectType( + await handle.$$eval( + 'a', + (elements, value) => { + expectType(elements); + return value; + }, + 1 + ) + ); + expectType( + await handle.$$eval( + 'some-element', + (elements, value) => { + expectType(elements); + return value; + }, + 1 + ) + ); + expectType( + await handle.$$eval('a', elements => { + return elements; + }) + ); + expectType(await handle.$$eval('a', 'document')); +} + +{ + { + expectType | null>( + await handle.waitForSelector('a') + ); + expectNotType | null>( + await handle.waitForSelector('a') + ); + } + { + expectType | null>( + await handle.waitForSelector('div') + ); + expectNotType | null>( + await handle.waitForSelector('div') + ); + } + { + expectType | null>( + await handle.waitForSelector('some-custom') + ); + } +} diff --git a/test-d/JSHandle.test-d.ts b/test-d/JSHandle.test-d.ts new file mode 100644 index 00000000000..d83872a1208 --- /dev/null +++ b/test-d/JSHandle.test-d.ts @@ -0,0 +1,84 @@ +import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; +import {ElementHandle} from '../lib/esm/puppeteer/common/ElementHandle.js'; +import {JSHandle} from '../lib/esm/puppeteer/common/JSHandle.js'; + +declare const handle: JSHandle; + +{ + expectType(await handle.evaluate('document')); + expectType( + await handle.evaluate(() => { + return 1; + }) + ); + expectType( + await handle.evaluate(() => { + return document.body; + }) + ); + expectType( + await handle.evaluate(() => { + return ''; + }) + ); + expectType( + await handle.evaluate((value, str) => { + expectNotAssignable(value); + expectType(str); + return ''; + }, '') + ); +} + +{ + expectType(await handle.evaluateHandle('document')); + expectType>( + await handle.evaluateHandle(() => { + return 1; + }) + ); + expectType>( + await handle.evaluateHandle(() => { + return ''; + }) + ); + expectType>( + await handle.evaluateHandle((value, str) => { + expectNotAssignable(value); + expectType(str); + return ''; + }, '') + ); + expectType>( + await handle.evaluateHandle(() => { + return document.body; + }) + ); +} + +declare const handle2: JSHandle<{test: number}>; + +{ + { + expectType>(await handle2.getProperty('test')); + expectNotAssignable>(await handle2.getProperty('test')); + } + { + expectType>( + await handle2.getProperty('key-doesnt-exist') + ); + expectAssignable>( + await handle2.getProperty('key-doesnt-exist') + ); + expectAssignable>( + await handle2.getProperty('key-doesnt-exist') + ); + } +} + +{ + handle.evaluate((value, other) => { + expectType(value); + expectType<{test: number}>(other); + }, handle2); +} diff --git a/test-d/puppeteer.test-d.ts b/test-d/puppeteer.test-d.ts new file mode 100644 index 00000000000..0b137d1cdd0 --- /dev/null +++ b/test-d/puppeteer.test-d.ts @@ -0,0 +1,15 @@ +import {expectType} from 'tsd'; +import { + connect, + createBrowserFetcher, + defaultArgs, + executablePath, + launch, + default as puppeteer, +} from '../lib/esm/puppeteer/puppeteer.js'; + +expectType(puppeteer.launch); +expectType(puppeteer.connect); +expectType(puppeteer.createBrowserFetcher); +expectType(puppeteer.defaultArgs); +expectType(puppeteer.executablePath); diff --git a/test-d/tsconfig.json b/test-d/tsconfig.json new file mode 100644 index 00000000000..259d60c123e --- /dev/null +++ b/test-d/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "noEmit": true, + "module": "ESNext" + }, + "references": [{"path": "../src/tsconfig.esm.json"}] +} diff --git a/test-ts-types/js-cjs-import-cjs-output/bad.js b/test-ts-types/js-cjs-import-cjs-output/bad.js deleted file mode 100644 index be5127947cd..00000000000 --- a/test-ts-types/js-cjs-import-cjs-output/bad.js +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index f4663006078..00000000000 --- a/test-ts-types/js-cjs-import-cjs-output/good.js +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 6141e954b0d..00000000000 --- a/test-ts-types/js-cjs-import-cjs-output/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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" - }, - "dependencies": { - "puppeteer": "file:../../puppeteer.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 deleted file mode 100644 index 2889972c4b8..00000000000 --- a/test-ts-types/js-cjs-import-cjs-output/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "checkJs": true, - "allowJs": true, - "strict": true, - "outDir": "dist", - "moduleResolution": "node" - }, - "files": ["good.js", "bad.js"] -} diff --git a/test-ts-types/js-cjs-import-esm-output/bad.js b/test-ts-types/js-cjs-import-esm-output/bad.js deleted file mode 100644 index be5127947cd..00000000000 --- a/test-ts-types/js-cjs-import-esm-output/bad.js +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index f4663006078..00000000000 --- a/test-ts-types/js-cjs-import-esm-output/good.js +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 6141e954b0d..00000000000 --- a/test-ts-types/js-cjs-import-esm-output/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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" - }, - "dependencies": { - "puppeteer": "file:../../puppeteer.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 deleted file mode 100644 index e2ce292bf3e..00000000000 --- a/test-ts-types/js-cjs-import-esm-output/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "checkJs": true, - "allowJs": true, - "strict": true, - "outDir": "dist", - "moduleResolution": "node" - }, - "files": ["good.js", "bad.js"] -} diff --git a/test-ts-types/js-esm-import-cjs-output/bad.js b/test-ts-types/js-esm-import-cjs-output/bad.js deleted file mode 100644 index cda9916d830..00000000000 --- a/test-ts-types/js-esm-import-cjs-output/bad.js +++ /dev/null @@ -1,25 +0,0 @@ -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); - const contentsOfDiv = await div.evaluate( - /** - * @param {number} divElem - * @returns number - */ - (divElem) => divElem.innerText - ); -} -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 deleted file mode 100644 index 544c43cf8ba..00000000000 --- a/test-ts-types/js-esm-import-cjs-output/good.js +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 6141e954b0d..00000000000 --- a/test-ts-types/js-esm-import-cjs-output/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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" - }, - "dependencies": { - "puppeteer": "file:../../puppeteer.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 deleted file mode 100644 index 2889972c4b8..00000000000 --- a/test-ts-types/js-esm-import-cjs-output/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "checkJs": true, - "allowJs": true, - "strict": true, - "outDir": "dist", - "moduleResolution": "node" - }, - "files": ["good.js", "bad.js"] -} diff --git a/test-ts-types/js-esm-import-esm-output/bad.js b/test-ts-types/js-esm-import-esm-output/bad.js deleted file mode 100644 index ba7b56133d4..00000000000 --- a/test-ts-types/js-esm-import-esm-output/bad.js +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 544c43cf8ba..00000000000 --- a/test-ts-types/js-esm-import-esm-output/good.js +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 6141e954b0d..00000000000 --- a/test-ts-types/js-esm-import-esm-output/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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" - }, - "dependencies": { - "puppeteer": "file:../../puppeteer.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 deleted file mode 100644 index e2ce292bf3e..00000000000 --- a/test-ts-types/js-esm-import-esm-output/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "checkJs": true, - "allowJs": true, - "strict": true, - "outDir": "dist", - "moduleResolution": "node" - }, - "files": ["good.js", "bad.js"] -} diff --git a/test-ts-types/ts-cjs-import-cjs-output/bad.ts b/test-ts-types/ts-cjs-import-cjs-output/bad.ts deleted file mode 100644 index fa7a2a57812..00000000000 --- a/test-ts-types/ts-cjs-import-cjs-output/bad.ts +++ /dev/null @@ -1,17 +0,0 @@ -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; - 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 deleted file mode 100644 index 64b50137245..00000000000 --- a/test-ts-types/ts-cjs-import-cjs-output/good.ts +++ /dev/null @@ -1,16 +0,0 @@ -import puppeteer = require('puppeteer'); - -async function run() { - const browser = await puppeteer.launch(); - const devices = puppeteer.devices; - console.log(devices); - const page = await browser.newPage(); - page.on('request', (request) => { - const resourceType = request.resourceType(); - }); - const div = (await page.$( - 'div' - )) as puppeteer.ElementHandle; - 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 deleted file mode 100644 index 6141e954b0d..00000000000 --- a/test-ts-types/ts-cjs-import-cjs-output/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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" - }, - "dependencies": { - "puppeteer": "file:../../puppeteer.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 deleted file mode 100644 index a417e47c143..00000000000 --- a/test-ts-types/ts-cjs-import-cjs-output/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "strict": true, - "outDir": "dist", - "moduleResolution": "node" - }, - "files": ["good.ts", "bad.ts"] -} diff --git a/test-ts-types/ts-esm-import-cjs-output/bad.ts b/test-ts-types/ts-esm-import-cjs-output/bad.ts deleted file mode 100644 index 8f890575fa4..00000000000 --- a/test-ts-types/ts-esm-import-cjs-output/bad.ts +++ /dev/null @@ -1,18 +0,0 @@ -// 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; - 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 deleted file mode 100644 index ed7764140d8..00000000000 --- a/test-ts-types/ts-esm-import-cjs-output/good.ts +++ /dev/null @@ -1,13 +0,0 @@ -// 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 deleted file mode 100644 index 6141e954b0d..00000000000 --- a/test-ts-types/ts-esm-import-cjs-output/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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" - }, - "dependencies": { - "puppeteer": "file:../../puppeteer.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 deleted file mode 100644 index a417e47c143..00000000000 --- a/test-ts-types/ts-esm-import-cjs-output/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "strict": true, - "outDir": "dist", - "moduleResolution": "node" - }, - "files": ["good.ts", "bad.ts"] -} diff --git a/test-ts-types/ts-esm-import-esm-output/bad.ts b/test-ts-types/ts-esm-import-esm-output/bad.ts deleted file mode 100644 index d08e6f450ad..00000000000 --- a/test-ts-types/ts-esm-import-esm-output/bad.ts +++ /dev/null @@ -1,30 +0,0 @@ -// 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; - console.log('got a div!', div); - const contentsOfDiv = await div.evaluate( - // Bad: the type system will know here that divElem is an HTMLAnchorElement - // and won't let me tell it it's a number - (divElem: number) => divElem.innerText - ); - // Bad: the type system will know here that divElem is an HTMLAnchorElement - // and won't let me tell it it's a number via the generic - const contentsOfDiv2 = await div.evaluate<(x: number) => string>( - // Bad: now I've forced it to be a number (which is an error also) - // I can't call `innerText` on it. - (divElem: number) => divElem.innerText - ); -} -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 deleted file mode 100644 index af19f0efb63..00000000000 --- a/test-ts-types/ts-esm-import-esm-output/good.ts +++ /dev/null @@ -1,15 +0,0 @@ -// 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); - - const contentsOfDiv = await div.evaluate((divElem) => divElem.innerText); -} -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 deleted file mode 100644 index 6141e954b0d..00000000000 --- a/test-ts-types/ts-esm-import-esm-output/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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" - }, - "dependencies": { - "puppeteer": "file:../../puppeteer.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 deleted file mode 100644 index f9e9bb5f878..00000000000 --- a/test-ts-types/ts-esm-import-esm-output/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "strict": true, - "outDir": "dist", - "moduleResolution": "node" - }, - "files": ["good.ts", "bad.ts"] -}