muagqa 1.0.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/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # ๐Ÿงช MuagQA CLI
2
+ **Generate, pull, and record Playwright test scripts using one-time session tokens from MuagQA.**
3
+
4
+ MuagQA CLI simplifies automation by allowing testers to:
5
+ - Regenerate test cases in the MuagQA dashboard
6
+ - Receive a **one-time session token**
7
+ - Run: `muagqa pull <token>`
8
+ - Automatically open **Playwright Codegen** for each test case
9
+ - Save recordings into `generated-tests/`
10
+
11
+ ---
12
+
13
+ ## ๐Ÿš€ Installation
14
+
15
+ Install globally:
16
+
17
+ ```bash
18
+ npm install -g muagqa
package/bin/muagqa ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import("../src/index.js");
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "muagqa",
3
+ "version": "1.0.0",
4
+ "description": "MuagQA CLI โ€” Test case runner with one-time session token and Playwright recorder",
5
+ "author": "Mary C.N. Enwezor",
6
+ "license": "MIT",
7
+ "type": "module",
8
+
9
+ "bin": {
10
+ "muagqa": "./bin/muagqa"
11
+ },
12
+
13
+ "dependencies": {
14
+ "axios": "^1.6.0",
15
+ "chalk": "^5.3.0",
16
+ "fs-extra": "^11.2.0",
17
+ "inquirer": "^9.2.7",
18
+ "node-fetch": "^3.3.2",
19
+ "ora": "^7.0.1",
20
+ "playwright": "^1.41.0",
21
+ "yargs": "^17.7.2"
22
+ }
23
+ }
package/src/api.js ADDED
@@ -0,0 +1,15 @@
1
+ import axios from "axios";
2
+ import chalk from "chalk";
3
+
4
+ export async function validateSessionToken(token) {
5
+ try {
6
+ const res = await axios.post("https://muagqa.vercel.app/api/cli/validate", {
7
+ token
8
+ });
9
+
10
+ return res.data;
11
+ } catch (err) {
12
+ console.log(chalk.red("\nโŒ Failed to validate token.\n"));
13
+ throw err;
14
+ }
15
+ }
@@ -0,0 +1,5 @@
1
+ import fs from "fs-extra";
2
+
3
+ export function ensureFolder(path) {
4
+ fs.ensureDirSync(path);
5
+ }
package/src/index.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ import inquirer from "inquirer";
3
+ import chalk from "chalk";
4
+ import run from "./runner.js";
5
+
6
+ console.log(chalk.cyan.bold("\n๐Ÿš€ MuagQA CLI โ€” One-Time Test Case Recorder\n"));
7
+
8
+ async function startCLI() {
9
+ const { token } = await inquirer.prompt([
10
+ {
11
+ type: "input",
12
+ name: "token",
13
+ message: "Enter your one-time session token:",
14
+ validate: v => v.trim() !== "" || "Token is required."
15
+ }
16
+ ]);
17
+
18
+ await run(token);
19
+ }
20
+
21
+ startCLI();
@@ -0,0 +1,19 @@
1
+ import { execSync } from "child_process";
2
+ import chalk from "chalk";
3
+
4
+ export function ensurePlaywrightInstalled() {
5
+ try {
6
+ execSync("npx playwright --version", { stdio: "ignore" });
7
+ return; // Already installed, nothing else to do
8
+ } catch (e) {
9
+ console.log(chalk.yellow("๐Ÿ“ฆ Playwright not detected. Installing browsers..."));
10
+ }
11
+
12
+ try {
13
+ execSync("npx playwright install", { stdio: "inherit" });
14
+ console.log(chalk.green("โœ” Playwright installation complete.\n"));
15
+ } catch (err) {
16
+ console.log(chalk.red("โŒ Failed to install Playwright browsers."));
17
+ throw err;
18
+ }
19
+ }
@@ -0,0 +1,20 @@
1
+ import { exec } from "child_process";
2
+ import chalk from "chalk";
3
+
4
+ export function openCodegenForTest(testCase) {
5
+ return new Promise((resolve) => {
6
+ const outputPath = `./generated-tests/${testCase.id}.spec.ts`;
7
+
8
+ console.log(chalk.cyan(`\nโ–ถ Recording: ${testCase.title}`));
9
+ console.log(chalk.gray(`Description: ${testCase.description}\n`));
10
+
11
+ const cmd = `npx playwright codegen ${testCase.startUrl || ""} --output=${outputPath}`;
12
+
13
+ const child = exec(cmd);
14
+
15
+ child.on("exit", () => {
16
+ console.log(chalk.green(`โœ” Saved recording to ${outputPath}`));
17
+ resolve();
18
+ });
19
+ });
20
+ }
package/src/runner.js ADDED
@@ -0,0 +1,48 @@
1
+ import chalk from "chalk";
2
+ import ora from "ora";
3
+ import { validateSessionToken } from "./api.js";
4
+ import { ensureFolder } from "./fileManager.js";
5
+ import { openCodegenForTest } from "./playwrightRunner.js";
6
+ import { ensurePlaywrightInstalled } from "./playwrightInstaller.js";
7
+
8
+
9
+ export default async function run(token) {
10
+ const spinner = ora("Validating token...").start();
11
+
12
+ try {
13
+ const result = await validateSessionToken(token);
14
+
15
+ if (!result.success) {
16
+ spinner.fail("Invalid token.");
17
+ console.log(chalk.red(`\nโŒ ${result.error}\n`));
18
+ return;
19
+ }
20
+
21
+ spinner.succeed("Token valid!");
22
+
23
+ const { testCases } = result;
24
+
25
+ if (!testCases || testCases.length === 0) {
26
+ console.log(chalk.red("\nโš  No test cases found.\n"));
27
+ return;
28
+ }
29
+
30
+ console.log(chalk.green(`\n๐Ÿ“Œ ${testCases.length} test cases found.\n`));
31
+
32
+ await ensurePlaywrightInstalled();
33
+
34
+ ensureFolder("./generated-tests");
35
+
36
+ // sequentially open codegen for each test
37
+ for (const testCase of testCases) {
38
+ await openCodegenForTest(testCase);
39
+ }
40
+
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
+
44
+ } catch (err) {
45
+ spinner.fail("An error occurred.");
46
+ console.error(err);
47
+ }
48
+ }
File without changes