@iamsergio/qttest-utils 0.4.8 → 1.0.0

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.
@@ -0,0 +1,37 @@
1
+ # Tips for contributors
2
+
3
+ ## Prepare your development environment
4
+
5
+ Just follow `.devcontainer/Dockerfile` to see what's needed.<br?>
6
+ Basically it's just `nodejs` >= v18 `tsc` and `npm`. <br>
7
+ Qt5, cmake and ninja if you want to run the tests.
8
+
9
+
10
+ ## Running tests
11
+
12
+ ```bash
13
+ tsc
14
+ node out/test.js
15
+ ```
16
+
17
+ Or simply let GitHub actions run the tests for you.<br>
18
+ See `ci.yml` for how we run the tests.
19
+
20
+ ## Install git-cliff
21
+
22
+ ```bash
23
+ cargo install git-cliff
24
+ ```
25
+
26
+ ## Releasing
27
+
28
+ (Replace 1.0.0 with actual version used)
29
+
30
+ - Make sure Github Actions CI is green
31
+ - Optional: To get a version compatible with semver, run `git cliff --bump`
32
+ - Increase version in package.json and package-lock.json.
33
+ - git cliff --tag 1.0.0 > Changelog
34
+ - git add Changelog package.json package-lock.json && git commit -m "chore: bump version"
35
+ - git tag -a v1.0.0 -m 'v1.0.0'
36
+ - git push --tags
37
+ - npm publish
package/Changelog ADDED
@@ -0,0 +1,54 @@
1
+ # Changelog
2
+
3
+
4
+
5
+ ## [1.0.0] - 2024-04-04
6
+
7
+ ### 🧪 Testing
8
+
9
+ - Add a proper test and add it to cI
10
+
11
+ ### ⚙️ Miscellaneous Tasks
12
+
13
+ - Add a git-cliff configuration file
14
+ - Add pre-commit support
15
+ - README improvements
16
+ - Add installation instructions to README
17
+ - Add a Dockerfile with nodejs 18
18
+ - *(ci)* Make pre-commit run on master branch
19
+ - Update version in package-lock.json
20
+ - *(docker)* Install npm, Qt5 and typescript
21
+ - *(ci)* Run tsc in ci
22
+ - *(ci)* Fix typo in yml file
23
+ - *(ci)* Bump to checkout v4
24
+ - *(ci)* Bump to setup-node v4
25
+ - *(ci)* Rename main ci job to 'build'
26
+ - *(vscode)* Add a workspace file
27
+ - Formatted some code automatically
28
+ - Fix typo in comment
29
+ - *(ci)* Install Qt and ninja
30
+ - Bump to version 1.0.0
31
+ - Regenerate out/
32
+ - Add a CONTRIBUTING.md file
33
+
34
+ ## [0.4.9] - 2023-04-06
35
+
36
+ ### 🧪 Testing
37
+
38
+ - Make test3 abort at the beginning
39
+
40
+ ## [0.4.7] - 2023-04-02
41
+
42
+ ### 🧪 Testing
43
+
44
+ - Rename the test slots
45
+
46
+ ### README
47
+
48
+ - Explain how to run the example
49
+
50
+ ### Minor
51
+
52
+ - Ran formatting
53
+ - Pass the entire slot
54
+
package/README.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # nodejs qttest-utils
2
2
 
