playwright-test-explorer 0.0.1 → 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.
@@ -855,7 +855,10 @@ async function listTestFile(workspaceFolder = process.cwd(), configFile = "playw
855
855
  configFile: path.join(workspaceFolder, configFile)
856
856
  });
857
857
  try {
858
- const output = { projects: (await testServer.listFiles()).projects };
858
+ const output = { projects: (await testServer.listFiles()).projects.map((project) => ({
859
+ ...project,
860
+ files: project.files.map((filePath) => path.relative(workspaceFolder, filePath))
861
+ })) };
859
862
  const jsonString = JSON.stringify(output, null, 2);
860
863
  if (outputFile) {
861
864
  await fs.writeFile(outputFile, jsonString, "utf-8");
@@ -873,24 +876,31 @@ async function listTestCase(workspaceFolder = process.cwd(), configFile = "playw
873
876
  configFile: path.join(workspaceFolder, configFile)
874
877
  });
875
878
  const reporter = { async onBegin(suite) {
876
- const tests = [];
877
- function walkSuite(s) {
878
- 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",
879
888
  title: test.title,
880
- file: test.location.file,
881
- line: test.location.line,
882
- 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
+ },
883
894
  tags: test.tags || [],
884
895
  annotations: test.annotations || [],
885
896
  expectedStatus: test.expectedStatus,
886
- timeout: test.timeout,
887
- titlePath: test.titlePath()
897
+ timeout: test.timeout
888
898
  });
889
- 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;
890
901
  }
891
- walkSuite(suite);
892
- const output = { tests };
893
- const jsonString = JSON.stringify(output, null, 2);
902
+ const tree = buildTree(suite);
903
+ const jsonString = JSON.stringify(tree, null, 2);
894
904
  if (outputFile) {
895
905
  await fs.writeFile(outputFile, jsonString, "utf-8");
896
906
  console.log(`Results saved to: ${outputFile}`);
@@ -898,7 +908,24 @@ async function listTestCase(workspaceFolder = process.cwd(), configFile = "playw
898
908
  } };
899
909
  try {
900
910
  const token = new CancellationToken();
901
- 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);
902
929
  testServer.close();
903
930
  } catch (error) {
904
931
  console.error("Error:", error);
@@ -915,14 +942,14 @@ async function treeStructure(workspaceFolder = process.cwd(), configFile = "play
915
942
  const node = {
916
943
  type: "suite",
917
944
  title: s.title || "Root",
918
- file: s.location ? s.location.file : void 0,
945
+ file: s.location ? path.relative(workspaceFolder, s.location.file) : void 0,
919
946
  children: []
920
947
  };
921
948
  if (s.tests) for (const test of s.tests) node.children.push({
922
949
  type: "test",
923
950
  title: test.title,
924
951
  location: {
925
- file: test.location.file,
952
+ file: path.relative(workspaceFolder, test.location.file),
926
953
  line: test.location.line,
927
954
  column: test.location.column
928
955
  },
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-DuYXKbq5.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-DuYXKbq5.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.1",
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",