diff --git a/.eleventy.js b/.eleventy.js index 9851a6225..74098f2ef 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,45 +1,44 @@ -const tocPlugin = require('eleventy-plugin-toc'); +const tocPlugin = require("eleventy-plugin-toc"); const markdownIt = require("markdown-it"); const CleanCSS = require("clean-css"); -module.exports = function (eleventyConfig) { - +module.exports = (eleventyConfig) => { eleventyConfig.addPassthroughCopy("docs/assets"); - eleventyConfig.addFilter("cssmin", function(code) { - return new CleanCSS({}).minify(code).styles; - }); + eleventyConfig.addFilter( + "cssmin", + (code) => new CleanCSS({}).minify(code).styles, + ); // This filter is used for deriving the chapter names // from data in chapters.json - eleventyConfig.addFilter('heading', function (str) { - return str.replace(/[_;\\/:*?\"<>|&']/g, " "); - }); + eleventyConfig.addFilter("heading", (str) => + str.replace(/[_;\\/:*?\"<>|&']/g, " "), + ); // Filter for linking to section headers // and displaying chapters in a page - let markdownItAnchor = require("markdown-it-anchor"); - let mdIt = markdownIt({ - html: true, - linkify: true - }) - .use(markdownItAnchor, { - permalink: true, - permalinkBefore: false, - permalinkClass: "direct-link", - permalinkSymbol: "#", - level: [1, 2] - }); - eleventyConfig.addFilter("markdown", function(code) { - if(code) { - return mdIt.render(code); - } + const markdownItAnchor = require("markdown-it-anchor"); + const mdIt = markdownIt({ + html: true, + linkify: true, + }).use(markdownItAnchor, { + permalink: true, + permalinkBefore: false, + permalinkClass: "direct-link", + permalinkSymbol: "#", + level: [1, 2], + }); + eleventyConfig.addFilter("markdown", (code) => { + if (code) { + return mdIt.render(code); + } }); eleventyConfig.setLibrary("md", mdIt); eleventyConfig.addPlugin(tocPlugin); return { dir: { - input: 'docs', - output: 'docs/_site' - } - } -}; \ No newline at end of file + input: "docs", + output: "docs/_site", + }, + }; +}; diff --git a/.github/workflows/taiko.yml b/.github/workflows/taiko.yml index 203953005..ea6a0595a 100644 --- a/.github/workflows/taiko.yml +++ b/.github/workflows/taiko.yml @@ -22,6 +22,10 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node_version }} + - name: Setup Biome + uses: biomejs/setup-biome@v2 + with: + version: latest - name: install run: npm install - name: install browser dependencies @@ -41,7 +45,7 @@ jobs: libasound-dev - name: unit-tests run: | - npm run lint:check + biome ci npm test functional-tests: @@ -139,7 +143,7 @@ jobs: docs-tests: needs: unit-tests - name: Docs tests - ${{ matrix.os }} + name: Docs tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -150,7 +154,6 @@ jobs: - name: install run: npm install - name: install browser dependencies - if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update sudo apt-get install -y \ @@ -171,11 +174,11 @@ jobs: uses: actions/upload-artifact@v1 if: failure() with: - name: docs-tests-reports-${{ matrix.os }} + name: docs-tests-reports path: test/docs-tests/gauge/reports/html-report - name: Upload logs uses: actions/upload-artifact@v1 if: failure() with: - name: docs-tests-logs-${{ matrix.os }} + name: docs-tests-logs path: test/docs-tests/gauge/logs diff --git a/.gitignore b/.gitignore index a51bf744d..ba777996b 100644 --- a/.gitignore +++ b/.gitignore @@ -92,7 +92,6 @@ test-script.js test/docs-tests/tmp/ test/docs-tests/lib/ test/docs-tests/gauge/.vscode -test/docs-tests/gauge/package-lock.json test/docs-tests/gauge/reports/ test/docs-tests/gauge/.gauge/ test/package-lock.json diff --git a/bin/runFile.js b/bin/runFile.js index f7986f380..ece68d717 100644 --- a/bin/runFile.js +++ b/bin/runFile.js @@ -1,21 +1,21 @@ -const path = require('path'); -const util = require('util'); -const recorder = require('../recorder'); +const path = require("node:path"); +const util = require("node:util"); +const recorder = require("../recorder"); -const { removeQuotes } = require('../lib/util'); +const { removeQuotes } = require("../lib/util"); module.exports = async (taiko, file, observe, observeTime, continueRepl) => { const realFuncs = {}; - for (let func in taiko) { + for (const func in taiko) { realFuncs[func] = taiko[func]; - if (realFuncs[func].constructor.name === 'AsyncFunction') { + if (realFuncs[func].constructor.name === "AsyncFunction") { global[func] = async function () { - let res, - args = arguments; - if (func === 'openBrowser' && (observe || continueRepl)) { - if (args['0']) { - args['0'].headless = !observe; + // biome-ignore lint/style/noArguments: Cannot use rest paramaters + let args = arguments; + if (func === "openBrowser" && (observe || continueRepl)) { + if (args["0"]) { + args["0"].headless = !observe; args[0].observe = observe; - args['0'].observeTime = observeTime; + args["0"].observeTime = observeTime; } else if (continueRepl) { args = [ { @@ -35,11 +35,12 @@ module.exports = async (taiko, file, observe, observeTime, continueRepl) => { } } - res = await realFuncs[func].apply(this, args); + const res = await realFuncs[func].apply(this, args); return res; }; - } else if (realFuncs[func].constructor.name === 'Function') { + } else if (realFuncs[func].constructor.name === "Function") { global[func] = function () { + // biome-ignore lint/style/noArguments: Cannot use rest paramaters return realFuncs[func].apply(this, arguments); }; } else { @@ -48,15 +49,20 @@ module.exports = async (taiko, file, observe, observeTime, continueRepl) => { if (continueRepl) { recorder.repl = async () => { console.log( - removeQuotes(util.inspect('Starting REPL..', { colors: true }), 'Starting REPL..'), + removeQuotes( + util.inspect("Starting REPL..", { colors: true }), + "Starting REPL..", + ), ); await continueRepl(file); }; } - require.cache[path.join(__dirname, 'taiko.js')].exports[func] = global[func]; + require.cache[path.join(__dirname, "taiko.js")].exports[func] = + global[func]; } const oldNodeModulesPaths = module.constructor._nodeModulePaths; module.constructor._nodeModulePaths = function () { + // biome-ignore lint/style/noArguments: Cannot use rest paramaters const ret = oldNodeModulesPaths.apply(this, arguments); ret.push(__dirname); ret.push(path.dirname(path.dirname(__dirname))); diff --git a/bin/taiko.js b/bin/taiko.js index cb7a2453d..e06824ee3 100755 --- a/bin/taiko.js +++ b/bin/taiko.js @@ -1,22 +1,22 @@ #! /usr/bin/env node -const runFile = require('./runFile'); -const fs = require('fs'); -const Command = require('commander').Command; -const repl = require('../lib/repl/repl'); -const { isTaikoRunner } = require('../lib/util'); -const devices = require('../lib/data/devices').default; -const NETWORK_TYPES = Object.keys(require('../lib/data/networkConditions')); -const { getExecutablePlugins } = require('../lib/plugins'); +const runFile = require("./runFile"); +const fs = require("node:fs"); +const Command = require("commander").Command; +const repl = require("../lib/repl/repl"); +const { isTaikoRunner } = require("../lib/util"); +const devices = require("../lib/data/devices").default; +const NETWORK_TYPES = Object.keys(require("../lib/data/networkConditions")); +const { getExecutablePlugins } = require("../lib/plugins"); const processArgv = process.argv; let repl_mode = false; let taiko; function printVersion() { try { - const packageJson = require('../package.json'); - let hash = 'RELEASE'; - if (packageJson._resolved && packageJson._resolved.includes('#')) { - hash = packageJson._resolved.split('#')[1]; + const packageJson = require("../package.json"); + let hash = "RELEASE"; + if (packageJson._resolved?.includes("#")) { + hash = packageJson._resolved.split("#")[1]; } const taikoVersion = packageJson.version; @@ -24,7 +24,7 @@ function printVersion() { return `Version: ${taikoVersion} (Chromium: ${browserVersion}) ${hash}`; } catch (error) { - return 'Could not find the package.json file to read version information'; + return "Could not find the package.json file to read version information"; } } @@ -43,26 +43,26 @@ async function exitOnUnhandledFailures(e) { } } -process.on('unhandledRejection', exitOnUnhandledFailures); -process.on('uncaughtException', exitOnUnhandledFailures); +process.on("unhandledRejection", exitOnUnhandledFailures); +process.on("uncaughtException", exitOnUnhandledFailures); function validate(file) { - if (!file.endsWith('.js')) { - console.log('Invalid file extension. Only javascript files are accepted.'); + if (!file.endsWith(".js")) { + console.log("Invalid file extension. Only javascript files are accepted."); process.exit(1); } if (!fs.existsSync(file)) { - console.log('File does not exist.'); + console.log("File does not exist."); process.exit(1); } } function setupEmulateDevice(device) { if (Object.prototype.hasOwnProperty.call(devices, device)) { - process.env['TAIKO_EMULATE_DEVICE'] = device; + process.env.TAIKO_EMULATE_DEVICE = device; } else { console.log(`Invalid value ${device} for --emulate-device`); - console.log(`Available devices: ${Object.keys(devices).join(', ')}`); + console.log(`Available devices: ${Object.keys(devices).join(", ")}`); process.exit(1); } } @@ -75,30 +75,30 @@ function setPluginNameInEnv(pluginName) { function setEmulatedNetwork(networkType) { if (!NETWORK_TYPES.includes(networkType)) { console.log(`Invalid value ${networkType} for --emulate-network`); - console.log(`Available options: ${NETWORK_TYPES.join(', ')}`); + console.log(`Available options: ${NETWORK_TYPES.join(", ")}`); process.exit(1); } process.env.TAIKO_EMULATE_NETWORK = networkType; } function setDisableLogout() { - process.env.TAIKO_ENABLE_ACTION_OUTPUT = 'false'; + process.env.TAIKO_ENABLE_ACTION_OUTPUT = "false"; } function seekingForHelp(args) { - return ['-h', '--help'].some((arg) => args.includes(arg)); + return ["-h", "--help"].some((arg) => args.includes(arg)); } function registerSubcommandForPlugins(program, plugins) { - Object.keys(plugins).forEach((pluginName) => { + for (const pluginName of Object.keys(plugins)) { program .command(`${pluginName} [options...]`) .allowUnknownOption(true) .action((options, cmd) => { - let plugin = require(plugins[cmd.name()]); + const plugin = require(plugins[cmd.name()]); plugin.exec(options); }); - }); + } } function isCLICommand() { @@ -106,44 +106,59 @@ function isCLICommand() { } if (isTaikoRunner(processArgv[1])) { - process.env.TAIKO_ENABLE_ACTION_OUTPUT = process.env.TAIKO_ENABLE_ACTION_OUTPUT || true; - let plugins = getExecutablePlugins(); + process.env.TAIKO_ENABLE_ACTION_OUTPUT = + process.env.TAIKO_ENABLE_ACTION_OUTPUT || true; + const plugins = getExecutablePlugins(); if ( isCLICommand() && - !(seekingForHelp(processArgv) || Object.prototype.hasOwnProperty.call(plugins, processArgv[2])) + !( + seekingForHelp(processArgv) || + Object.prototype.hasOwnProperty.call(plugins, processArgv[2]) + ) ) { // append taiko sub-command as if the user has executed - processArgv.splice(2, 0, 'taiko'); + processArgv.splice(2, 0, "taiko"); } - let program = new Command('taiko'); + const program = new Command("taiko"); program - .arguments(' [fileName]') - .version(printVersion(), '-v, --version') + .arguments(" [fileName]") + .version(printVersion(), "-v, --version") .usage( `[options] taiko [options]`, ) .option( - '-o, --observe', + "-o, --observe", `enables headful mode and runs script with 3000ms delay by default. \t\t\tpass --wait-time option to override the default 3000ms\n`, ) - .option('-l, --load', 'run the given file and start the repl to record further steps.\n') - .option('-w, --wait-time