From ffec2475d0cae61ddb4d6d32956408afe836552e Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Mon, 13 Jul 2020 10:22:26 +0100 Subject: [PATCH] chore: enforce file extensions on imports (#6202) * chore: enforce file extensions on imports To make our output agnostic it should include file extensions in the output, as per the ESM spec. It's a bit odd for Node packages but makes it easier to publish a browser build. --- .eslintrc.js | 6 +- mocha-config/puppeteer-unit-tests.js | 4 +- package.json | 3 +- ...nsure-correct-devtools-protocol-package.ts | 1 + src/api-docs-entry.ts | 62 +++++++++---------- src/common/Accessibility.ts | 4 +- src/common/Browser.ts | 14 ++--- src/common/Connection.ts | 10 +-- src/common/ConsoleMessage.ts | 2 +- src/common/Coverage.ts | 8 +-- src/common/DOMWorld.ts | 27 ++++---- src/common/Debug.ts | 2 +- src/common/Dialog.ts | 4 +- src/common/EmulationManager.ts | 4 +- src/common/EvalTypes.ts | 2 +- src/common/ExecutionContext.ts | 14 ++--- src/common/FileChooser.ts | 4 +- src/common/FrameManager.ts | 31 +++++----- src/common/HTTPRequest.ts | 10 +-- src/common/HTTPResponse.ts | 8 +-- src/common/Input.ts | 6 +- src/common/JSHandle.ts | 18 +++--- src/common/LifecycleWatcher.ts | 20 +++--- src/common/NetworkManager.ts | 14 ++--- src/common/Page.ts | 56 ++++++++++------- src/common/Puppeteer.ts | 23 ++++--- src/common/Target.ts | 10 +-- src/common/Tracing.ts | 6 +- src/common/WebSocketTransport.ts | 2 +- src/common/WebWorker.ts | 12 ++-- src/common/helper.ts | 10 +-- src/index-core.ts | 2 +- src/index.ts | 2 +- src/initialize.ts | 4 +- src/install.ts | 4 +- src/node/BrowserFetcher.ts | 4 +- src/node/BrowserRunner.ts | 16 ++--- src/node/LaunchOptions.ts | 2 +- src/node/Launcher.ts | 18 +++--- src/node/PipeTransport.ts | 8 ++- test/.eslintrc.js | 13 ++++ test/CDPSession.spec.ts | 4 +- test/EventEmitter.spec.ts | 2 +- test/accessibility.spec.ts | 2 +- test/browser.spec.ts | 2 +- test/browsercontext.spec.ts | 4 +- test/chromiumonly.spec.ts | 2 +- test/click.spec.ts | 4 +- test/cookies.spec.ts | 2 +- test/coverage-utils.js | 52 ++++++++-------- test/coverage.spec.ts | 2 +- test/defaultbrowsercontext.spec.ts | 2 +- test/dialog.spec.ts | 2 +- test/elementhandle.spec.ts | 6 +- test/emulation.spec.ts | 2 +- test/evaluation.spec.ts | 4 +- test/fixtures.spec.ts | 2 +- test/frame.spec.ts | 4 +- test/headful.spec.ts | 2 +- test/ignorehttpserrors.spec.ts | 2 +- test/input.spec.ts | 2 +- test/jshandle.spec.ts | 2 +- test/keyboard.spec.ts | 6 +- test/launcher.spec.ts | 6 +- test/mocha-ts-require.js | 8 +++ test/mocha-utils.ts | 14 ++--- test/mouse.spec.ts | 4 +- test/navigation.spec.ts | 4 +- test/network.spec.ts | 4 +- test/oopif.spec.ts | 2 +- test/page.spec.ts | 8 +-- test/queryselector.spec.ts | 2 +- test/requestinterception.spec.ts | 4 +- test/screenshot.spec.ts | 2 +- test/target.spec.ts | 6 +- test/touchscreen.spec.ts | 2 +- test/tracing.spec.ts | 2 +- test/waittask.spec.ts | 4 +- test/worker.spec.ts | 8 +-- 79 files changed, 356 insertions(+), 306 deletions(-) create mode 100644 test/.eslintrc.js create mode 100644 test/mocha-ts-require.js diff --git a/.eslintrc.js b/.eslintrc.js index 670e7904..bc63a76d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,7 +10,8 @@ module.exports = { "plugins": [ "mocha", "@typescript-eslint", - "unicorn" + "unicorn", + "import" ], "extends": [ @@ -88,7 +89,8 @@ module.exports = { "no-restricted-imports": ["error", { patterns: ["*Events"], - }] + }], + "import/extensions": ["error", "ignorePackages"] }, "overrides": [ { diff --git a/mocha-config/puppeteer-unit-tests.js b/mocha-config/puppeteer-unit-tests.js index fb11fd18..8ab70f6b 100644 --- a/mocha-config/puppeteer-unit-tests.js +++ b/mocha-config/puppeteer-unit-tests.js @@ -18,9 +18,9 @@ const base = require('./base'); module.exports = { ...base, - require: ['ts-node/register', './test/mocha-utils.ts'], + require: ['./test/mocha-ts-require', './test/mocha-utils.ts'], spec: 'test/*.spec.ts', - extension: ['ts'], + extension: ['js', 'ts'], parallel: process.env.CI && !process.env.COVERAGE, // retry twice more, so we run each test up to 3 times if needed. retries: process.env.CI ? 2 : 0, diff --git a/package.json b/package.json index d6fc5119..f3a43990 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "node": ">=10.18.1" }, "scripts": { - "unit": "tsc --version && mocha --config mocha-config/puppeteer-unit-tests.js", + "unit": "npm run tsc-cjs && mocha --config mocha-config/puppeteer-unit-tests.js", "unit-with-coverage": "cross-env COVERAGE=1 npm run unit", "assert-unit-coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js", "funit": "PUPPETEER_PRODUCT=firefox npm run unit", @@ -76,6 +76,7 @@ "dependency-cruiser": "^9.7.0", "eslint": "^6.8.0", "eslint-config-prettier": "^6.11.0", + "eslint-plugin-import": "^2.22.0", "eslint-plugin-mocha": "^6.3.0", "eslint-plugin-prettier": "^3.1.3", "eslint-plugin-unicorn": "^19.0.1", diff --git a/scripts/ensure-correct-devtools-protocol-package.ts b/scripts/ensure-correct-devtools-protocol-package.ts index f953844c..2d6a4a1d 100644 --- a/scripts/ensure-correct-devtools-protocol-package.ts +++ b/scripts/ensure-correct-devtools-protocol-package.ts @@ -33,6 +33,7 @@ * find the one closest to our Chromium revision. */ +// eslint-disable-next-line import/extensions import { PUPPETEER_REVISIONS } from '../src/revisions'; import { execSync } from 'child_process'; diff --git a/src/api-docs-entry.ts b/src/api-docs-entry.ts index 359c3989..c132fba8 100644 --- a/src/api-docs-entry.ts +++ b/src/api-docs-entry.ts @@ -25,34 +25,34 @@ * Once we have migrated to API Extractor and removed DocLint we can remove the * duplication and use this file. */ -export * from './common/Accessibility'; -export * from './common/Browser'; -export * from './node/BrowserFetcher'; -export * from './common/Connection'; -export * from './common/ConsoleMessage'; -export * from './common/Coverage'; -export * from './common/DeviceDescriptors'; -export * from './common/Dialog'; -export * from './common/DOMWorld'; -export * from './common/JSHandle'; -export * from './common/ExecutionContext'; -export * from './common/EventEmitter'; -export * from './common/FileChooser'; -export * from './common/FrameManager'; -export * from './common/Input'; -export * from './common/Page'; -export * from './common/Puppeteer'; -export * from './node/LaunchOptions'; -export * from './node/Launcher'; -export * from './common/HTTPRequest'; -export * from './common/HTTPResponse'; -export * from './common/SecurityDetails'; -export * from './common/Target'; -export * from './common/Errors'; -export * from './common/Tracing'; -export * from './common/NetworkManager'; -export * from './common/WebWorker'; -export * from './common/USKeyboardLayout'; -export * from './common/EvalTypes'; -export * from './common/TimeoutSettings'; -export * from './common/LifecycleWatcher'; +export * from './common/Accessibility.js'; +export * from './common/Browser.js'; +export * from './node/BrowserFetcher.js'; +export * from './common/Connection.js'; +export * from './common/ConsoleMessage.js'; +export * from './common/Coverage.js'; +export * from './common/DeviceDescriptors.js'; +export * from './common/Dialog.js'; +export * from './common/DOMWorld.js'; +export * from './common/JSHandle.js'; +export * from './common/ExecutionContext.js'; +export * from './common/EventEmitter.js'; +export * from './common/FileChooser.js'; +export * from './common/FrameManager.js'; +export * from './common/Input.js'; +export * from './common/Page.js'; +export * from './common/Puppeteer.js'; +export * from './node/LaunchOptions.js'; +export * from './node/Launcher.js'; +export * from './common/HTTPRequest.js'; +export * from './common/HTTPResponse.js'; +export * from './common/SecurityDetails.js'; +export * from './common/Target.js'; +export * from './common/Errors.js'; +export * from './common/Tracing.js'; +export * from './common/NetworkManager.js'; +export * from './common/WebWorker.js'; +export * from './common/USKeyboardLayout.js'; +export * from './common/EvalTypes.js'; +export * from './common/TimeoutSettings.js'; +export * from './common/LifecycleWatcher.js'; diff --git a/src/common/Accessibility.ts b/src/common/Accessibility.ts index cc41c325..919f06d3 100644 --- a/src/common/Accessibility.ts +++ b/src/common/Accessibility.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { CDPSession } from './Connection'; -import { ElementHandle } from './JSHandle'; +import { CDPSession } from './Connection.js'; +import { ElementHandle } from './JSHandle.js'; import { Protocol } from 'devtools-protocol'; /** diff --git a/src/common/Browser.ts b/src/common/Browser.ts index 060e50f1..ff4d553b 100644 --- a/src/common/Browser.ts +++ b/src/common/Browser.ts @@ -14,15 +14,15 @@ * limitations under the License. */ -import { assert } from './assert'; -import { helper } from './helper'; -import { Target } from './Target'; -import { EventEmitter } from './EventEmitter'; -import { Connection, ConnectionEmittedEvents } from './Connection'; +import { assert } from './assert.js'; +import { helper } from './helper.js'; +import { Target } from './Target.js'; +import { EventEmitter } from './EventEmitter.js'; +import { Connection, ConnectionEmittedEvents } from './Connection.js'; import { Protocol } from 'devtools-protocol'; -import { Page } from './Page'; +import { Page } from './Page.js'; import { ChildProcess } from 'child_process'; -import { Viewport } from './PuppeteerViewport'; +import { Viewport } from './PuppeteerViewport.js'; type BrowserCloseCallback = () => Promise | void; diff --git a/src/common/Connection.ts b/src/common/Connection.ts index 7765fad2..fc2d3607 100644 --- a/src/common/Connection.ts +++ b/src/common/Connection.ts @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { assert } from './assert'; -import { debug } from './Debug'; +import { assert } from './assert.js'; +import { debug } from './Debug.js'; const debugProtocolSend = debug('puppeteer:protocol:SEND ►'); const debugProtocolReceive = debug('puppeteer:protocol:RECV ◀'); import { Protocol } from 'devtools-protocol'; -import { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping'; -import { ConnectionTransport } from './ConnectionTransport'; -import { EventEmitter } from './EventEmitter'; +import { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js'; +import { ConnectionTransport } from './ConnectionTransport.js'; +import { EventEmitter } from './EventEmitter.js'; interface ConnectionCallback { resolve: Function; diff --git a/src/common/ConsoleMessage.ts b/src/common/ConsoleMessage.ts index d0f658de..7b772dc4 100644 --- a/src/common/ConsoleMessage.ts +++ b/src/common/ConsoleMessage.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { JSHandle } from './JSHandle'; +import { JSHandle } from './JSHandle.js'; /** * @public diff --git a/src/common/Coverage.ts b/src/common/Coverage.ts index 47fa003e..63060e65 100644 --- a/src/common/Coverage.ts +++ b/src/common/Coverage.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import { assert } from './assert'; -import { helper, debugError, PuppeteerEventListener } from './helper'; +import { assert } from './assert.js'; +import { helper, debugError, PuppeteerEventListener } from './helper.js'; import { Protocol } from 'devtools-protocol'; -import { CDPSession } from './Connection'; +import { CDPSession } from './Connection.js'; -import { EVALUATION_SCRIPT_URL } from './ExecutionContext'; +import { EVALUATION_SCRIPT_URL } from './ExecutionContext.js'; /** * The CoverageEntry class represents one entry of the coverage report. diff --git a/src/common/DOMWorld.ts b/src/common/DOMWorld.ts index 28f37b9c..1a64a7ed 100644 --- a/src/common/DOMWorld.ts +++ b/src/common/DOMWorld.ts @@ -14,16 +14,19 @@ * limitations under the License. */ -import { assert } from './assert'; -import { helper } from './helper'; -import { LifecycleWatcher, PuppeteerLifeCycleEvent } from './LifecycleWatcher'; -import { TimeoutError } from './Errors'; -import { JSHandle, ElementHandle } from './JSHandle'; -import { ExecutionContext } from './ExecutionContext'; -import { TimeoutSettings } from './TimeoutSettings'; -import { MouseButton } from './Input'; -import { FrameManager, Frame } from './FrameManager'; -import { getQueryHandlerAndSelector, QueryHandler } from './QueryHandler'; +import { assert } from './assert.js'; +import { helper } from './helper.js'; +import { + LifecycleWatcher, + PuppeteerLifeCycleEvent, +} from './LifecycleWatcher.js'; +import { TimeoutError } from './Errors.js'; +import { JSHandle, ElementHandle } from './JSHandle.js'; +import { ExecutionContext } from './ExecutionContext.js'; +import { TimeoutSettings } from './TimeoutSettings.js'; +import { MouseButton } from './Input.js'; +import { FrameManager, Frame } from './FrameManager.js'; +import { getQueryHandlerAndSelector, QueryHandler } from './QueryHandler.js'; import { SerializableOrJSHandle, EvaluateHandleFn, @@ -31,8 +34,8 @@ import { EvaluateFn, EvaluateFnReturnType, UnwrapPromiseLike, -} from './EvalTypes'; -import { isNode } from '../environment'; +} from './EvalTypes.js'; +import { isNode } from '../environment.js'; // This predicateQueryHandler is declared here so that TypeScript knows about it // when it is used in the predicate function below. diff --git a/src/common/Debug.ts b/src/common/Debug.ts index 236be96d..e9a608e3 100644 --- a/src/common/Debug.ts +++ b/src/common/Debug.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { isNode } from '../environment'; +import { isNode } from '../environment.js'; /** * A debug function that can be used in any environment. diff --git a/src/common/Dialog.ts b/src/common/Dialog.ts index 3223936d..48720239 100644 --- a/src/common/Dialog.ts +++ b/src/common/Dialog.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { assert } from './assert'; -import { CDPSession } from './Connection'; +import { assert } from './assert.js'; +import { CDPSession } from './Connection.js'; import { Protocol } from 'devtools-protocol'; /** diff --git a/src/common/EmulationManager.ts b/src/common/EmulationManager.ts index 17d77f38..f3130ef3 100644 --- a/src/common/EmulationManager.ts +++ b/src/common/EmulationManager.ts @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { CDPSession } from './Connection'; -import { Viewport } from './PuppeteerViewport'; +import { CDPSession } from './Connection.js'; +import { Viewport } from './PuppeteerViewport.js'; import { Protocol } from 'devtools-protocol'; export class EmulationManager { diff --git a/src/common/EvalTypes.ts b/src/common/EvalTypes.ts index 95b4039b..7a933594 100644 --- a/src/common/EvalTypes.ts +++ b/src/common/EvalTypes.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { JSHandle, ElementHandle } from './JSHandle'; +import { JSHandle, ElementHandle } from './JSHandle.js'; /** * @public diff --git a/src/common/ExecutionContext.ts b/src/common/ExecutionContext.ts index b3473f0b..68bbd369 100644 --- a/src/common/ExecutionContext.ts +++ b/src/common/ExecutionContext.ts @@ -14,14 +14,14 @@ * limitations under the License. */ -import { assert } from './assert'; -import { helper } from './helper'; -import { createJSHandle, JSHandle, ElementHandle } from './JSHandle'; -import { CDPSession } from './Connection'; -import { DOMWorld } from './DOMWorld'; -import { Frame } from './FrameManager'; +import { assert } from './assert.js'; +import { helper } from './helper.js'; +import { createJSHandle, JSHandle, ElementHandle } from './JSHandle.js'; +import { CDPSession } from './Connection.js'; +import { DOMWorld } from './DOMWorld.js'; +import { Frame } from './FrameManager.js'; import { Protocol } from 'devtools-protocol'; -import { EvaluateHandleFn, SerializableOrJSHandle } from './EvalTypes'; +import { EvaluateHandleFn, SerializableOrJSHandle } from './EvalTypes.js'; export const EVALUATION_SCRIPT_URL = '__puppeteer_evaluation_script__'; const SOURCE_URL_REGEX = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m; diff --git a/src/common/FileChooser.ts b/src/common/FileChooser.ts index cbd086d7..34069188 100644 --- a/src/common/FileChooser.ts +++ b/src/common/FileChooser.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { ElementHandle } from './JSHandle'; +import { ElementHandle } from './JSHandle.js'; import { Protocol } from 'devtools-protocol'; -import { assert } from './assert'; +import { assert } from './assert.js'; /** * File choosers let you react to the page requesting for a file. diff --git a/src/common/FrameManager.ts b/src/common/FrameManager.ts index 366f7bed..491b6bba 100644 --- a/src/common/FrameManager.ts +++ b/src/common/FrameManager.ts @@ -14,19 +14,22 @@ * limitations under the License. */ -import { EventEmitter } from './EventEmitter'; -import { assert } from './assert'; -import { helper, debugError } from './helper'; -import { ExecutionContext, EVALUATION_SCRIPT_URL } from './ExecutionContext'; -import { LifecycleWatcher, PuppeteerLifeCycleEvent } from './LifecycleWatcher'; -import { DOMWorld, WaitForSelectorOptions } from './DOMWorld'; -import { NetworkManager } from './NetworkManager'; -import { TimeoutSettings } from './TimeoutSettings'; -import { CDPSession } from './Connection'; -import { JSHandle, ElementHandle } from './JSHandle'; -import { MouseButton } from './Input'; -import { Page } from './Page'; -import { HTTPResponse } from './HTTPResponse'; +import { EventEmitter } from './EventEmitter.js'; +import { assert } from './assert.js'; +import { helper, debugError } from './helper.js'; +import { ExecutionContext, EVALUATION_SCRIPT_URL } from './ExecutionContext.js'; +import { + LifecycleWatcher, + PuppeteerLifeCycleEvent, +} from './LifecycleWatcher.js'; +import { DOMWorld, WaitForSelectorOptions } from './DOMWorld.js'; +import { NetworkManager } from './NetworkManager.js'; +import { TimeoutSettings } from './TimeoutSettings.js'; +import { CDPSession } from './Connection.js'; +import { JSHandle, ElementHandle } from './JSHandle.js'; +import { MouseButton } from './Input.js'; +import { Page } from './Page.js'; +import { HTTPResponse } from './HTTPResponse.js'; import { Protocol } from 'devtools-protocol'; import { SerializableOrJSHandle, @@ -35,7 +38,7 @@ import { EvaluateFn, EvaluateFnReturnType, UnwrapPromiseLike, -} from './EvalTypes'; +} from './EvalTypes.js'; const UTILITY_WORLD_NAME = '__puppeteer_utility_world__'; diff --git a/src/common/HTTPRequest.ts b/src/common/HTTPRequest.ts index a27b94a8..3e8b60a5 100644 --- a/src/common/HTTPRequest.ts +++ b/src/common/HTTPRequest.ts @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { CDPSession } from './Connection'; -import { Frame } from './FrameManager'; -import { HTTPResponse } from './HTTPResponse'; -import { assert } from './assert'; -import { helper, debugError } from './helper'; +import { CDPSession } from './Connection.js'; +import { Frame } from './FrameManager.js'; +import { HTTPResponse } from './HTTPResponse.js'; +import { assert } from './assert.js'; +import { helper, debugError } from './helper.js'; import { Protocol } from 'devtools-protocol'; /** diff --git a/src/common/HTTPResponse.ts b/src/common/HTTPResponse.ts index 575b684e..3df6c627 100644 --- a/src/common/HTTPResponse.ts +++ b/src/common/HTTPResponse.ts @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { CDPSession } from './Connection'; -import { Frame } from './FrameManager'; -import { HTTPRequest } from './HTTPRequest'; -import { SecurityDetails } from './SecurityDetails'; +import { CDPSession } from './Connection.js'; +import { Frame } from './FrameManager.js'; +import { HTTPRequest } from './HTTPRequest.js'; +import { SecurityDetails } from './SecurityDetails.js'; import { Protocol } from 'devtools-protocol'; /** diff --git a/src/common/Input.ts b/src/common/Input.ts index 30443c92..495bd284 100644 --- a/src/common/Input.ts +++ b/src/common/Input.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { assert } from './assert'; -import { CDPSession } from './Connection'; -import { keyDefinitions, KeyDefinition, KeyInput } from './USKeyboardLayout'; +import { assert } from './assert.js'; +import { CDPSession } from './Connection.js'; +import { keyDefinitions, KeyDefinition, KeyInput } from './USKeyboardLayout.js'; type KeyDescription = Required< Pick diff --git a/src/common/JSHandle.ts b/src/common/JSHandle.ts index ffb0c6b2..806ad814 100644 --- a/src/common/JSHandle.ts +++ b/src/common/JSHandle.ts @@ -14,14 +14,14 @@ * limitations under the License. */ -import { assert } from './assert'; -import { helper, debugError } from './helper'; -import { ExecutionContext } from './ExecutionContext'; -import { Page } from './Page'; -import { CDPSession } from './Connection'; -import { KeyInput } from './USKeyboardLayout'; -import { FrameManager, Frame } from './FrameManager'; -import { getQueryHandlerAndSelector } from './QueryHandler'; +import { assert } from './assert.js'; +import { helper, debugError } from './helper.js'; +import { ExecutionContext } from './ExecutionContext.js'; +import { Page } from './Page.js'; +import { CDPSession } from './Connection.js'; +import { KeyInput } from './USKeyboardLayout.js'; +import { FrameManager, Frame } from './FrameManager.js'; +import { getQueryHandlerAndSelector } from './QueryHandler.js'; import { Protocol } from 'devtools-protocol'; import { EvaluateFn, @@ -30,7 +30,7 @@ import { EvaluateHandleFn, WrapElementHandle, UnwrapPromiseLike, -} from './EvalTypes'; +} from './EvalTypes.js'; export interface BoxModel { content: Array<{ x: number; y: number }>; diff --git a/src/common/LifecycleWatcher.ts b/src/common/LifecycleWatcher.ts index 45ff9711..2b8ab604 100644 --- a/src/common/LifecycleWatcher.ts +++ b/src/common/LifecycleWatcher.ts @@ -14,14 +14,18 @@ * limitations under the License. */ -import { assert } from './assert'; -import { helper, PuppeteerEventListener } from './helper'; -import { TimeoutError } from './Errors'; -import { FrameManager, Frame, FrameManagerEmittedEvents } from './FrameManager'; -import { HTTPRequest } from './HTTPRequest'; -import { HTTPResponse } from './HTTPResponse'; -import { NetworkManagerEmittedEvents } from './NetworkManager'; -import { CDPSessionEmittedEvents } from './Connection'; +import { assert } from './assert.js'; +import { helper, PuppeteerEventListener } from './helper.js'; +import { TimeoutError } from './Errors.js'; +import { + FrameManager, + Frame, + FrameManagerEmittedEvents, +} from './FrameManager.js'; +import { HTTPRequest } from './HTTPRequest.js'; +import { HTTPResponse } from './HTTPResponse.js'; +import { NetworkManagerEmittedEvents } from './NetworkManager.js'; +import { CDPSessionEmittedEvents } from './Connection.js'; export type PuppeteerLifeCycleEvent = | 'load' diff --git a/src/common/NetworkManager.ts b/src/common/NetworkManager.ts index 4eaf1e05..52b0aee0 100644 --- a/src/common/NetworkManager.ts +++ b/src/common/NetworkManager.ts @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EventEmitter } from './EventEmitter'; -import { assert } from './assert'; -import { helper, debugError } from './helper'; +import { EventEmitter } from './EventEmitter.js'; +import { assert } from './assert.js'; +import { helper, debugError } from './helper.js'; import { Protocol } from 'devtools-protocol'; -import { CDPSession } from './Connection'; -import { FrameManager } from './FrameManager'; -import { HTTPRequest } from './HTTPRequest'; -import { HTTPResponse } from './HTTPResponse'; +import { CDPSession } from './Connection.js'; +import { FrameManager } from './FrameManager.js'; +import { HTTPRequest } from './HTTPRequest.js'; +import { HTTPResponse } from './HTTPResponse.js'; /** * @public diff --git a/src/common/Page.ts b/src/common/Page.ts index a58f9fbf..388ca610 100644 --- a/src/common/Page.ts +++ b/src/common/Page.ts @@ -16,30 +16,38 @@ import * as fs from 'fs'; import { promisify } from 'util'; -import { EventEmitter } from './EventEmitter'; +import { EventEmitter } from './EventEmitter.js'; import * as mime from 'mime'; -import { Connection, CDPSession, CDPSessionEmittedEvents } from './Connection'; -import { Dialog } from './Dialog'; -import { EmulationManager } from './EmulationManager'; -import { Frame, FrameManager, FrameManagerEmittedEvents } from './FrameManager'; -import { Keyboard, Mouse, Touchscreen, MouseButton } from './Input'; -import { Tracing } from './Tracing'; -import { assert } from './assert'; -import { helper, debugError } from './helper'; -import { Coverage } from './Coverage'; -import { WebWorker } from './WebWorker'; -import { Browser, BrowserContext } from './Browser'; -import { Target } from './Target'; -import { createJSHandle, JSHandle, ElementHandle } from './JSHandle'; -import { Viewport } from './PuppeteerViewport'; -import { Credentials, NetworkManagerEmittedEvents } from './NetworkManager'; -import { HTTPRequest } from './HTTPRequest'; -import { HTTPResponse } from './HTTPResponse'; -import { Accessibility } from './Accessibility'; -import { TimeoutSettings } from './TimeoutSettings'; -import { FileChooser } from './FileChooser'; -import { ConsoleMessage, ConsoleMessageType } from './ConsoleMessage'; -import { PuppeteerLifeCycleEvent } from './LifecycleWatcher'; +import { + Connection, + CDPSession, + CDPSessionEmittedEvents, +} from './Connection.js'; +import { Dialog } from './Dialog.js'; +import { EmulationManager } from './EmulationManager.js'; +import { + Frame, + FrameManager, + FrameManagerEmittedEvents, +} from './FrameManager.js'; +import { Keyboard, Mouse, Touchscreen, MouseButton } from './Input.js'; +import { Tracing } from './Tracing.js'; +import { assert } from './assert.js'; +import { helper, debugError } from './helper.js'; +import { Coverage } from './Coverage.js'; +import { WebWorker } from './WebWorker.js'; +import { Browser, BrowserContext } from './Browser.js'; +import { Target } from './Target.js'; +import { createJSHandle, JSHandle, ElementHandle } from './JSHandle.js'; +import { Viewport } from './PuppeteerViewport.js'; +import { Credentials, NetworkManagerEmittedEvents } from './NetworkManager.js'; +import { HTTPRequest } from './HTTPRequest.js'; +import { HTTPResponse } from './HTTPResponse.js'; +import { Accessibility } from './Accessibility.js'; +import { TimeoutSettings } from './TimeoutSettings.js'; +import { FileChooser } from './FileChooser.js'; +import { ConsoleMessage, ConsoleMessageType } from './ConsoleMessage.js'; +import { PuppeteerLifeCycleEvent } from './LifecycleWatcher.js'; import { Protocol } from 'devtools-protocol'; import { SerializableOrJSHandle, @@ -48,7 +56,7 @@ import { EvaluateFn, EvaluateFnReturnType, UnwrapPromiseLike, -} from './EvalTypes'; +} from './EvalTypes.js'; const writeFileAsync = promisify(fs.writeFile); diff --git a/src/common/Puppeteer.ts b/src/common/Puppeteer.ts index e4833c9a..310f7c20 100644 --- a/src/common/Puppeteer.ts +++ b/src/common/Puppeteer.ts @@ -13,26 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Launcher from '../node/Launcher'; +import Launcher from '../node/Launcher.js'; import { LaunchOptions, ChromeArgOptions, BrowserOptions, -} from '../node/LaunchOptions'; -import { ProductLauncher } from '../node/Launcher'; -import { BrowserFetcher, BrowserFetcherOptions } from '../node/BrowserFetcher'; -import { puppeteerErrors, PuppeteerErrors } from './Errors'; -import { ConnectionTransport } from './ConnectionTransport'; -import { devicesMap, DevicesMap } from './DeviceDescriptors'; -import { Browser } from './Browser'; +} from '../node/LaunchOptions.js'; +import { ProductLauncher } from '../node/Launcher.js'; +import { + BrowserFetcher, + BrowserFetcherOptions, +} from '../node/BrowserFetcher.js'; +import { puppeteerErrors, PuppeteerErrors } from './Errors.js'; +import { ConnectionTransport } from './ConnectionTransport.js'; +import { devicesMap, DevicesMap } from './DeviceDescriptors.js'; +import { Browser } from './Browser.js'; import { registerCustomQueryHandler, unregisterCustomQueryHandler, customQueryHandlers, clearQueryHandlers, QueryHandler, -} from './QueryHandler'; -import { PUPPETEER_REVISIONS } from '../revisions'; +} from './QueryHandler.js'; +import { PUPPETEER_REVISIONS } from '../revisions.js'; /** * The main Puppeteer class. Provides the {@link Puppeteer.launch | launch} diff --git a/src/common/Target.ts b/src/common/Target.ts index b5b9ad11..e50dc8ab 100644 --- a/src/common/Target.ts +++ b/src/common/Target.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import { Page, PageEmittedEvents } from './Page'; -import { WebWorker } from './WebWorker'; -import { CDPSession } from './Connection'; -import { Browser, BrowserContext } from './Browser'; -import { Viewport } from './PuppeteerViewport'; +import { Page, PageEmittedEvents } from './Page.js'; +import { WebWorker } from './WebWorker.js'; +import { CDPSession } from './Connection.js'; +import { Browser, BrowserContext } from './Browser.js'; +import { Viewport } from './PuppeteerViewport.js'; import { Protocol } from 'devtools-protocol'; /** diff --git a/src/common/Tracing.ts b/src/common/Tracing.ts index 15b0b14d..ba1a5ff5 100644 --- a/src/common/Tracing.ts +++ b/src/common/Tracing.ts @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { assert } from './assert'; -import { helper } from './helper'; -import { CDPSession } from './Connection'; +import { assert } from './assert.js'; +import { helper } from './helper.js'; +import { CDPSession } from './Connection.js'; /** * @public diff --git a/src/common/WebSocketTransport.ts b/src/common/WebSocketTransport.ts index 1685edac..cd4dd6ad 100644 --- a/src/common/WebSocketTransport.ts +++ b/src/common/WebSocketTransport.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ConnectionTransport } from './ConnectionTransport'; +import { ConnectionTransport } from './ConnectionTransport.js'; import NodeWebSocket from 'ws'; export class WebSocketTransport implements ConnectionTransport { diff --git a/src/common/WebWorker.ts b/src/common/WebWorker.ts index 54d416ac..a4d41531 100644 --- a/src/common/WebWorker.ts +++ b/src/common/WebWorker.ts @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EventEmitter } from './EventEmitter'; -import { debugError } from './helper'; -import { ExecutionContext } from './ExecutionContext'; -import { JSHandle } from './JSHandle'; -import { CDPSession } from './Connection'; +import { EventEmitter } from './EventEmitter.js'; +import { debugError } from './helper.js'; +import { ExecutionContext } from './ExecutionContext.js'; +import { JSHandle } from './JSHandle.js'; +import { CDPSession } from './Connection.js'; import { Protocol } from 'devtools-protocol'; -import { EvaluateHandleFn, SerializableOrJSHandle } from './EvalTypes'; +import { EvaluateHandleFn, SerializableOrJSHandle } from './EvalTypes.js'; /** * @internal diff --git a/src/common/helper.ts b/src/common/helper.ts index b100ddf6..218c41c2 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { TimeoutError } from './Errors'; -import { debug } from './Debug'; +import { TimeoutError } from './Errors.js'; +import { debug } from './Debug.js'; import * as fs from 'fs'; -import { CDPSession } from './Connection'; +import { CDPSession } from './Connection.js'; import { promisify } from 'util'; import { Protocol } from 'devtools-protocol'; -import { CommonEventEmitter } from './EventEmitter'; -import { assert } from './assert'; +import { CommonEventEmitter } from './EventEmitter.js'; +import { assert } from './assert.js'; const openAsync = promisify(fs.open); const writeAsync = promisify(fs.write); diff --git a/src/index-core.ts b/src/index-core.ts index 692279f1..600808a0 100644 --- a/src/index-core.ts +++ b/src/index-core.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { initializePuppeteer } from './initialize'; +import { initializePuppeteer } from './initialize.js'; const puppeteer = initializePuppeteer('puppeteer-core'); export default puppeteer; diff --git a/src/index.ts b/src/index.ts index bcabc493..4d89fe4d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { initializePuppeteer } from './initialize'; +import { initializePuppeteer } from './initialize.js'; const puppeteer = initializePuppeteer('puppeteer'); export default puppeteer; diff --git a/src/initialize.ts b/src/initialize.ts index 563a718f..1c63a62c 100644 --- a/src/initialize.ts +++ b/src/initialize.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { Puppeteer } from './common/Puppeteer'; -import { PUPPETEER_REVISIONS } from './revisions'; +import { Puppeteer } from './common/Puppeteer.js'; +import { PUPPETEER_REVISIONS } from './revisions.js'; import pkgDir from 'pkg-dir'; export const initializePuppeteer = (packageName: string): Puppeteer => { diff --git a/src/install.ts b/src/install.ts index 57872e93..7604f79e 100644 --- a/src/install.ts +++ b/src/install.ts @@ -17,8 +17,8 @@ import os from 'os'; import https from 'https'; import ProgressBar from 'progress'; -import puppeteer from './index'; -import { PUPPETEER_REVISIONS } from './revisions'; +import puppeteer from './index.js'; +import { PUPPETEER_REVISIONS } from './revisions.js'; const firefoxVersions = 'https://product-details.mozilla.org/1.0/firefox_versions.json'; diff --git a/src/node/BrowserFetcher.ts b/src/node/BrowserFetcher.ts index f76cc4c2..f5ecdba4 100644 --- a/src/node/BrowserFetcher.ts +++ b/src/node/BrowserFetcher.ts @@ -23,13 +23,13 @@ import * as https from 'https'; import * as http from 'http'; import extractZip from 'extract-zip'; -import { debug } from '../common/Debug'; +import { debug } from '../common/Debug.js'; import { promisify } from 'util'; import removeRecursive from 'rimraf'; import * as URL from 'url'; import ProxyAgent from 'https-proxy-agent'; import { getProxyForUrl } from 'proxy-from-env'; -import { assert } from '../common/assert'; +import { assert } from '../common/assert.js'; const debugFetcher = debug(`puppeteer:fetcher`); diff --git a/src/node/BrowserRunner.ts b/src/node/BrowserRunner.ts index b7b6d8b4..36d83ca8 100644 --- a/src/node/BrowserRunner.ts +++ b/src/node/BrowserRunner.ts @@ -14,18 +14,18 @@ * limitations under the License. */ -import { debug } from '../common/Debug'; +import { debug } from '../common/Debug.js'; import removeFolder from 'rimraf'; import * as childProcess from 'child_process'; -import { assert } from '../common/assert'; -import { helper, debugError } from '../common/helper'; -import { LaunchOptions } from './LaunchOptions'; -import { Connection } from '../common/Connection'; -import { WebSocketTransport } from '../common/WebSocketTransport'; -import { PipeTransport } from './PipeTransport'; +import { assert } from '../common/assert.js'; +import { helper, debugError } from '../common/helper.js'; +import { LaunchOptions } from './LaunchOptions.js'; +import { Connection } from '../common/Connection.js'; +import { WebSocketTransport } from '../common/WebSocketTransport.js'; +import { PipeTransport } from './PipeTransport.js'; import * as readline from 'readline'; -import { TimeoutError } from '../common/Errors'; +import { TimeoutError } from '../common/Errors.js'; import { promisify } from 'util'; const removeFolderAsync = promisify(removeFolder); diff --git a/src/node/LaunchOptions.ts b/src/node/LaunchOptions.ts index 487020ec..0003ba87 100644 --- a/src/node/LaunchOptions.ts +++ b/src/node/LaunchOptions.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Viewport } from '../common/PuppeteerViewport'; +import { Viewport } from '../common/PuppeteerViewport.js'; /** * Launcher options that only apply to Chrome. diff --git a/src/node/Launcher.ts b/src/node/Launcher.ts index eb165f19..eb345388 100644 --- a/src/node/Launcher.ts +++ b/src/node/Launcher.ts @@ -20,14 +20,14 @@ import * as https from 'https'; import * as URL from 'url'; import * as fs from 'fs'; -import { BrowserFetcher } from './BrowserFetcher'; -import { Connection } from '../common/Connection'; -import { Browser } from '../common/Browser'; -import { assert } from '../common/assert'; -import { debugError } from '../common/helper'; -import { ConnectionTransport } from '../common/ConnectionTransport'; -import { WebSocketTransport } from '../common/WebSocketTransport'; -import { BrowserRunner } from './BrowserRunner'; +import { BrowserFetcher } from './BrowserFetcher.js'; +import { Connection } from '../common/Connection.js'; +import { Browser } from '../common/Browser.js'; +import { assert } from '../common/assert.js'; +import { debugError } from '../common/helper.js'; +import { ConnectionTransport } from '../common/ConnectionTransport.js'; +import { WebSocketTransport } from '../common/WebSocketTransport.js'; +import { BrowserRunner } from './BrowserRunner.js'; import { promisify } from 'util'; const mkdtempAsync = promisify(fs.mkdtemp); @@ -37,7 +37,7 @@ import { ChromeArgOptions, LaunchOptions, BrowserOptions, -} from './LaunchOptions'; +} from './LaunchOptions.js'; /** * Describes a launcher - a class that is able to create and launch a browser instance. diff --git a/src/node/PipeTransport.ts b/src/node/PipeTransport.ts index 9711e23e..e66c2c0b 100644 --- a/src/node/PipeTransport.ts +++ b/src/node/PipeTransport.ts @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { helper, debugError, PuppeteerEventListener } from '../common/helper'; -import { ConnectionTransport } from '../common/ConnectionTransport'; +import { + helper, + debugError, + PuppeteerEventListener, +} from '../common/helper.js'; +import { ConnectionTransport } from '../common/ConnectionTransport.js'; export class PipeTransport implements ConnectionTransport { _pipeWrite: NodeJS.WritableStream; diff --git a/test/.eslintrc.js b/test/.eslintrc.js new file mode 100644 index 00000000..9d86da20 --- /dev/null +++ b/test/.eslintrc.js @@ -0,0 +1,13 @@ +module.exports = { + rules: { + 'no-restricted-imports': [ + 'error', + { + /** The mocha tests run on the compiled output in the /lib directory + * so we should avoid importing from src. + */ + patterns: ['*src*'], + }, + ], + }, +}; diff --git a/test/CDPSession.spec.ts b/test/CDPSession.spec.ts index 29936480..7ba02d6f 100644 --- a/test/CDPSession.spec.ts +++ b/test/CDPSession.spec.ts @@ -14,14 +14,14 @@ * limitations under the License. */ -import { waitEvent } from './utils'; +import { waitEvent } from './utils.js'; import expect from 'expect'; import { getTestState, setupTestBrowserHooks, setupTestPageAndContextHooks, describeChromeOnly, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describeChromeOnly('Target.createCDPSession', function () { setupTestBrowserHooks(); diff --git a/test/EventEmitter.spec.ts b/test/EventEmitter.spec.ts index 9e1d2272..ea0189d9 100644 --- a/test/EventEmitter.spec.ts +++ b/test/EventEmitter.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { EventEmitter } from '../src/common/EventEmitter'; +import { EventEmitter } from '../lib/cjs/common/EventEmitter.js'; import sinon from 'sinon'; import expect from 'expect'; diff --git a/test/accessibility.spec.ts b/test/accessibility.spec.ts index 618be600..e941c683 100644 --- a/test/accessibility.spec.ts +++ b/test/accessibility.spec.ts @@ -20,7 +20,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, describeFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describeFailsFirefox('Accessibility', function () { setupTestBrowserHooks(); diff --git a/test/browser.spec.ts b/test/browser.spec.ts index af2c71f8..0d06e7f6 100644 --- a/test/browser.spec.ts +++ b/test/browser.spec.ts @@ -15,7 +15,7 @@ */ import expect from 'expect'; -import { getTestState, setupTestBrowserHooks } from './mocha-utils'; +import { getTestState, setupTestBrowserHooks } from './mocha-utils'; // eslint-disable-line import/extensions describe('Browser specs', function () { setupTestBrowserHooks(); diff --git a/test/browsercontext.spec.ts b/test/browsercontext.spec.ts index 98502654..dfddb0d8 100644 --- a/test/browsercontext.spec.ts +++ b/test/browsercontext.spec.ts @@ -19,8 +19,8 @@ import { getTestState, setupTestBrowserHooks, itFailsFirefox, -} from './mocha-utils'; -import utils from './utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions +import utils from './utils.js'; describe('BrowserContext', function () { setupTestBrowserHooks(); diff --git a/test/chromiumonly.spec.ts b/test/chromiumonly.spec.ts index 8c0ee81e..65d1c820 100644 --- a/test/chromiumonly.spec.ts +++ b/test/chromiumonly.spec.ts @@ -19,7 +19,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, describeChromeOnly, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describeChromeOnly('Chromium-Specific Launcher tests', function () { describe('Puppeteer.launch |browserURL| option', function () { diff --git a/test/click.spec.ts b/test/click.spec.ts index ab5271ec..2cc4fb7a 100644 --- a/test/click.spec.ts +++ b/test/click.spec.ts @@ -20,8 +20,8 @@ import { setupTestPageAndContextHooks, setupTestBrowserHooks, itFailsFirefox, -} from './mocha-utils'; -import utils from './utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions +import utils from './utils.js'; describe('Page.click', function () { setupTestBrowserHooks(); diff --git a/test/cookies.spec.ts b/test/cookies.spec.ts index ea840fe7..ac57ce22 100644 --- a/test/cookies.spec.ts +++ b/test/cookies.spec.ts @@ -19,7 +19,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('Cookie specs', () => { setupTestBrowserHooks(); diff --git a/test/coverage-utils.js b/test/coverage-utils.js index b320b787..27b06e74 100644 --- a/test/coverage-utils.js +++ b/test/coverage-utils.js @@ -39,32 +39,32 @@ const fs = require('fs'); * part of the TSDoc migration. */ const MODULES_TO_CHECK_FOR_COVERAGE = { - Accessibility: '../src/common/Accessibility', - Browser: '../src/common/Browser', - BrowserContext: '../src/common/Browser', - BrowserFetcher: '../src/node/BrowserFetcher', - CDPSession: '../src/common/Connection', - ConsoleMessage: '../src/common/ConsoleMessage', - Coverage: '../src/common/Coverage', - Dialog: '../src/common/Dialog', - ElementHandle: '../src/common/JSHandle', - ExecutionContext: '../src/common/ExecutionContext', - EventEmitter: '../src/common/EventEmitter', - FileChooser: '../src/common/FileChooser', - Frame: '../src/common/FrameManager', - JSHandle: '../src/common/JSHandle', - Keyboard: '../src/common/Input', - Mouse: '../src/common/Input', - Page: '../src/common/Page', - Puppeteer: '../src/common/Puppeteer', - HTTPRequest: '../src/common/HTTPRequest', - HTTPResponse: '../src/common/HTTPResponse', - SecurityDetails: '../src/common/SecurityDetails', - Target: '../src/common/Target', - TimeoutError: '../src/common/Errors', - Touchscreen: '../src/common/Input', - Tracing: '../src/common/Tracing', - WebWorker: '../src/common/WebWorker', + Accessibility: '../lib/cjs/common/Accessibility', + Browser: '../lib/cjs/common/Browser', + BrowserContext: '../lib/cjs/common/Browser', + BrowserFetcher: '../lib/cjs/node/BrowserFetcher', + CDPSession: '../lib/cjs/common/Connection', + ConsoleMessage: '../lib/cjs/common/ConsoleMessage', + Coverage: '../lib/cjs/common/Coverage', + Dialog: '../lib/cjs/common/Dialog', + ElementHandle: '../lib/cjs/common/JSHandle', + ExecutionContext: '../lib/cjs/common/ExecutionContext', + EventEmitter: '../lib/cjs/common/EventEmitter', + FileChooser: '../lib/cjs/common/FileChooser', + Frame: '../lib/cjs/common/FrameManager', + JSHandle: '../lib/cjs/common/JSHandle', + Keyboard: '../lib/cjs/common/Input', + Mouse: '../lib/cjs/common/Input', + Page: '../lib/cjs/common/Page', + Puppeteer: '../lib/cjs/common/Puppeteer', + HTTPRequest: '../lib/cjs/common/HTTPRequest', + HTTPResponse: '../lib/cjs/common/HTTPResponse', + SecurityDetails: '../lib/cjs/common/SecurityDetails', + Target: '../lib/cjs/common/Target', + TimeoutError: '../lib/cjs/common/Errors', + Touchscreen: '../lib/cjs/common/Input', + Tracing: '../lib/cjs/common/Tracing', + WebWorker: '../lib/cjs/common/WebWorker', }; function traceAPICoverage(apiCoverage, className, modulePath) { diff --git a/test/coverage.spec.ts b/test/coverage.spec.ts index bc92938d..d3aa3bf2 100644 --- a/test/coverage.spec.ts +++ b/test/coverage.spec.ts @@ -20,7 +20,7 @@ import { setupTestPageAndContextHooks, setupTestBrowserHooks, describeChromeOnly, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('Coverage specs', function () { describeChromeOnly('JSCoverage', function () { diff --git a/test/defaultbrowsercontext.spec.ts b/test/defaultbrowsercontext.spec.ts index e4cba190..01dec7f3 100644 --- a/test/defaultbrowsercontext.spec.ts +++ b/test/defaultbrowsercontext.spec.ts @@ -19,7 +19,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('DefaultBrowserContext', function () { setupTestBrowserHooks(); diff --git a/test/dialog.spec.ts b/test/dialog.spec.ts index 3b762ff5..39339f1f 100644 --- a/test/dialog.spec.ts +++ b/test/dialog.spec.ts @@ -21,7 +21,7 @@ import { setupTestPageAndContextHooks, setupTestBrowserHooks, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('Page.Events.Dialog', function () { setupTestBrowserHooks(); diff --git a/test/elementhandle.spec.ts b/test/elementhandle.spec.ts index bfcef439..e7d221b3 100644 --- a/test/elementhandle.spec.ts +++ b/test/elementhandle.spec.ts @@ -21,10 +21,10 @@ import { setupTestPageAndContextHooks, describeFailsFirefox, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions -import utils from './utils'; -import { ElementHandle } from '../src/common/JSHandle'; +import utils from './utils.js'; +import { ElementHandle } from '../lib/cjs/common/JSHandle.js'; describe('ElementHandle specs', function () { setupTestBrowserHooks(); diff --git a/test/emulation.spec.ts b/test/emulation.spec.ts index a54dbafe..ce5986f3 100644 --- a/test/emulation.spec.ts +++ b/test/emulation.spec.ts @@ -21,7 +21,7 @@ import { setupTestPageAndContextHooks, itFailsFirefox, describeFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('Emulation', () => { setupTestBrowserHooks(); diff --git a/test/evaluation.spec.ts b/test/evaluation.spec.ts index c16cf654..a2497d9c 100644 --- a/test/evaluation.spec.ts +++ b/test/evaluation.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import utils from './utils'; +import utils from './utils.js'; import expect from 'expect'; import { getTestState, @@ -22,7 +22,7 @@ import { setupTestPageAndContextHooks, itFailsFirefox, describeFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions const bigint = typeof BigInt !== 'undefined'; diff --git a/test/fixtures.spec.ts b/test/fixtures.spec.ts index 8a45c103..8eca3620 100644 --- a/test/fixtures.spec.ts +++ b/test/fixtures.spec.ts @@ -17,7 +17,7 @@ /* eslint-disable @typescript-eslint/no-var-requires */ import expect from 'expect'; -import { getTestState, itChromeOnly } from './mocha-utils'; +import { getTestState, itChromeOnly } from './mocha-utils'; // eslint-disable-line import/extensions import path from 'path'; diff --git a/test/frame.spec.ts b/test/frame.spec.ts index 8251f1d0..f8132e25 100644 --- a/test/frame.spec.ts +++ b/test/frame.spec.ts @@ -14,14 +14,14 @@ * limitations under the License. */ -import utils from './utils'; +import utils from './utils.js'; import expect from 'expect'; import { getTestState, setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('Frame specs', function () { setupTestBrowserHooks(); diff --git a/test/headful.spec.ts b/test/headful.spec.ts index 88237c0d..119823eb 100644 --- a/test/headful.spec.ts +++ b/test/headful.spec.ts @@ -23,7 +23,7 @@ import { getTestState, describeChromeOnly, itFailsWindows, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions import rimraf from 'rimraf'; const rmAsync = promisify(rimraf); diff --git a/test/ignorehttpserrors.spec.ts b/test/ignorehttpserrors.spec.ts index 1532ee6b..de6f0504 100644 --- a/test/ignorehttpserrors.spec.ts +++ b/test/ignorehttpserrors.spec.ts @@ -19,7 +19,7 @@ import { getTestState, describeFailsFirefox, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('ignoreHTTPSErrors', function () { /* Note that this test creates its own browser rather than use diff --git a/test/input.spec.ts b/test/input.spec.ts index cd2c1033..d87aa137 100644 --- a/test/input.spec.ts +++ b/test/input.spec.ts @@ -21,7 +21,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, describeFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions const FILE_TO_UPLOAD = path.join(__dirname, '/assets/file-to-upload.txt'); diff --git a/test/jshandle.spec.ts b/test/jshandle.spec.ts index cdcb7efb..bb135083 100644 --- a/test/jshandle.spec.ts +++ b/test/jshandle.spec.ts @@ -20,7 +20,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('JSHandle', function () { setupTestBrowserHooks(); diff --git a/test/keyboard.spec.ts b/test/keyboard.spec.ts index cd13574d..9ad47972 100644 --- a/test/keyboard.spec.ts +++ b/test/keyboard.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import utils from './utils'; +import utils from './utils.js'; import os from 'os'; import expect from 'expect'; import { @@ -22,8 +22,8 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; -import { KeyInput } from '../src/common/USKeyboardLayout'; +} from './mocha-utils'; // eslint-disable-line import/extensions +import { KeyInput } from '../lib/cjs/common/USKeyboardLayout.js'; describe('Keyboard', function () { setupTestBrowserHooks(); diff --git a/test/launcher.spec.ts b/test/launcher.spec.ts index ba2c1300..4e1d6232 100644 --- a/test/launcher.spec.ts +++ b/test/launcher.spec.ts @@ -23,11 +23,11 @@ import { itFailsFirefox, itOnlyRegularInstall, itFailsWindowsUntilDate, -} from './mocha-utils'; -import utils from './utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions +import utils from './utils.js'; import expect from 'expect'; import rimraf from 'rimraf'; -import { Page } from '../src/common/Page'; +import { Page } from '../lib/cjs/common/Page.js'; const rmAsync = promisify(rimraf); const mkdtempAsync = promisify(fs.mkdtemp); diff --git a/test/mocha-ts-require.js b/test/mocha-ts-require.js new file mode 100644 index 00000000..2bf2cc67 --- /dev/null +++ b/test/mocha-ts-require.js @@ -0,0 +1,8 @@ +require('ts-node').register({ + /** + * We ignore the lib/ directory because that's already been TypeScript + * compiled and checked. So we don't want to check it again as part of running + * the unit tests. + */ + ignore: ['lib/*', 'node_modules'], +}); diff --git a/test/mocha-utils.ts b/test/mocha-utils.ts index 51717273..2a26afc9 100644 --- a/test/mocha-utils.ts +++ b/test/mocha-utils.ts @@ -14,19 +14,19 @@ * limitations under the License. */ -import { TestServer } from '../utils/testserver/index'; +import { TestServer } from '../utils/testserver/index.js'; import * as path from 'path'; import * as fs from 'fs'; import * as os from 'os'; import sinon from 'sinon'; -import puppeteer from '../src/index'; -import { Browser, BrowserContext } from '../src/common/Browser'; -import { Page } from '../src/common/Page'; -import { Puppeteer } from '../src/common/Puppeteer'; -import utils from './utils'; +import puppeteer from '../lib/cjs/index.js'; +import { Browser, BrowserContext } from '../lib/cjs/common/Browser.js'; +import { Page } from '../lib/cjs/common/Page.js'; +import { Puppeteer } from '../lib/cjs/common/Puppeteer.js'; +import utils from './utils.js'; import rimraf from 'rimraf'; -import { trackCoverage } from './coverage-utils'; +import { trackCoverage } from './coverage-utils.js'; const setupServer = async () => { const assetsPath = path.join(__dirname, 'assets'); diff --git a/test/mouse.spec.ts b/test/mouse.spec.ts index cb114607..7d47b4ca 100644 --- a/test/mouse.spec.ts +++ b/test/mouse.spec.ts @@ -20,8 +20,8 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; -import { KeyInput } from '../src/common/USKeyboardLayout'; +} from './mocha-utils'; // eslint-disable-line import/extensions +import { KeyInput } from '../lib/cjs/common/USKeyboardLayout.js'; interface Dimensions { x: number; diff --git a/test/navigation.spec.ts b/test/navigation.spec.ts index c654b4af..0b367f76 100644 --- a/test/navigation.spec.ts +++ b/test/navigation.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import utils from './utils'; +import utils from './utils.js'; import expect from 'expect'; import { getTestState, @@ -22,7 +22,7 @@ import { setupTestPageAndContextHooks, itFailsFirefox, describeFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions import os from 'os'; describe('navigation', function () { diff --git a/test/network.spec.ts b/test/network.spec.ts index a80d3479..f56902fc 100644 --- a/test/network.spec.ts +++ b/test/network.spec.ts @@ -16,7 +16,7 @@ import fs from 'fs'; import path from 'path'; -import utils from './utils'; +import utils from './utils.js'; import expect from 'expect'; import { getTestState, @@ -24,7 +24,7 @@ import { setupTestPageAndContextHooks, itFailsFirefox, describeFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('network', function () { setupTestBrowserHooks(); diff --git a/test/oopif.spec.ts b/test/oopif.spec.ts index d58b8f56..845429a6 100644 --- a/test/oopif.spec.ts +++ b/test/oopif.spec.ts @@ -15,7 +15,7 @@ */ import expect from 'expect'; -import { getTestState, describeChromeOnly } from './mocha-utils'; +import { getTestState, describeChromeOnly } from './mocha-utils'; // eslint-disable-line import/extensions describeChromeOnly('OOPIF', function () { /* We use a special browser for this test as we need the --site-per-process flag */ diff --git a/test/page.spec.ts b/test/page.spec.ts index 96749481..441bc5ac 100644 --- a/test/page.spec.ts +++ b/test/page.spec.ts @@ -15,7 +15,7 @@ */ import fs from 'fs'; import path from 'path'; -import utils from './utils'; +import utils from './utils.js'; const { waitEvent } = utils; import expect from 'expect'; import sinon from 'sinon'; @@ -25,9 +25,9 @@ import { setupTestPageAndContextHooks, itFailsFirefox, describeFailsFirefox, -} from './mocha-utils'; -import { Page, Metrics } from '../src/common/Page'; -import { JSHandle } from '../src/common/JSHandle'; +} from './mocha-utils'; // eslint-disable-line import/extensions +import { Page, Metrics } from '../lib/cjs/common/Page.js'; +import { JSHandle } from '../lib/cjs/common/JSHandle.js'; describe('Page', function () { setupTestBrowserHooks(); diff --git a/test/queryselector.spec.ts b/test/queryselector.spec.ts index 3beb03de..854fe851 100644 --- a/test/queryselector.spec.ts +++ b/test/queryselector.spec.ts @@ -18,7 +18,7 @@ import { getTestState, setupTestBrowserHooks, setupTestPageAndContextHooks, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('querySelector', function () { setupTestBrowserHooks(); diff --git a/test/requestinterception.spec.ts b/test/requestinterception.spec.ts index 024824aa..e58c356c 100644 --- a/test/requestinterception.spec.ts +++ b/test/requestinterception.spec.ts @@ -16,14 +16,14 @@ import fs from 'fs'; import path from 'path'; -import utils from './utils'; +import utils from './utils.js'; import expect from 'expect'; import { getTestState, setupTestBrowserHooks, setupTestPageAndContextHooks, describeFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('request interception', function () { setupTestBrowserHooks(); diff --git a/test/screenshot.spec.ts b/test/screenshot.spec.ts index 3687e185..fbe50097 100644 --- a/test/screenshot.spec.ts +++ b/test/screenshot.spec.ts @@ -20,7 +20,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('Screenshots', function () { setupTestBrowserHooks(); diff --git a/test/target.spec.ts b/test/target.spec.ts index bc6deb00..7459218d 100644 --- a/test/target.spec.ts +++ b/test/target.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import utils from './utils'; +import utils from './utils.js'; const { waitEvent } = utils; import expect from 'expect'; import { @@ -22,8 +22,8 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; -import { Target } from '../src/common/Target'; +} from './mocha-utils'; // eslint-disable-line import/extensions +import { Target } from '../lib/cjs/common/Target.js'; describe('Target', function () { setupTestBrowserHooks(); diff --git a/test/touchscreen.spec.ts b/test/touchscreen.spec.ts index 8f4129a3..36931d58 100644 --- a/test/touchscreen.spec.ts +++ b/test/touchscreen.spec.ts @@ -20,7 +20,7 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, describeFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describeFailsFirefox('Touchscreen', function () { setupTestBrowserHooks(); diff --git a/test/tracing.spec.ts b/test/tracing.spec.ts index 7b5afeac..64afda9b 100644 --- a/test/tracing.spec.ts +++ b/test/tracing.spec.ts @@ -17,7 +17,7 @@ import fs from 'fs'; import path from 'path'; import expect from 'expect'; -import { getTestState, describeChromeOnly } from './mocha-utils'; +import { getTestState, describeChromeOnly } from './mocha-utils'; // eslint-disable-line import/extensions describeChromeOnly('Tracing', function () { let outputFile; diff --git a/test/waittask.spec.ts b/test/waittask.spec.ts index d31e9523..73bfae40 100644 --- a/test/waittask.spec.ts +++ b/test/waittask.spec.ts @@ -14,14 +14,14 @@ * limitations under the License. */ -import utils from './utils'; +import utils from './utils.js'; import expect from 'expect'; import { getTestState, setupTestBrowserHooks, setupTestPageAndContextHooks, itFailsFirefox, -} from './mocha-utils'; +} from './mocha-utils'; // eslint-disable-line import/extensions describe('waittask specs', function () { setupTestBrowserHooks(); diff --git a/test/worker.spec.ts b/test/worker.spec.ts index 1f070df6..a4a356bf 100644 --- a/test/worker.spec.ts +++ b/test/worker.spec.ts @@ -20,10 +20,10 @@ import { setupTestBrowserHooks, setupTestPageAndContextHooks, describeFailsFirefox, -} from './mocha-utils'; -import utils from './utils'; -import { WebWorker } from '../src/common/WebWorker'; -import { ConsoleMessage } from '../src/common/ConsoleMessage'; +} from './mocha-utils'; // eslint-disable-line import/extensions +import utils from './utils.js'; +import { WebWorker } from '../lib/cjs/common/WebWorker.js'; +import { ConsoleMessage } from '../lib/cjs/common/ConsoleMessage.js'; const { waitEvent } = utils; describeFailsFirefox('Workers', function () {