test: detect dependency cycles (#10973)

This commit is contained in:
Alex Rudenko 2023-09-21 22:22:38 +02:00 committed by GitHub
parent ecd6ac9dfa
commit 02a9917d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 23 deletions

View File

@ -12,7 +12,13 @@ module.exports = {
plugins: ['mocha', '@typescript-eslint', 'import'], plugins: ['mocha', '@typescript-eslint', 'import'],
extends: ['plugin:prettier/recommended'], extends: ['plugin:prettier/recommended', 'plugin:import/typescript'],
settings: {
'import/resolver': {
typescript: true,
},
},
rules: { rules: {
// Brackets keep code readable. // Brackets keep code readable.
@ -111,8 +117,6 @@ module.exports = {
], ],
}, },
], ],
'import/extensions': ['error', 'ignorePackages'],
'import/order': [ 'import/order': [
'error', 'error',
{ {
@ -121,6 +125,8 @@ module.exports = {
}, },
], ],
'import/no-cycle': ['warn', {maxDepth: Infinity}],
'no-restricted-syntax': [ 'no-restricted-syntax': [
'error', 'error',
// Don't allow underscored declarations on camelCased variables/properties. // Don't allow underscored declarations on camelCased variables/properties.

48
package-lock.json generated
View File

@ -47,6 +47,7 @@
"eslint": "8.49.0", "eslint": "8.49.0",
"eslint-config-prettier": "9.0.0", "eslint-config-prettier": "9.0.0",
"eslint-formatter-codeframe": "7.32.1", "eslint-formatter-codeframe": "7.32.1",
"eslint-import-resolver-typescript": "3.6.0",
"eslint-plugin-import": "2.28.1", "eslint-plugin-import": "2.28.1",
"eslint-plugin-mocha": "10.1.0", "eslint-plugin-mocha": "10.1.0",
"eslint-plugin-prettier": "5.0.0", "eslint-plugin-prettier": "5.0.0",
@ -3416,6 +3417,19 @@
"once": "^1.4.0" "once": "^1.4.0"
} }
}, },
"node_modules/enhanced-resolve": {
"version": "5.15.0",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz",
"integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==",
"dev": true,
"dependencies": {
"graceful-fs": "^4.2.4",
"tapable": "^2.2.0"
},
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/entities": { "node_modules/entities": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/entities/-/entities-2.0.3.tgz", "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.3.tgz",
@ -3745,6 +3759,31 @@
"ms": "^2.1.1" "ms": "^2.1.1"
} }
}, },
"node_modules/eslint-import-resolver-typescript": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.6.0.tgz",
"integrity": "sha512-QTHR9ddNnn35RTxlaEnx2gCxqFlF2SEN0SE2d17SqwyM7YOSI2GHWRYp5BiRkObTUNYPupC/3Fq2a0PpT+EKpg==",
"dev": true,
"dependencies": {
"debug": "^4.3.4",
"enhanced-resolve": "^5.12.0",
"eslint-module-utils": "^2.7.4",
"fast-glob": "^3.3.1",
"get-tsconfig": "^4.5.0",
"is-core-module": "^2.11.0",
"is-glob": "^4.0.3"
},
"engines": {
"node": "^14.18.0 || >=16.0.0"
},
"funding": {
"url": "https://opencollective.com/unts/projects/eslint-import-resolver-ts"
},
"peerDependencies": {
"eslint": "*",
"eslint-plugin-import": "*"
}
},
"node_modules/eslint-module-utils": { "node_modules/eslint-module-utils": {
"version": "2.8.0", "version": "2.8.0",
"resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.8.0.tgz", "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.8.0.tgz",
@ -9754,6 +9793,15 @@
"url": "https://opencollective.com/unts" "url": "https://opencollective.com/unts"
} }
}, },
"node_modules/tapable": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz",
"integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/tar": { "node_modules/tar": {
"version": "6.2.0", "version": "6.2.0",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz", "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz",

View File

@ -139,9 +139,9 @@
"@types/tar-fs": "2.0.2", "@types/tar-fs": "2.0.2",
"@types/unbzip2-stream": "1.4.1", "@types/unbzip2-stream": "1.4.1",
"@types/ws": "8.5.5", "@types/ws": "8.5.5",
"@types/yargs": "17.0.24",
"@typescript-eslint/eslint-plugin": "6.7.2", "@typescript-eslint/eslint-plugin": "6.7.2",
"@typescript-eslint/parser": "6.7.2", "@typescript-eslint/parser": "6.7.2",
"@types/yargs": "17.0.24",
"c8": "8.0.1", "c8": "8.0.1",
"commonmark": "0.30.0", "commonmark": "0.30.0",
"cross-env": "7.0.3", "cross-env": "7.0.3",
@ -150,10 +150,11 @@
"eslint": "8.49.0", "eslint": "8.49.0",
"eslint-config-prettier": "9.0.0", "eslint-config-prettier": "9.0.0",
"eslint-formatter-codeframe": "7.32.1", "eslint-formatter-codeframe": "7.32.1",
"eslint-import-resolver-typescript": "3.6.0",
"eslint-plugin-import": "2.28.1", "eslint-plugin-import": "2.28.1",
"eslint-plugin-rulesdir": "0.2.2",
"eslint-plugin-mocha": "10.1.0", "eslint-plugin-mocha": "10.1.0",
"eslint-plugin-prettier": "5.0.0", "eslint-plugin-prettier": "5.0.0",
"eslint-plugin-rulesdir": "0.2.2",
"eslint-plugin-tsdoc": "0.2.17", "eslint-plugin-tsdoc": "0.2.17",
"eslint-plugin-unused-imports": "3.0.0", "eslint-plugin-unused-imports": "3.0.0",
"esprima": "4.0.1", "esprima": "4.0.1",

View File

@ -32,18 +32,6 @@ const BUILTIN_QUERY_HANDLERS = {
const QUERY_SEPARATORS = ['=', '/']; const QUERY_SEPARATORS = ['=', '/'];
/**
* @internal
*/
export function getQueryHandlerByName(
name: string
): typeof QueryHandler | undefined {
if (name in BUILTIN_QUERY_HANDLERS) {
return BUILTIN_QUERY_HANDLERS[name as keyof typeof BUILTIN_QUERY_HANDLERS];
}
return customQueryHandlers.get(name);
}
/** /**
* @internal * @internal
*/ */

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {ElementHandle} from '../api/ElementHandle.js'; import type {ElementHandle} from '../api/ElementHandle.js';
import type {Frame} from '../api/Frame.js'; import type {Frame} from '../api/Frame.js';
import type {WaitForSelectorOptions} from '../api/Page.js'; import type {WaitForSelectorOptions} from '../api/Page.js';
import type PuppeteerUtil from '../injected/injected.js'; import type PuppeteerUtil from '../injected/injected.js';
@ -132,6 +132,7 @@ export class QueryHandler {
return context.puppeteerUtil; return context.puppeteerUtil;
}) })
); );
const {ElementHandle} = await import('../api/ElementHandle.js');
if (!(result instanceof ElementHandle)) { if (!(result instanceof ElementHandle)) {
return null; return null;
} }
@ -150,6 +151,7 @@ export class QueryHandler {
selector: string, selector: string,
options: WaitForSelectorOptions options: WaitForSelectorOptions
): Promise<ElementHandle<Node> | null> { ): Promise<ElementHandle<Node> | null> {
const {ElementHandle} = await import('../api/ElementHandle.js');
let frame!: Frame; let frame!: Frame;
using element = await (async () => { using element = await (async () => {
if (!(elementOrFrame instanceof ElementHandle)) { if (!(elementOrFrame instanceof ElementHandle)) {

View File

@ -1,12 +1,13 @@
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import {EventEmitter as NodeEventEmitter} from 'node:events'; import {EventEmitter as NodeEventEmitter} from 'node:events';
import {expectAssignable} from 'tsd';
import { import {
type CommonEventEmitter, type CommonEventEmitter,
type EventEmitter, type EventEmitter,
type EventType, type EventType,
} from 'puppeteer'; } from 'puppeteer';
import {expectAssignable} from 'tsd';
declare const emitter: EventEmitter<Record<EventType, any>>; declare const emitter: EventEmitter<Record<EventType, any>>;

View File

@ -1,6 +1,7 @@
import {type ElementHandle} from 'puppeteer';
import {expectNotType, expectType} from 'tsd'; import {expectNotType, expectType} from 'tsd';
import {type ElementHandle} from 'puppeteer';
declare const handle: ElementHandle; declare const handle: ElementHandle;
{ {

View File

@ -1,6 +1,7 @@
import {type ElementHandle, type JSHandle} from 'puppeteer';
import {expectNotAssignable, expectNotType, expectType} from 'tsd'; import {expectNotAssignable, expectNotType, expectType} from 'tsd';
import {type ElementHandle, type JSHandle} from 'puppeteer';
declare const handle: JSHandle; declare const handle: JSHandle;
{ {

View File

@ -1,6 +1,7 @@
import type {NodeFor} from 'puppeteer';
import {expectType, expectNotType} from 'tsd'; import {expectType, expectNotType} from 'tsd';
import type {NodeFor} from 'puppeteer';
declare const nodeFor: <Selector extends string>( declare const nodeFor: <Selector extends string>(
selector: Selector selector: Selector
) => NodeFor<Selector>; ) => NodeFor<Selector>;

View File

@ -1,10 +1,11 @@
import {expectType} from 'tsd';
import puppeteer, { import puppeteer, {
type connect, type connect,
type defaultArgs, type defaultArgs,
type executablePath, type executablePath,
type launch, type launch,
} from 'puppeteer'; } from 'puppeteer';
import {expectType} from 'tsd';
expectType<typeof launch>(puppeteer.launch); expectType<typeof launch>(puppeteer.launch);
expectType<typeof connect>(puppeteer.connect); expectType<typeof connect>(puppeteer.connect);