3
- A nodejs module for listing Qt Test executables and their individual test slots from a CMake build directory.
3
+ ![Build Status](https://github.com/qttest-utils/actions/workflows/ci.yml/badge.svg
4
+ ![Pre-commit](https://github.com/qttest-utils/actions/workflows/pre-commit.yml/badge.svg
5
+
6
+ A [nodejs](https://www.npmjs.com/package/@iamsergio/qttest-utils) module for listing Qt Test executables and their individual test slots from a CMake build directory.
4
7
 
5
8
  To be used by vscode extensions that implement the `Testing API`, but can also be used standalone for whatever reason ;).
6
9
 
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm i @iamsergio/qttest-utils
14
+ ```
7
15
 
8
16
  ## Example
9
17
 
10
- ```
11
- $ cd test/qt_test
12
- $ cmake --preset=dev
13
- $ cmake --build build-dev/
14
- $ cd ../..
15
- $ tsc
16
- $ node out/example.js test/qt_test/build-dev
18
+ ```bash
19
+ cd test/qt_test
20
+ cmake --preset=dev
21
+ cmake --build build-dev/
22
+ cd ../..
23
+ tsc
24
+ node out/example.js test/qt_test/build-dev
17
25
  ```
package/out/cmake.js CHANGED
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.CMakeTest = exports.CMakeTests = void 0;
19
19
  const child_process_1 = require("child_process");
20
20
  const path_1 = __importDefault(require("path"));
21
+ const qttest_1 = require("./qttest");
21
22
  /**
22
23
  * Represents tests added in cmake (Via add_test())
23
24
  *
@@ -40,6 +41,7 @@ class CMakeTests {
40
41
  return undefined;
41
42
  }
42
43
  return new Promise((resolve, reject) => {
44
+ (0, qttest_1.logMessage)("Running ctest --show-only=json-v1 with cwd=" + this.buildDirPath);
43
45
  const child = (0, child_process_1.spawn)("ctest", ["--show-only=json-v1"], { "cwd": this.buildDirPath });
44
46
  let output = "";
45
47
  child.stdout.on("data", (chunk) => {
package/out/example.js CHANGED
@@ -54,6 +54,9 @@ function example() {
54
54
  if (slot.lastTestFailure) {
55
55
  console.log(" failed slot=" + slot.name + "; path=" + slot.lastTestFailure.filePath + "; line=" + slot.lastTestFailure.lineNumber);
56
56
  }
57
+ else {
58
+ console.log(" pass: " + slot.name);
59
+ }
57
60
  }
58
61
  }
59
62
  // Also run individual slots, just for example purposes:
package/out/qttest.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  type LoggerFunction = (arg: string) => void;
2
+ export declare function logMessage(message: string): void;
2
3
  /**
3
4
  * Represents a single QtTest executable.
4
5
  * Supports listing the individual test slots
@@ -12,6 +13,7 @@ export declare class QtTest {
12
13
  constructor(filename: string, buildDirPath: string);
13
14
  get id(): string;
14
15
  get label(): string;
16
+ relativeFilename(): string;
15
17
  /**
16
18
  * Calls "./yourqttest -functions" and stores the results in the slots property.
17
19
  */
package/out/qttest.js CHANGED
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.QtTests = exports.QtTestSlot = exports.QtTest = void 0;
41
+ exports.QtTests = exports.QtTestSlot = exports.QtTest = exports.logMessage = void 0;
42
42
  const child_process_1 = require("child_process");
43
43
  const path_1 = __importDefault(require("path"));
44
44
  const fs = __importStar(require("fs"));
@@ -49,6 +49,7 @@ function logMessage(message) {
49
49
  gLogFunction(message);
50
50
  }
51
51
  }
52
+ exports.logMessage = logMessage;
52
53
  /**
53
54
  * Represents a single QtTest executable.
54
55
  * Supports listing the individual test slots
@@ -68,6 +69,10 @@ class QtTest {
68
69
  get label() {
69
70
  return path_1.default.basename(this.filename);
70
71
  }
72
+ relativeFilename() {
73
+ let current_dir = process.cwd();
74
+ return this.filename.replace(current_dir + "/", "");
75
+ }
71
76
  /**
72
77
  * Calls "./yourqttest -functions" and stores the results in the slots property.
73
78
  */
@@ -178,8 +183,8 @@ class QtTest {
178
183
  return undefined;
179
184
  }
180
185
  /// Runs this test
181
- runTest(slot, cwd = "") {
182
- return __awaiter(this, void 0, void 0, function* () {
186
+ runTest(slot_1) {
187
+ return __awaiter(this, arguments, void 0, function* (slot, cwd = "") {
183
188
  let args = [];
184
189
  if (slot) {
185
190
  // Runs a single Qt test instead
package/out/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/out/test.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ // SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3
+ // Author: Sergio Martins <sergio.martins@kdab.com>
4
+ // SPDX-License-Identifier: MIT
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const qttest_1 = require("./qttest");
16
+ // Be sure to build the Qt tests with CMake first
17
+ // See .github/workflows/ci.yml
18
+ function runTests(buildDirPath) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ let qt = new qttest_1.QtTests();
21
+ yield qt.discoverViaCMake(buildDirPath);
22
+ let expected_executables = [
23
+ "test/qt_test/build-dev/test1",
24
+ "test/qt_test/build-dev/test2",
25
+ "test/qt_test/build-dev/test3"
26
+ ];
27
+ if (qt.qtTestExecutables.length != expected_executables.length) {
28
+ console.error("Expected 3 executables, got " + qt.qtTestExecutables.length);
29
+ process.exit(1);
30
+ }
31
+ // 1. Test that the executable test names are correct:
32
+ var i = 0;
33
+ for (var executable of qt.qtTestExecutables) {
34
+ let expected = expected_executables[i];
35
+ if (executable.relativeFilename() != expected) {
36
+ console.error("Expected executable " + expected + ", got " + executable.relativeFilename());
37
+ process.exit(1);
38
+ }
39
+ i++;
40
+ }
41
+ // 2. Test that the discovered slots are correct:
42
+ yield qt.dumpTestSlots();
43
+ let expected_slots = {
44
+ "test/qt_test/build-dev/test1": ["testA", "testB", "testC"],
45
+ "test/qt_test/build-dev/test2": ["testD", "testE", "testF"],
46
+ "test/qt_test/build-dev/test3": ["testAbortsEverythig", "testH", "testI"],
47
+ };
48
+ for (var executable of qt.qtTestExecutables) {
49
+ var i = 0;
50
+ for (let slot of executable.slots) {
51
+ let expected_slot = expected_slots[executable.relativeFilename()][i];
52
+ if (slot.name != expected_slot) {
53
+ console.error("Expected slot " + expected_slot + ", got " + slot.name);
54
+ process.exit(1);
55
+ }
56
+ i++;
57
+ }
58
+ }
59
+ // 3. Run the tests:
60
+ let expected_success = [true, false, false];
61
+ var i = 0;
62
+ for (var executable of qt.qtTestExecutables) {
63
+ yield executable.runTest();
64
+ let wasSuccess = executable.lastExitCode === 0;
65
+ if (wasSuccess && !expected_success[i]) {
66
+ console.error("Expected test to fail: " + executable.filename);
67
+ process.exit(1);
68
+ }
69
+ else if (!wasSuccess && expected_success[i]) {
70
+ console.error("Expected test to pass: " + executable.filename);
71
+ process.exit(1);
72
+ }
73
+ i++;
74
+ }
75
+ // 4. Run individual slots:
76
+ let slot = qt.qtTestExecutables[0].slots[0];
77
+ yield slot.runTest();
78
+ if (slot.lastTestFailure) {
79
+ console.error("Expected test to pass: " + slot.name);
80
+ process.exit(1);
81
+ }
82
+ let slot2 = qt.qtTestExecutables[1].slots[2];
83
+ yield slot2.runTest();
84
+ if (!slot2.lastTestFailure) {
85
+ console.error("Expected test to fail: " + slot2.name);
86
+ process.exit(1);
87
+ }
88
+ });
89
+ }
90
+ runTests("test/qt_test/build-dev/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamsergio/qttest-utils",
3
- "version": "0.4.8",
3
+ "version": "1.0.0",
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
  "repository": {
6
6
  "type": "git",