playwright-test-explorer 0.0.2 → 0.0.5

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.
@@ -857,7 +857,7 @@ async function listTestFile(workspaceFolder = process.cwd(), configFile = "playw
857
857
  try {
858
858
  const output = { projects: (await testServer.listFiles()).projects.map((project) => ({
859
859
  ...project,
860
- files: project.files.map((filePath) => path.relative(workspaceFolder, filePath))
860
+ files: project.files.map((filePath) => path.relative(workspaceFolder, filePath).replace(/\\/g, "/"))
861
861
  })) };
862
862
  const jsonString = JSON.stringify(output, null, 2);
863
863
  if (outputFile) {
@@ -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).replace(/\\/g, "/") : 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).replace(/\\/g, "/"),
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,23 @@ 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).replace(/\\/g, "/");
920
+ if (relativeFile.startsWith(normalizedInputPath + "/") || relativeFile === normalizedInputPath) expandedPaths.push(relativeFile);
921
+ }
922
+ } else expandedPaths.push(relativePath);
923
+ } catch {
924
+ expandedPaths.push(relativePath);
925
+ }
926
+ }
927
+ if (expandedPaths.length > 0) await testServer.listTests(expandedPaths, reporter, token);
905
928
  testServer.close();
906
929
  } catch (error) {
907
930
  console.error("Error:", error);
@@ -918,14 +941,14 @@ async function treeStructure(workspaceFolder = process.cwd(), configFile = "play
918
941
  const node = {
919
942
  type: "suite",
920
943
  title: s.title || "Root",
921
- file: s.location ? path.relative(workspaceFolder, s.location.file) : void 0,
944
+ file: s.location ? path.relative(workspaceFolder, s.location.file).replace(/\\/g, "/") : void 0,
922
945
  children: []
923
946
  };
924
947
  if (s.tests) for (const test of s.tests) node.children.push({
925
948
  type: "test",
926
949
  title: test.title,
927
950
  location: {
928
- file: path.relative(workspaceFolder, test.location.file),
951
+ file: path.relative(workspaceFolder, test.location.file).replace(/\\/g, "/"),
929
952
  line: test.location.line,
930
953
  column: test.location.column
931
954
  },
@@ -951,7 +974,7 @@ async function treeStructure(workspaceFolder = process.cwd(), configFile = "play
951
974
  const allRelativePaths = [];
952
975
  for (const project of files.projects) if (project.files.length > 0) {
953
976
  const relativePaths = project.files.map((absolutePath) => {
954
- return path.relative(workspaceFolder, absolutePath);
977
+ return path.relative(workspaceFolder, absolutePath).replace(/\\/g, "/");
955
978
  });
956
979
  allRelativePaths.push(...relativePaths);
957
980
  }
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-DqaqZS_A.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-DqaqZS_A.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.5",
4
4
  "description": "A CLI tool and library for exploring Playwright tests",
5
5
  "type": "module",
6
6
  "license": "MIT",