playwright-test-explorer 0.0.2 → 0.0.3

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.
@@ -876,24 +876,31 @@ async function listTestCase(workspaceFolder = process.cwd(), configFile = "playw
876
876
  configFile: path.join(workspaceFolder, configFile)
877
877
  });
878
878
  const reporter = { async onBegin(suite) {
879
- const tests = [];
880
- function walkSuite(s) {
881
- if (s.tests) for (const test of s.tests) tests.push({
879
+ function buildTree(s) {
880
+ const node = {
881
+ type: "suite",
882
+ title: s.title || "Root",
883
+ file: s.location ? path.relative(workspaceFolder, s.location.file) : void 0,
884
+ children: []
885
+ };
886
+ if (s.tests) for (const test of s.tests) node.children.push({
887
+ type: "test",
882
888
  title: test.title,
883
- file: path.relative(workspaceFolder, test.location.file),
884
- line: test.location.line,
885
- column: test.location.column,
889
+ location: {
890
+ file: path.relative(workspaceFolder, test.location.file),
891
+ line: test.location.line,
892
+ column: test.location.column
893
+ },
886
894
  tags: test.tags || [],
887
895
  annotations: test.annotations || [],
888
896
  expectedStatus: test.expectedStatus,
889
- timeout: test.timeout,
890
- titlePath: test.titlePath()
897
+ timeout: test.timeout
891
898
  });
892
- if (s.suites) for (const child of s.suites) walkSuite(child);
899
+ if (s.suites) for (const child of s.suites) node.children.push(buildTree(child));
900
+ return node;
893
901
  }
894
- walkSuite(suite);
895
- const output = { tests };
896
- const jsonString = JSON.stringify(output, null, 2);
902
+ const tree = buildTree(suite);
903
+ const jsonString = JSON.stringify(tree, null, 2);
897
904
  if (outputFile) {
898
905
  await fs.writeFile(outputFile, jsonString, "utf-8");
899
906
  console.log(`Results saved to: ${outputFile}`);
@@ -901,7 +908,24 @@ async function listTestCase(workspaceFolder = process.cwd(), configFile = "playw
901
908
  } };
902
909
  try {
903
910
  const token = new CancellationToken();
904
- if (relativePaths.length > 0) await testServer.listTests(relativePaths, reporter, token);
911
+ const expandedPaths = [];
912
+ for (const relativePath of relativePaths) {
913
+ const normalizedInputPath = relativePath.replace(/\\/g, "/").replace(/\/$/, "");
914
+ const absolutePath = path.join(workspaceFolder, relativePath);
915
+ try {
916
+ if ((await fs.stat(absolutePath)).isDirectory()) {
917
+ const files = await testServer.listFiles();
918
+ for (const project of files.projects) for (const file of project.files) {
919
+ const relativeFile = path.relative(workspaceFolder, file);
920
+ const normalizedFile = relativeFile.replace(/\\/g, "/");
921
+ if (normalizedFile.startsWith(normalizedInputPath + "/") || normalizedFile === normalizedInputPath) expandedPaths.push(relativeFile);
922
+ }
923
+ } else expandedPaths.push(relativePath);
924
+ } catch {
925
+ expandedPaths.push(relativePath);
926
+ }
927
+ }
928
+ if (expandedPaths.length > 0) await testServer.listTests(expandedPaths, reporter, token);
905
929
  testServer.close();
906
930
  } catch (error) {
907
931
  console.error("Error:", error);
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as CancellationToken, n as listTestFile, r as treeStructure, t as listTestCase } from "./api-Dpe-8gQe.js";
2
+ import { i as CancellationToken, n as listTestFile, r as treeStructure, t as listTestCase } from "./api-CyzEW-tV.js";
3
3
  import { program } from "commander";
4
4
  import chalk from "chalk";
5
5
  import ora from "ora";
@@ -20,9 +20,9 @@ program.command("list-files").description("List all test files in the Playwright
20
20
  process.exit(1);
21
21
  }
22
22
  });
23
- program.command("list-tests").description("List all test cases in specified files").option("-w, --workspace <path>", "workspace folder path", process.cwd()).option("-c, --config <file>", "config file path (relative to workspace)", "playwright.config.ts").option("-f, --files <files...>", "test file paths (relative to workspace)", []).option("-o, --output <file>", "output file path to save JSON results").action(async (options) => {
23
+ program.command("list-tests").description("List all test cases in specified files or directories").option("-w, --workspace <path>", "workspace folder path", process.cwd()).option("-c, --config <file>", "config file path (relative to workspace)", "playwright.config.ts").option("-f, --files <files...>", "test file or directory paths (relative to workspace)", []).option("-o, --output <file>", "output file path to save JSON results").action(async (options) => {
24
24
  if (!options.files || options.files.length === 0) {
25
- console.error(chalk.red("Error: Please specify at least one test file using -f or --files"));
25
+ console.error(chalk.red("Error: Please specify at least one test file or directory using -f or --files"));
26
26
  process.exit(1);
27
27
  }
28
28
  const spinner = ora("Loading test cases...").start();
@@ -71,6 +71,12 @@ ${chalk.bold("Examples:")}
71
71
  ${chalk.cyan("# List test cases in specific files")}
72
72
  $ pw-test-explorer list-tests -f tests/example.spec.ts tests/another.spec.ts
73
73
 
74
+ ${chalk.cyan("# List test cases in a directory")}
75
+ $ pw-test-explorer list-tests -f tests/
76
+
77
+ ${chalk.cyan("# List test cases in multiple files and directories")}
78
+ $ pw-test-explorer list-tests -f tests/auth/ tests/api/login.spec.ts
79
+
74
80
  ${chalk.cyan("# Save test cases to JSON file")}
75
81
  $ pw-test-explorer list-tests -f tests/example.spec.ts -o tests.json
76
82
 
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as listTestFile, r as treeStructure, t as listTestCase } from "./api-Dpe-8gQe.js";
1
+ import { n as listTestFile, r as treeStructure, t as listTestCase } from "./api-CyzEW-tV.js";
2
2
 
3
3
  export { listTestCase, listTestFile, treeStructure };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-test-explorer",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A CLI tool and library for exploring Playwright tests",
5
5
  "type": "module",
6
6
  "license": "MIT",