summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/tools
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /remote/test/puppeteer/tools
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/test/puppeteer/tools')
-rwxr-xr-xremote/test/puppeteer/tools/analyze_issue.mjs6
-rwxr-xr-xremote/test/puppeteer/tools/clean.mjs (renamed from remote/test/puppeteer/tools/clean.js)10
-rw-r--r--remote/test/puppeteer/tools/docgen/package.json10
-rw-r--r--remote/test/puppeteer/tools/docgen/tsconfig.json4
-rw-r--r--remote/test/puppeteer/tools/doctest/package.json4
-rw-r--r--remote/test/puppeteer/tools/doctest/tsconfig.json4
-rw-r--r--remote/test/puppeteer/tools/download_chrome_canary.mjs51
-rw-r--r--remote/test/puppeteer/tools/eslint/package.json3
-rw-r--r--remote/test/puppeteer/tools/eslint/src/check-license.ts67
-rw-r--r--remote/test/puppeteer/tools/eslint/tsconfig.json5
-rw-r--r--remote/test/puppeteer/tools/mocha-runner/package.json2
-rw-r--r--remote/test/puppeteer/tools/mocha-runner/src/mocha-runner.ts2
-rw-r--r--remote/test/puppeteer/tools/mocha-runner/tsconfig.json4
-rw-r--r--remote/test/puppeteer/tools/sort-test-expectations.mjs94
-rw-r--r--remote/test/puppeteer/tools/tsconfig.json2
15 files changed, 218 insertions, 50 deletions
diff --git a/remote/test/puppeteer/tools/analyze_issue.mjs b/remote/test/puppeteer/tools/analyze_issue.mjs
index 9592112de0..eff6a4122e 100755
--- a/remote/test/puppeteer/tools/analyze_issue.mjs
+++ b/remote/test/puppeteer/tools/analyze_issue.mjs
@@ -1,4 +1,10 @@
#!/usr/bin/env node
+/**
+ * @license
+ * Copyright 2024 Google Inc.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
// @ts-check
'use strict';
diff --git a/remote/test/puppeteer/tools/clean.js b/remote/test/puppeteer/tools/clean.mjs
index 049fdc0434..aa4ba516b1 100755
--- a/remote/test/puppeteer/tools/clean.js
+++ b/remote/test/puppeteer/tools/clean.mjs
@@ -1,7 +1,13 @@
#!/usr/bin/env node
-const {exec} = require('child_process');
-const {readdirSync} = require('fs');
+/**
+ * @license
+ * Copyright 2022 Google Inc.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import {exec} from 'child_process';
+import {readdirSync} from 'fs';
exec(
`git clean -Xf ${readdirSync(process.cwd())
diff --git a/remote/test/puppeteer/tools/docgen/package.json b/remote/test/puppeteer/tools/docgen/package.json
index f1ca4ea127..82f6d4d6c4 100644
--- a/remote/test/puppeteer/tools/docgen/package.json
+++ b/remote/test/puppeteer/tools/docgen/package.json
@@ -8,7 +8,7 @@
"license": "Apache-2.0",
"scripts": {
"build": "wireit",
- "clean": "../clean.js"
+ "clean": "../clean.mjs"
},
"wireit": {
"build": {
@@ -24,10 +24,10 @@
}
},
"devDependencies": {
- "@microsoft/api-extractor": "7.39.4",
- "@microsoft/api-documenter": "7.23.20",
- "@microsoft/api-extractor-model": "7.28.7",
+ "@microsoft/api-extractor": "7.42.2",
+ "@microsoft/api-documenter": "7.23.35",
+ "@microsoft/api-extractor-model": "7.28.13",
"@microsoft/tsdoc": "0.14.2",
- "@rushstack/node-core-library": "3.64.2"
+ "@rushstack/node-core-library": "4.0.2"
}
}
diff --git a/remote/test/puppeteer/tools/docgen/tsconfig.json b/remote/test/puppeteer/tools/docgen/tsconfig.json
index fcaf1db737..27d0d84f5d 100644
--- a/remote/test/puppeteer/tools/docgen/tsconfig.json
+++ b/remote/test/puppeteer/tools/docgen/tsconfig.json
@@ -6,6 +6,6 @@
"sourceMap": true,
"declaration": false,
"declarationMap": false,
- "composite": false,
- },
+ "composite": false
+ }
}
diff --git a/remote/test/puppeteer/tools/doctest/package.json b/remote/test/puppeteer/tools/doctest/package.json
index 8c7e9544d0..1d0adb633b 100644
--- a/remote/test/puppeteer/tools/doctest/package.json
+++ b/remote/test/puppeteer/tools/doctest/package.json
@@ -8,7 +8,7 @@
"license": "Apache-2.0",
"scripts": {
"build": "wireit",
- "clean": "../clean.js"
+ "clean": "../clean.mjs"
},
"wireit": {
"build": {
@@ -24,7 +24,7 @@
}
},
"devDependencies": {
- "@swc/core": "1.3.107",
+ "@swc/core": "1.4.2",
"@types/doctrine": "0.0.9",
"@types/source-map-support": "0.5.10",
"@types/yargs": "17.0.32",
diff --git a/remote/test/puppeteer/tools/doctest/tsconfig.json b/remote/test/puppeteer/tools/doctest/tsconfig.json
index bd70c0bd5e..6b8221571b 100644
--- a/remote/test/puppeteer/tools/doctest/tsconfig.json
+++ b/remote/test/puppeteer/tools/doctest/tsconfig.json
@@ -6,6 +6,6 @@
"sourceMap": true,
"declaration": false,
"declarationMap": false,
- "composite": false,
- },
+ "composite": false
+ }
}
diff --git a/remote/test/puppeteer/tools/download_chrome_canary.mjs b/remote/test/puppeteer/tools/download_chrome_canary.mjs
new file mode 100644
index 0000000000..9f523aea2a
--- /dev/null
+++ b/remote/test/puppeteer/tools/download_chrome_canary.mjs
@@ -0,0 +1,51 @@
+/**
+ * @license
+ * Copyright 2024 Google Inc.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/* eslint-disable no-console */
+
+/**
+ * @fileoverview Installs the latest Chrome Canary using
+ * `@puppeteer/browsers` to the directory provided as the first argument
+ * (default: cwd). The executable path is written to the `executablePath` output
+ * param for GitHub actions.
+ *
+ * Examples:
+ *
+ * - `node tools/download_chrome_canary.mjs`
+ * - `node tools/download_chrome_canary.mjs /tmp/cache`
+ */
+import actions from '@actions/core';
+
+import {
+ Browser,
+ computeExecutablePath,
+ install,
+ resolveBuildId,
+ detectBrowserPlatform,
+} from '@puppeteer/browsers';
+
+try {
+ const cacheDir = process.argv[2] || process.cwd();
+ const browser = Browser.CHROME;
+ const platform = detectBrowserPlatform();
+ const buildId = await resolveBuildId(browser, platform, 'canary');
+ await install({
+ browser,
+ buildId,
+ cacheDir,
+ });
+ const executablePath = computeExecutablePath({
+ cacheDir,
+ browser,
+ buildId,
+ });
+ if (process.argv.indexOf('--shell') === -1) {
+ actions.setOutput('executablePath', executablePath);
+ }
+ console.log(executablePath);
+} catch (err) {
+ actions.setFailed(`Failed to download the browser: ${err.message}`);
+}
diff --git a/remote/test/puppeteer/tools/eslint/package.json b/remote/test/puppeteer/tools/eslint/package.json
index 190367ae43..c7f7f4f38d 100644
--- a/remote/test/puppeteer/tools/eslint/package.json
+++ b/remote/test/puppeteer/tools/eslint/package.json
@@ -32,6 +32,7 @@
"author": "The Chromium Authors",
"license": "Apache-2.0",
"devDependencies": {
- "@prettier/sync": "0.5.0"
+ "@prettier/sync": "0.5.1",
+ "@typescript-eslint/utils": "7.1.0"
}
}
diff --git a/remote/test/puppeteer/tools/eslint/src/check-license.ts b/remote/test/puppeteer/tools/eslint/src/check-license.ts
index 7ae1a54384..b8590a7c3f 100644
--- a/remote/test/puppeteer/tools/eslint/src/check-license.ts
+++ b/remote/test/puppeteer/tools/eslint/src/check-license.ts
@@ -11,15 +11,16 @@ const createRule = ESLintUtils.RuleCreator(name => {
return `https://github.com/puppeteer/puppeteer/tree/main/tools/eslint/${name}.ts`;
});
-const copyrightPattern = /Copyright ([0-9]{4}) Google Inc\./;
+const currentYear = new Date().getFullYear();
-// const currentYear = new Date().getFullYear;
-
-// const licenseHeader = `/**
-// * @license
-// * Copyright ${currentYear} Google Inc.
-// * SPDX-License-Identifier: Apache-2.0
-// */`;
+// Needs to start and end with new line
+const licenseHeader = `
+/**
+ * @license
+ * Copyright ${currentYear} Google Inc.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+`;
const enforceLicenseRule = createRule<[], 'licenseRule'>({
name: 'check-license',
@@ -29,7 +30,7 @@ const enforceLicenseRule = createRule<[], 'licenseRule'>({
description: 'Validate existence of license header',
requiresTypeChecking: false,
},
- fixable: undefined, // TODO: change to 'code' once fixer works.
+ fixable: 'code',
schema: [],
messages: {
licenseRule: 'Add license header.',
@@ -39,40 +40,52 @@ const enforceLicenseRule = createRule<[], 'licenseRule'>({
create(context) {
const sourceCode = context.sourceCode;
const comments = sourceCode.getAllComments();
- const header =
- comments[0]?.type === 'Block' && isHeaderComment(comments[0])
- ? comments[0]
- : null;
-
- function isHeaderComment(comment: TSESTree.Comment) {
- if (comment && comment.range[0] >= 0 && comment.range[1] <= 88) {
- return true;
- } else {
- return false;
+ let insertAfter = [0, 0] as TSESTree.Range;
+ let header: TSESTree.Comment | null = null;
+ // Check only the first 2 comments
+ for (let index = 0; index < 2; index++) {
+ const comment = comments[index];
+ if (!comment) {
+ break;
+ }
+ // Shebang comments should be at the top
+ if (
+ // Types don't have it debugger showed it...
+ (comment.type as string) === 'Shebang' ||
+ (comment.type === 'Line' && comment.value.startsWith('#!'))
+ ) {
+ insertAfter = comment.range;
+ continue;
+ }
+ if (comment.type === 'Block') {
+ header = comment;
+ break;
}
}
return {
Program(node) {
+ if (context.filename.endsWith('.json')) {
+ return;
+ }
+
if (
header &&
- header.value.includes('@license') &&
- header.value.includes('SPDX-License-Identifier: Apache-2.0') &&
- copyrightPattern.test(header.value)
+ (header.value.includes('@license') ||
+ header.value.includes('License') ||
+ header.value.includes('Copyright'))
) {
return;
}
// Add header license
if (!header || !header.value.includes('@license')) {
- // const startLoc: [number, number] = [0, 88];
context.report({
node: node,
messageId: 'licenseRule',
- // TODO: fix the fixer.
- // fix(fixer) {
- // return fixer.insertTextBeforeRange(startLoc, licenseHeader);
- // },
+ fix(fixer) {
+ return fixer.insertTextAfterRange(insertAfter, licenseHeader);
+ },
});
}
},
diff --git a/remote/test/puppeteer/tools/eslint/tsconfig.json b/remote/test/puppeteer/tools/eslint/tsconfig.json
index da26cc936b..3a71788a21 100644
--- a/remote/test/puppeteer/tools/eslint/tsconfig.json
+++ b/remote/test/puppeteer/tools/eslint/tsconfig.json
@@ -7,8 +7,7 @@
"outDir": "./lib",
"declaration": false,
"declarationMap": false,
- "sourceMap": false,
"composite": false,
- "removeComments": true,
- },
+ "removeComments": true
+ }
}
diff --git a/remote/test/puppeteer/tools/mocha-runner/package.json b/remote/test/puppeteer/tools/mocha-runner/package.json
index 26612e504a..a817020d5e 100644
--- a/remote/test/puppeteer/tools/mocha-runner/package.json
+++ b/remote/test/puppeteer/tools/mocha-runner/package.json
@@ -9,7 +9,7 @@
"scripts": {
"build": "wireit",
"test": "wireit",
- "clean": "../clean.js"
+ "clean": "../clean.mjs"
},
"wireit": {
"build": {
diff --git a/remote/test/puppeteer/tools/mocha-runner/src/mocha-runner.ts b/remote/test/puppeteer/tools/mocha-runner/src/mocha-runner.ts
index 1707e4cc41..93287abe74 100644
--- a/remote/test/puppeteer/tools/mocha-runner/src/mocha-runner.ts
+++ b/remote/test/puppeteer/tools/mocha-runner/src/mocha-runner.ts
@@ -52,7 +52,7 @@ const {
.scriptName('@puppeteer/mocha-runner')
.option('coverage', {
boolean: true,
- default: true,
+ default: false,
})
.option('suggestions', {
boolean: true,
diff --git a/remote/test/puppeteer/tools/mocha-runner/tsconfig.json b/remote/test/puppeteer/tools/mocha-runner/tsconfig.json
index 73a1b17815..220a467ac1 100644
--- a/remote/test/puppeteer/tools/mocha-runner/tsconfig.json
+++ b/remote/test/puppeteer/tools/mocha-runner/tsconfig.json
@@ -8,6 +8,6 @@
"sourceMap": true,
"declaration": false,
"declarationMap": false,
- "composite": false,
- },
+ "composite": false
+ }
}
diff --git a/remote/test/puppeteer/tools/sort-test-expectations.mjs b/remote/test/puppeteer/tools/sort-test-expectations.mjs
index d1c8588d8a..972d244874 100644
--- a/remote/test/puppeteer/tools/sort-test-expectations.mjs
+++ b/remote/test/puppeteer/tools/sort-test-expectations.mjs
@@ -13,9 +13,22 @@ import prettier from 'prettier';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const source = 'test/TestExpectations.json';
-const testExpectations = JSON.parse(fs.readFileSync(source, 'utf-8'));
+let testExpectations = JSON.parse(fs.readFileSync(source, 'utf-8'));
const committedExpectations = structuredClone(testExpectations);
+function testIdMatchesExpectationPattern(title, pattern) {
+ const patternRegExString = pattern
+ // Replace `*` with non special character
+ .replace(/\*/g, '--STAR--')
+ // Escape special characters https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
+ // Replace placeholder with greedy match
+ .replace(/--STAR--/g, '(.*)?');
+ // Match beginning and end explicitly
+ const patternRegEx = new RegExp(`^${patternRegExString}$`);
+ return patternRegEx.test(title);
+}
+
const prettierConfig = await import(
path.join(__dirname, '..', '.prettierrc.cjs')
);
@@ -43,9 +56,80 @@ testExpectations.forEach(item => {
item.parameters.sort();
item.expectations.sort();
item.platforms.sort();
+ // Delete comments for PASS expectations. They are likely outdated.
+ if (item.expectations.length === 1 && item.expectations[0] === 'PASS') {
+ delete item.comment;
+ }
+});
+
+function isSubset(superset, subset) {
+ let isSubset = true;
+
+ for (const p of subset) {
+ if (!superset.has(p)) {
+ isSubset = false;
+ }
+ }
+
+ return isSubset;
+}
+
+const toBeRemoved = new Set();
+for (let i = testExpectations.length - 1; i >= 0; i--) {
+ const expectation = testExpectations[i];
+ const params = new Set(expectation.parameters);
+ const labels = new Set(expectation.expectations);
+ const platforms = new Set(expectation.platforms);
+
+ let foundMatch = false;
+ for (let j = i - 1; j >= 0; j--) {
+ const candidate = testExpectations[j];
+ const candidateParams = new Set(candidate.parameters);
+ const candidateLabels = new Set(candidate.expectations);
+ const candidatePlatforms = new Set(candidate.platforms);
+
+ if (
+ testIdMatchesExpectationPattern(
+ expectation.testIdPattern,
+ candidate.testIdPattern
+ ) &&
+ isSubset(candidateParams, params) &&
+ isSubset(candidatePlatforms, platforms)
+ ) {
+ foundMatch = true;
+ if (isSubset(candidateLabels, labels)) {
+ console.log('removing', expectation, 'already covered by', candidate);
+ toBeRemoved.add(expectation);
+ }
+ break;
+ }
+ }
+
+ if (!foundMatch && isSubset(new Set(['PASS']), labels)) {
+ console.log(
+ 'removing',
+ expectation,
+ 'because the default expectation is to pass'
+ );
+ toBeRemoved.add(expectation);
+ }
+}
+
+testExpectations = testExpectations.filter(item => {
+ return !toBeRemoved.has(item);
});
if (process.argv.includes('--lint')) {
+ const missingComments = [];
+ testExpectations.forEach(item => {
+ if (item.expectations.length === 1 && item.expectations[0] === 'PASS') {
+ return;
+ }
+ if (!item.comment) {
+ missingComments.push(item);
+ }
+ });
+
if (
JSON.stringify(committedExpectations) !== JSON.stringify(testExpectations)
) {
@@ -54,6 +138,14 @@ if (process.argv.includes('--lint')) {
);
process.exit(1);
}
+
+ if (missingComments.length > 0) {
+ console.error(
+ `${source}: missing comments for the following expectations:`,
+ missingComments
+ );
+ process.exit(1);
+ }
} else {
fs.writeFileSync(
source,
diff --git a/remote/test/puppeteer/tools/tsconfig.json b/remote/test/puppeteer/tools/tsconfig.json
index 964d349435..393392c494 100644
--- a/remote/test/puppeteer/tools/tsconfig.json
+++ b/remote/test/puppeteer/tools/tsconfig.json
@@ -1,4 +1,4 @@
{
"extends": "../tsconfig.base.json",
- "files": ["../package.json"],
+ "files": ["../package.json"]
}