@iamsergio/qttest-utils 0.4.0 → 0.4.1

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/out/qttest.d.ts CHANGED
@@ -4,8 +4,9 @@
4
4
  */
5
5
  export declare class QtTest {
6
6
  readonly filename: string;
7
+ readonly buildDirPath: string;
7
8
  slots: QtTestSlot[] | null;
8
- constructor(filename: string);
9
+ constructor(filename: string, buildDirPath: string);
9
10
  get id(): string;
10
11
  get label(): string;
11
12
  /**
@@ -21,7 +22,7 @@ export declare class QtTest {
21
22
  */
22
23
  linksToQtTestLib(): Promise<boolean> | undefined;
23
24
  isQtTestViaHelp(): Promise<boolean | undefined>;
24
- runTest(slotName?: string): Promise<boolean>;
25
+ runTest(slotName?: string, cwd?: string): Promise<boolean>;
25
26
  command(): {
26
27
  label: string;
27
28
  executablePath: string;
package/out/qttest.js CHANGED
@@ -2,6 +2,29 @@
2
2
  // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3
3
  // Author: Sergio Martins <sergio.martins@kdab.com>
4
4
  // SPDX-License-Identifier: MIT
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
5
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,15 +41,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
41
  exports.QtTests = exports.QtTestSlot = exports.QtTest = void 0;
19
42
  const child_process_1 = require("child_process");
20
43
  const path_1 = __importDefault(require("path"));
44
+ const fs = __importStar(require("fs"));
21
45
  const cmake_1 = require("./cmake");
22
46
  /**
23
47
  * Represents a single QtTest executable.
24
48
  * Supports listing the individual test slots
25
49
  */
26
50
  class QtTest {
27
- constructor(filename) {
51
+ constructor(filename, buildDirPath) {
28
52
  this.slots = null;
29
53
  this.filename = filename;
54
+ this.buildDirPath = buildDirPath;
30
55
  }
31
56
  get id() {
32
57
  return this.filename;
@@ -41,11 +66,19 @@ class QtTest {
41
66
  return __awaiter(this, void 0, void 0, function* () {
42
67
  let slotNames = [];
43
68
  let output = "";
69
+ let err = "";
44
70
  yield new Promise((resolve, reject) => {
71
+ if (!fs.existsSync(this.filename)) {
72
+ reject(new Error("File doesn't exit: " + this.filename));
73
+ return;
74
+ }
45
75
  const child = (0, child_process_1.spawn)(this.filename, ["-functions"]);
46
76
  child.stdout.on("data", (chunk) => {
47
77
  output += chunk.toString();
48
78
  });
79
+ child.stderr.on("data", (chunk) => {
80
+ err += chunk.toString();
81
+ });
49
82
  child.on("exit", (code) => {
50
83
  if (code === 0) {
51
84
  slotNames = slotNames.concat(output.split("\n"));
@@ -61,7 +94,7 @@ class QtTest {
61
94
  resolve(slotNames);
62
95
  }
63
96
  else {
64
- reject(new Error("Failed to run -functions"));
97
+ reject(new Error("Failed to run -functions, stdout=" + output + "; stderr=" + err + "; code=" + code));
65
98
  }
66
99
  });
67
100
  });
@@ -127,7 +160,7 @@ class QtTest {
127
160
  });
128
161
  }
129
162
  /// Runs this test
130
- runTest(slotName) {
163
+ runTest(slotName, cwd = "") {
131
164
  return __awaiter(this, void 0, void 0, function* () {
132
165
  let args = [];
133
166
  if (slotName) {
@@ -135,7 +168,8 @@ class QtTest {
135
168
  args = args.concat(slotName);
136
169
  }
137
170
  return yield new Promise((resolve, reject) => {
138
- const child = (0, child_process_1.spawn)(this.filename, args);
171
+ let opts = cwd.length > 0 ? { cwd: cwd } : { cwd: this.buildDirPath };
172
+ const child = (0, child_process_1.spawn)(this.filename, args, opts);
139
173
  child.stdout.on("data", (chunk) => {
140
174
  // chunk.toString()
141
175
  });
@@ -192,7 +226,7 @@ class QtTests {
192
226
  let ctests = yield cmake.tests();
193
227
  if (ctests) {
194
228
  for (let ctest of ctests) {
195
- let qtest = new QtTest(ctest.executablePath());
229
+ let qtest = new QtTest(ctest.executablePath(), buildDirPath);
196
230
  this.qtTestExecutables.push(qtest);
197
231
  }
198
232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamsergio/qttest-utils",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "API for listing QtTest executables from a build directory and which individual test slots each executable contains. Useful for a Text Explorer VSCode extension.",
5
5
  "scripts": {
6
6
  "build": "tsc"