playwright-test-explorer 0.0.5 → 0.0.7

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.
@@ -722,6 +722,18 @@ var PlaywrightTestServer = class {
722
722
  for (const message of report) teleReceiver.dispatch(message);
723
723
  return result;
724
724
  }
725
+ /**
726
+ * Get raw test report without processing through TeleReporterReceiver
727
+ * This preserves the complete test.describe hierarchy
728
+ */
729
+ async getRawTestReport(locations, token) {
730
+ const { connection } = await this._testServer();
731
+ if (token?.isCancellationRequested) return [];
732
+ if (!connection) return [];
733
+ const escapedLocations = locations.map(escapeRegex);
734
+ const { report } = await connection.listTests({ locations: escapedLocations });
735
+ return report;
736
+ }
725
737
  async listTests(locations, reporter, token) {
726
738
  const { connection } = await this._testServer();
727
739
  if (token?.isCancellationRequested) return;
@@ -875,37 +887,6 @@ async function listTestCase(workspaceFolder = process.cwd(), configFile = "playw
875
887
  workspaceFolder,
876
888
  configFile: path.join(workspaceFolder, configFile)
877
889
  });
878
- const reporter = { async onBegin(suite) {
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",
888
- title: test.title,
889
- location: {
890
- file: path.relative(workspaceFolder, test.location.file).replace(/\\/g, "/"),
891
- line: test.location.line,
892
- column: test.location.column
893
- },
894
- tags: test.tags || [],
895
- annotations: test.annotations || [],
896
- expectedStatus: test.expectedStatus,
897
- timeout: test.timeout
898
- });
899
- if (s.suites) for (const child of s.suites) node.children.push(buildTree(child));
900
- return node;
901
- }
902
- const tree = buildTree(suite);
903
- const jsonString = JSON.stringify(tree, null, 2);
904
- if (outputFile) {
905
- await fs.writeFile(outputFile, jsonString, "utf-8");
906
- console.log(`Results saved to: ${outputFile}`);
907
- } else console.log(jsonString);
908
- } };
909
890
  try {
910
891
  const token = new CancellationToken();
911
892
  const expandedPaths = [];
@@ -924,7 +905,70 @@ async function listTestCase(workspaceFolder = process.cwd(), configFile = "playw
924
905
  expandedPaths.push(relativePath);
925
906
  }
926
907
  }
927
- if (expandedPaths.length > 0) await testServer.listTests(expandedPaths, reporter, token);
908
+ if (expandedPaths.length === 0) {
909
+ testServer.close();
910
+ return;
911
+ }
912
+ const report = await testServer.getRawTestReport(expandedPaths, token);
913
+ function parseEntry(entry, testDir) {
914
+ if (entry.testId) {
915
+ const filePath = testDir ? path.join(testDir, entry.location.file).replace(/\\/g, "/") : entry.location.file.replace(/\\/g, "/");
916
+ return {
917
+ type: "test",
918
+ title: entry.title,
919
+ testId: entry.testId,
920
+ location: {
921
+ file: filePath,
922
+ line: entry.location.line,
923
+ column: entry.location.column
924
+ },
925
+ tags: entry.tags || [],
926
+ annotations: entry.annotations || [],
927
+ expectedStatus: "passed",
928
+ timeout: 0
929
+ };
930
+ } else {
931
+ const filePath = entry.location && testDir ? path.join(testDir, entry.location.file).replace(/\\/g, "/") : entry.location?.file.replace(/\\/g, "/");
932
+ const node = {
933
+ type: "suite",
934
+ title: entry.title,
935
+ file: filePath,
936
+ children: []
937
+ };
938
+ if (entry.entries && Array.isArray(entry.entries)) for (const childEntry of entry.entries) node.children.push(parseEntry(childEntry, testDir));
939
+ return node;
940
+ }
941
+ }
942
+ const rootNode = {
943
+ type: "suite",
944
+ title: "Root",
945
+ children: []
946
+ };
947
+ let rootDir = "";
948
+ for (const message of report) if (message.method === "onConfigure") {
949
+ rootDir = message.params.config.rootDir || "";
950
+ break;
951
+ }
952
+ for (const message of report) if (message.method === "onProject") {
953
+ const project = message.params.project;
954
+ const projectNode = {
955
+ type: "suite",
956
+ title: project.name,
957
+ children: []
958
+ };
959
+ const relativeRootDir = rootDir ? path.relative(workspaceFolder, rootDir).replace(/\\/g, "/") : "";
960
+ const testDir = project.testDir ? path.join(relativeRootDir, project.testDir).replace(/\\/g, "/") : relativeRootDir;
961
+ if (project.suites && Array.isArray(project.suites)) for (const suite of project.suites) {
962
+ const suiteNode = parseEntry(suite, testDir);
963
+ projectNode.children.push(suiteNode);
964
+ }
965
+ rootNode.children.push(projectNode);
966
+ }
967
+ const jsonString = JSON.stringify(rootNode, null, 2);
968
+ if (outputFile) {
969
+ await fs.writeFile(outputFile, jsonString, "utf-8");
970
+ console.log(`Results saved to: ${outputFile}`);
971
+ } else console.log(jsonString);
928
972
  testServer.close();
929
973
  } catch (error) {
930
974
  console.error("Error:", error);
@@ -936,50 +980,84 @@ async function treeStructure(workspaceFolder = process.cwd(), configFile = "play
936
980
  workspaceFolder,
937
981
  configFile: path.join(workspaceFolder, configFile)
938
982
  });
