muagqa 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muagqa",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "MuagQA CLI — Test case runner with one-time session token and Playwright recorder",
5
5
  "author": "Mary C.N. Enwezor",
6
6
  "license": "MIT",
@@ -9,6 +9,9 @@
9
9
  "bin": {
10
10
  "muagqa": "./bin/muagqa"
11
11
  },
12
+ "scripts": {
13
+ "postinstall": "node ./src/postinstall.js"
14
+ },
12
15
 
13
16
  "dependencies": {
14
17
  "axios": "^1.6.0",
package/src/index.js CHANGED
@@ -1,11 +1,55 @@
1
1
  #!/usr/bin/env node
2
+ import { exec } from "child_process";
3
+ import { createRequire } from "module";
4
+ import { promisify } from "util";
2
5
  import inquirer from "inquirer";
3
6
  import chalk from "chalk";
4
7
  import run from "./runner.js";
5
8
 
6
- console.log(chalk.cyan.bold("\nšŸš€ MuagQA CLI — One-Time Test Case Recorder\n"));
9
+ const execAsync = promisify(exec);
10
+ const require = createRequire(import.meta.url);
11
+ const pkg = require("../package.json");
12
+
13
+ console.log(chalk.cyan.bold("\nMuagQA CLI - One-Time Test Case Recorder\n"));
14
+
15
+ async function checkForUpdate({ force = false } = {}) {
16
+ try {
17
+ const { stdout } = await execAsync("npm view muagqa version", {
18
+ timeout: 4000
19
+ });
20
+ const latest = stdout.trim();
21
+ if (!latest) {
22
+ return;
23
+ }
24
+ if (latest !== pkg.version) {
25
+ console.log(chalk.yellow(`Update available: v${latest} (installed v${pkg.version}).`));
26
+ console.log(chalk.gray("Run: npm install -g muagqa@latest\n"));
27
+ } else if (force) {
28
+ console.log(chalk.green(`MuagQA is up to date (v${pkg.version}).`));
29
+ }
30
+ } catch (err) {
31
+ if (force) {
32
+ console.log(chalk.red("Unable to check for updates right now."));
33
+ }
34
+ }
35
+ }
7
36
 
8
37
  async function startCLI() {
38
+ const args = new Set(process.argv.slice(2));
39
+
40
+ if (args.has("--version") || args.has("-v")) {
41
+ console.log(`muagqa v${pkg.version}`);
42
+ return;
43
+ }
44
+
45
+ if (args.has("--check-update")) {
46
+ await checkForUpdate({ force: true });
47
+ return;
48
+ }
49
+
50
+ // Fire-and-forget update check to avoid slowing down the prompt.
51
+ checkForUpdate();
52
+
9
53
  const { token } = await inquirer.prompt([
10
54
  {
11
55
  type: "input",
@@ -0,0 +1,15 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { createRequire } from "module";
4
+
5
+ const require = createRequire(import.meta.url);
6
+
7
+ export function getPlaywrightCliPath() {
8
+ try {
9
+ const pkgPath = require.resolve("playwright/package.json");
10
+ const cliPath = path.join(path.dirname(pkgPath), "cli.js");
11
+ return fs.existsSync(cliPath) ? cliPath : null;
12
+ } catch {
13
+ return null;
14
+ }
15
+ }
@@ -1,36 +1,30 @@
1
- import { execSync } from "child_process";
2
- import path from "path";
3
- import chalk from "chalk";
4
-
5
- export function ensurePlaywrightInstalled() {
6
- try {
7
- console.log(chalk.cyan("šŸ” Checking Playwright installation..."));
8
-
9
- // Try running playwright --version
10
- execSync("npx playwright --version", { stdio: "ignore" });
11
-
12
- console.log(chalk.green("āœ” Playwright is already installed globally."));
13
- return true;
14
- } catch (err) {
15
- console.log(chalk.yellow("⚠ Playwright not found globally. Installing..."));
16
- }
17
-
18
- try {
19
- // 1ļøāƒ£ Determine global CLI install folder
20
- const globalRoot = execSync("npm root -g").toString().trim();
21
-
22
- const cliPath = path.join(globalRoot, "muagqa");
23
-
24
- console.log(chalk.cyan(`šŸ“‚ Installing Playwright inside: ${cliPath}`));
25
-
26
- // 2ļøāƒ£ Install Playwright inside the global muagqa folder
27
- execSync(`cd "${cliPath}" && npm install playwright`, { stdio: "inherit" });
28
-
29
- console.log(chalk.green("āœ” Playwright installed successfully!"));
30
- return true;
31
- } catch (e) {
32
- console.log(chalk.red("āŒ Failed to install Playwright globally."));
33
- console.error(e);
34
- return false;
35
- }
36
- }
1
+ import { execSync } from "child_process";
2
+ import chalk from "chalk";
3
+ import { getPlaywrightCliPath } from "./playwrightCli.js";
4
+
5
+ export function ensurePlaywrightInstalled() {
6
+ try {
7
+ const cliPath = getPlaywrightCliPath();
8
+ if (!cliPath) {
9
+ console.log(chalk.red("Playwright CLI not found. Please reinstall the package."));
10
+ return false;
11
+ }
12
+
13
+ if (process.env.PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD === "1") {
14
+ console.log(chalk.yellow("Skipping Playwright browser download (env set)."));
15
+ return true;
16
+ }
17
+
18
+ console.log(chalk.cyan("Ensuring Playwright Chrome browser is installed..."));
19
+ execSync(`"${process.execPath}" "${cliPath}" install chrome`, {
20
+ stdio: "inherit"
21
+ });
22
+
23
+ console.log(chalk.green("Playwright browser install complete."));
24
+ return true;
25
+ } catch (err) {
26
+ console.log(chalk.red("Failed to ensure Playwright browsers are installed."));
27
+ console.error(err);
28
+ return false;
29
+ }
30
+ }
@@ -1,19 +1,41 @@
1
- import { exec } from "child_process";
1
+ import { spawn } from "child_process";
2
2
  import chalk from "chalk";
3
+ import { getPlaywrightCliPath } from "./playwrightCli.js";
3
4
 
4
5
  export function openCodegenForTest(testCase) {
5
6
  return new Promise((resolve) => {
6
7
  const outputPath = `./generated-tests/${testCase.id}.spec.ts`;
7
8
 
8
- console.log(chalk.cyan(`\nā–¶ Recording: ${testCase.title}`));
9
+ console.log(chalk.cyan(`\nRecording: ${testCase.title}`));
9
10
  console.log(chalk.gray(`Description: ${testCase.description}\n`));
10
11
 
11
- const cmd = `npx playwright codegen ${testCase.startUrl || ""} --output=${outputPath}`;
12
+ const cliPath = getPlaywrightCliPath();
13
+ if (!cliPath) {
14
+ console.log(chalk.red("Playwright CLI not found. Please reinstall the package."));
15
+ resolve();
16
+ return;
17
+ }
18
+
19
+ const args = [cliPath, "codegen"];
20
+ if (testCase.startUrl) {
21
+ args.push(testCase.startUrl);
22
+ }
23
+ args.push(`--output=${outputPath}`, "--channel=chrome");
24
+
25
+ const child = spawn(process.execPath, args, { stdio: "inherit" });
12
26
 
13
- const child = exec(cmd);
27
+ child.on("error", (err) => {
28
+ console.log(chalk.red("Failed to start Playwright codegen."));
29
+ console.error(err);
30
+ resolve();
31
+ });
14
32
 
15
- child.on("exit", () => {
16
- console.log(chalk.green(`āœ” Saved recording to ${outputPath}`));
33
+ child.on("exit", (code) => {
34
+ if (code === 0) {
35
+ console.log(chalk.green(`Saved recording to ${outputPath}`));
36
+ } else {
37
+ console.log(chalk.red(`Playwright codegen exited with code ${code}.`));
38
+ }
17
39
  resolve();
18
40
  });
19
41
  });
@@ -0,0 +1,31 @@
1
+ import { execSync } from "child_process";
2
+ import chalk from "chalk";
3
+ import { getPlaywrightCliPath } from "./playwrightCli.js";
4
+
5
+ function shouldSkip() {
6
+ return process.env.PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD === "1";
7
+ }
8
+
9
+ function installChrome() {
10
+ const cliPath = getPlaywrightCliPath();
11
+ if (!cliPath) {
12
+ console.log(chalk.red("Playwright CLI not found; skipping browser install."));
13
+ return;
14
+ }
15
+
16
+ console.log(chalk.cyan("Installing Playwright Chrome browser..."));
17
+ execSync(`"${process.execPath}" "${cliPath}" install chrome`, {
18
+ stdio: "inherit"
19
+ });
20
+ }
21
+
22
+ try {
23
+ if (shouldSkip()) {
24
+ console.log(chalk.yellow("Skipping Playwright browser download (env set)."));
25
+ } else {
26
+ installChrome();
27
+ }
28
+ } catch (err) {
29
+ console.log(chalk.red("Failed to install Playwright browsers."));
30
+ console.error(err);
31
+ }
package/src/runner.js CHANGED
@@ -5,7 +5,6 @@ import { ensureFolder } from "./fileManager.js";
5
5
  import { openCodegenForTest } from "./playwrightRunner.js";
6
6
  import { ensurePlaywrightInstalled } from "./playwrightInstaller.js";
7
7
 
8
-
9
8
  export default async function run(token) {
10
9
  const spinner = ora("Validating token...").start();
11
10
 
@@ -14,7 +13,7 @@ export default async function run(token) {
14
13
 
15
14
  if (!result.success) {
16
15
  spinner.fail("Invalid token.");
17
- console.log(chalk.red(`\nāŒ ${result.error}\n`));
16
+ console.log(chalk.red(`\n${result.error}\n`));
18
17
  return;
19
18
  }
20
19
 
@@ -23,24 +22,25 @@ export default async function run(token) {
23
22
  const { testCases } = result;
24
23
 
25
24
  if (!testCases || testCases.length === 0) {
26
- console.log(chalk.red("\n⚠ No test cases found.\n"));
25
+ console.log(chalk.red("\nNo test cases found.\n"));
27
26
  return;
28
27
  }
29
28
 
30
- console.log(chalk.green(`\nšŸ“Œ ${testCases.length} test cases found.\n`));
29
+ console.log(chalk.green(`\n${testCases.length} test cases found.\n`));
31
30
 
32
- await ensurePlaywrightInstalled();
31
+ const ok = ensurePlaywrightInstalled();
32
+ if (!ok) {
33
+ return;
34
+ }
33
35
 
34
36
  ensureFolder("./generated-tests");
35
37
 
36
- // sequentially open codegen for each test
37
38
  for (const testCase of testCases) {
38
39
  await openCodegenForTest(testCase);
39
40
  }
40
41
 
41
- console.log(chalk.green.bold("\nšŸŽ‰ All test cases recorded successfully!\n"));
42
- console.log(chalk.yellow("⚠ Token has now expired. Generate a new one for the next session.\n"));
43
-
42
+ console.log(chalk.green.bold("\nAll test cases recorded successfully!\n"));
43
+ console.log(chalk.yellow("Token has now expired. Generate a new one for the next session.\n"));
44
44
  } catch (err) {
45
45
  spinner.fail("An error occurred.");
46
46
  console.error(err);