939
- const reporter = { async onBegin(suite) {
940
- function buildTree(s) {
941
- const node = {
983
+ try {
984
+ const token = cancellationToken || new CancellationToken();
985
+ const files = await testServer.listFiles();
986
+ if (files.projects.length === 0) {
987
+ testServer.close();
988
+ return;
989
+ }
990
+ const allRelativePaths = [];
991
+ for (const project of files.projects) if (project.files.length > 0) {
992
+ const relativePaths = project.files.map((absolutePath) => {
993
+ return path.relative(workspaceFolder, absolutePath).replace(/\\/g, "/");
994
+ });
995
+ allRelativePaths.push(...relativePaths);
996
+ }
997
+ if (allRelativePaths.length === 0) {
998
+ testServer.close();
999
+ return;
1000
+ }
1001
+ const report = await testServer.getRawTestReport(allRelativePaths, token);
1002
+ function parseEntry(entry, testDir) {
1003
+ if (entry.testId) {
1004
+ const filePath = testDir ? path.join(testDir, entry.location.file).replace(/\\/g, "/") : entry.location.file.replace(/\\/g, "/");
1005
+ return {
1006
+ type: "test",
1007
+ title: entry.title,
1008
+ testId: entry.testId,
1009
+ location: {
1010
+ file: filePath,
1011
+ line: entry.location.line,
1012
+ column: entry.location.column
1013
+ },
1014
+ tags: entry.tags || [],
1015
+ annotations: entry.annotations || [],
1016
+ expectedStatus: "passed",
1017
+ timeout: 0
1018
+ };
1019
+ } else {
1020
+ const filePath = entry.location && testDir ? path.join(testDir, entry.location.file).replace(/\\/g, "/") : entry.location?.file.replace(/\\/g, "/");
1021
+ const node = {
1022
+ type: "suite",
1023
+ title: entry.title,
1024
+ file: filePath,
1025
+ children: []
1026
+ };
1027
+ if (entry.entries && Array.isArray(entry.entries)) for (const childEntry of entry.entries) node.children.push(parseEntry(childEntry, testDir));
1028
+ return node;
1029
+ }
1030
+ }
1031
+ const rootNode = {
1032
+ type: "suite",
1033
+ title: "Root",
1034
+ children: []
1035
+ };
1036
+ let rootDir = "";
1037
+ for (const message of report) if (message.method === "onConfigure") {
1038
+ rootDir = message.params.config.rootDir || "";
1039
+ break;
1040
+ }
1041
+ for (const message of report) if (message.method === "onProject") {
1042
+ const project = message.params.project;
1043
+ const projectNode = {
942
1044
  type: "suite",
943
- title: s.title || "Root",
944
- file: s.location ? path.relative(workspaceFolder, s.location.file).replace(/\\/g, "/") : void 0,
1045
+ title: project.name,
945
1046
  children: []
946
1047
  };
947
- if (s.tests) for (const test of s.tests) node.children.push({
948
- type: "test",
949
- title: test.title,
950
- location: {
951
- file: path.relative(workspaceFolder, test.location.file).replace(/\\/g, "/"),
952
- line: test.location.line,
953
- column: test.location.column
954
- },
955
- tags: test.tags || [],
956
- annotations: test.annotations || [],
957
- expectedStatus: test.expectedStatus,
958
- timeout: test.timeout
959
- });
960
- if (s.suites) for (const child of s.suites) node.children.push(buildTree(child));
961
- return node;
1048
+ const relativeRootDir = rootDir ? path.relative(workspaceFolder, rootDir).replace(/\\/g, "/") : "";
1049
+ const testDir = project.testDir ? path.join(relativeRootDir, project.testDir).replace(/\\/g, "/") : relativeRootDir;
1050
+ if (project.suites && Array.isArray(project.suites)) for (const suite of project.suites) {
1051
+ const suiteNode = parseEntry(suite, testDir);
1052
+ projectNode.children.push(suiteNode);
1053
+ }
1054
+ rootNode.children.push(projectNode);
962
1055
  }
963
- const tree = buildTree(suite);
964
- const jsonString = JSON.stringify(tree, null, 2);
1056
+ const jsonString = JSON.stringify(rootNode, null, 2);
965
1057
  if (outputFile) {
966
1058
  await fs.writeFile(outputFile, jsonString, "utf-8");
967
1059
  console.log(`Results saved to: ${outputFile}`);
968
1060
  } else console.log(jsonString);
969
- } };
970
- try {
971
- const token = cancellationToken || new CancellationToken();
972
- const files = await testServer.listFiles();
973
- if (files.projects.length > 0) {
974
- const allRelativePaths = [];
975
- for (const project of files.projects) if (project.files.length > 0) {
976
- const relativePaths = project.files.map((absolutePath) => {
977
- return path.relative(workspaceFolder, absolutePath).replace(/\\/g, "/");
978
- });
979
- allRelativePaths.push(...relativePaths);
980
- }
981
- if (allRelativePaths.length > 0) await testServer.listTests(allRelativePaths, reporter, token);
982
- }
983
1061
  testServer.close();
984
1062
  } catch (error) {
985
1063
  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-DqaqZS_A.js";
2
+ import { i as CancellationToken, n as listTestFile, r as treeStructure, t as listTestCase } from "./api-JooYjXT5.js";
3
3
  import { program } from "commander";
4
4
  import chalk from "chalk";
5
5
  import ora from "ora";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as listTestFile, r as treeStructure, t as listTestCase } from "./api-DqaqZS_A.js";
1
+ import { n as listTestFile, r as treeStructure, t as listTestCase } from "./api-JooYjXT5.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.5",
3
+ "version": "0.0.7",
4
4
  "description": "A CLI tool and library for exploring Playwright tests",
5
5
  "type": "module",
6
6
  "license": "MIT",