@iamsergio/qttest-utils 0.4.9 → 1.1.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,82 @@
1
+ # Changelog
2
+
3
+
4
+
5
+ ## [1.1.0] - 2024-04-07
6
+
7
+ ### 🚀 Features
8
+
9
+ - Added QtTest.verbose property
10
+
11
+ ### 🧪 Testing
12
+
13
+ - Add a QBENCHMARK
14
+ - Fix tests on windows
15
+ - Fix more cases of wrong slashes
16
+ - Test linksToQtTestLib too
17
+
18
+ ### ⚙️ Miscellaneous Tasks
19
+
20
+ - Minor readme comment
21
+ - Update .npmignore
22
+ - Fix typo in README
23
+ - Fix badge urls in README
24
+ - Mention the vscode extension in the README
25
+ - Remove duplicate vscode workspace file
26
+ - Add macOS and Windows to CI
27
+ - Make npm install be verose
28
+ - Trying fixing the path for tsc on macos
29
+ - Update packages
30
+
31
+ ## [1.0.0] - 2024-04-04
32
+
33
+ ### 🧪 Testing
34
+
35
+ - Add a proper test and add it to cI
36
+
37
+ ### ⚙️ Miscellaneous Tasks
38
+
39
+ - Add a git-cliff configuration file
40
+ - Add pre-commit support
41
+ - README improvements
42
+ - Add installation instructions to README
43
+ - Add a Dockerfile with nodejs 18
44
+ - *(ci)* Make pre-commit run on master branch
45
+ - Update version in package-lock.json
46
+ - *(docker)* Install npm, Qt5 and typescript
47
+ - *(ci)* Run tsc in ci
48
+ - *(ci)* Fix typo in yml file
49
+ - *(ci)* Bump to checkout v4
50
+ - *(ci)* Bump to setup-node v4
51
+ - *(ci)* Rename main ci job to 'build'
52
+ - *(vscode)* Add a workspace file
53
+ - Formatted some code automatically
54
+ - Fix typo in comment
55
+ - *(ci)* Install Qt and ninja
56
+ - Bump to version 1.0.0
57
+ - Regenerate out/
58
+ - Add a CONTRIBUTING.md file
59
+ - Update changelog
60
+ - Add ci badges to readme
61
+
62
+ ## [0.4.9] - 2023-04-06
63
+
64
+ ### 🧪 Testing
65
+
66
+ - Make test3 abort at the beginning
67
+
68
+ ## [0.4.7] - 2023-04-02
69
+
70
+ ### 🧪 Testing
71
+
72
+ - Rename the test slots
73
+
74
+ ### README
75
+
76
+ - Explain how to run the example
77
+
78
+ ### Minor
79
+
80
+ - Ran formatting
81
+ - Pass the entire slot
82
+
package/README.md CHANGED
@@ -1,17 +1,27 @@
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/KDAB/qttest-utils/actions/workflows/ci.yml/badge.svg)
4
+ ![Pre-commit](https://github.com/KDAB/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
+ Used by [vscode-qttest](https://github.com/KDAB/vscode-qttest) extension.
7
11
 
8
- ## Example
12
+ ## Installation
9
13
 
14
+ ```bash
15
+ npm i @iamsergio/qttest-utils
10
16
  ```
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
17
+
18
+ ## Example
19
+
20
+ ```bash
21
+ cd test/qt_test
22
+ cmake --preset=dev
23
+ cmake --build build-dev/
24
+ cd ../..
25
+ tsc
26
+ node out/example.js test/qt_test/build-dev
17
27
  ```
package/out/qttest.d.ts CHANGED
@@ -7,12 +7,14 @@ export declare function logMessage(message: string): void;
7
7
  export declare class QtTest {
8
8
  readonly filename: string;
9
9
  readonly buildDirPath: string;
10
+ verbose: boolean;
10
11
  vscodeTestItem: any | undefined;
11
12
  slots: QtTestSlot[] | null;
12
13
  lastExitCode: number;
13
14
  constructor(filename: string, buildDirPath: string);
14
15
  get id(): string;
15
16
  get label(): string;
17
+ relativeFilename(): string;
16
18
  /**
17
19
  * Calls "./yourqttest -functions" and stores the results in the slots property.
18
20
  */
package/out/qttest.js CHANGED
@@ -56,6 +56,8 @@ exports.logMessage = logMessage;
56
56
  */
57
57
  class QtTest {
58
58
  constructor(filename, buildDirPath) {
59
+ /// If true, will print more verbose output
60
+ this.verbose = false;
59
61
  /// The list of individual runnable test slots
60
62
  this.slots = null;
61
63
  /// Set after running
@@ -69,6 +71,15 @@ class QtTest {
69
71
  get label() {
70
72
  return path_1.default.basename(this.filename);
71
73
  }
74
+ relativeFilename() {
75
+ let result = path_1.default.relative(process.cwd(), this.filename);
76
+ // strip .exe, as we only use this for tests
77
+ if (result.endsWith(".exe"))
78
+ result = result.slice(0, -4);
79
+ // normalize slashes
80
+ result = result.replace(/\\/g, "/");
81
+ return result;
82
+ }
72
83
  /**
73
84
  * Calls "./yourqttest -functions" and stores the results in the slots property.
74
85
  */
@@ -79,7 +90,7 @@ class QtTest {
79
90
  let err = "";
80
91
  yield new Promise((resolve, reject) => {
81
92
  if (!fs.existsSync(this.filename)) {
82
- reject(new Error("File doesn't exit: " + this.filename));
93
+ reject(new Error("qttest: File doesn't exit: " + this.filename));
83
94
  return;
84
95
  }
85
96
  const child = (0, child_process_1.spawn)(this.filename, ["-functions"], { cwd: this.buildDirPath });
@@ -104,7 +115,7 @@ class QtTest {
104
115
  resolve(slotNames);
105
116
  }
106
117
  else {
107
- reject(new Error("Failed to run -functions, stdout=" + output + "; stderr=" + err + "; code=" + code));
118
+ reject(new Error("qttest: Failed to run -functions, stdout=" + output + "; stderr=" + err + "; code=" + code));
108
119
  }
109
120
  });
110
121
  });
@@ -132,13 +143,15 @@ class QtTest {
132
143
  result = true;
133
144
  }
134
145
  }
146
+ if (this.verbose)
147
+ console.log(chunk.toString());
135
148
  });
136
149
  child.on("exit", (code) => {
137
150
  if (code === 0) {
138
151
  resolve(result);
139
152
  }
140
153
  else {
141
- reject(new Error("Failed to run ldd"));
154
+ reject(new Error("qttest: Failed to run ldd"));
142
155
  }
143
156
  });
144
157
  });
package/out/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/out/test.js ADDED
@@ -0,0 +1,97 @@
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
+ yield qt.removeNonLinking();
32
+ // 1. Test that the executable test names are correct:
33
+ var i = 0;
34
+ for (var executable of qt.qtTestExecutables) {
35
+ let expected = expected_executables[i];
36
+ if (executable.relativeFilename() != expected) {
37
+ console.error("Expected executable " + expected + ", got " + executable.relativeFilename());
38
+ process.exit(1);
39
+ }
40
+ i++;
41
+ }
42
+ // 2. Test that the discovered slots are correct:
43
+ yield qt.dumpTestSlots();
44
+ let expected_slots = {
45
+ "test/qt_test/build-dev/test1": ["testA", "testB", "testC"],
46
+ "test/qt_test/build-dev/test2": ["testD", "testE", "testF"],
47
+ "test/qt_test/build-dev/test3": ["testAbortsEverythig", "testH", "testI"],
48
+ };
49
+ for (var executable of qt.qtTestExecutables) {
50
+ var i = 0;
51
+ for (let slot of executable.slots) {
52
+ let expected_slot = expected_slots[executable.relativeFilename()][i];
53
+ if (slot.name != expected_slot) {
54
+ console.error("Expected slot " + expected_slot + ", got " + slot.name);
55
+ process.exit(1);
56
+ }
57
+ i++;
58
+ }
59
+ }
60
+ // 3. Run the tests:
61
+ let expected_success = [true, false, false];
62
+ var i = 0;
63
+ for (var executable of qt.qtTestExecutables) {
64
+ yield executable.runTest();
65
+ let wasSuccess = executable.lastExitCode === 0;
66
+ if (wasSuccess && !expected_success[i]) {
67
+ console.error("Expected test to fail: " + executable.filename);
68
+ process.exit(1);
69
+ }
70
+ else if (!wasSuccess && expected_success[i]) {
71
+ console.error("Expected test to pass: " + executable.filename);
72
+ process.exit(1);
73
+ }
74
+ if (process.platform === "linux") {
75
+ if (!executable.linksToQtTestLib()) {
76
+ console.error("Expected test to link to QtTest: " + executable.filename);
77
+ process.exit(1);
78
+ }
79
+ }
80
+ i++;
81
+ }
82
+ // 4. Run individual slots:
83
+ let slot = qt.qtTestExecutables[0].slots[0];
84
+ yield slot.runTest();
85
+ if (slot.lastTestFailure) {
86
+ console.error("Expected test to pass: " + slot.name);
87
+ process.exit(1);
88
+ }
89
+ let slot2 = qt.qtTestExecutables[1].slots[2];
90
+ yield slot2.runTest();
91
+ if (!slot2.lastTestFailure) {
92
+ console.error("Expected test to fail: " + slot2.name);
93
+ process.exit(1);
94
+ }
95
+ });
96
+ }
97
+ 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.9",
3
+ "version": "1.1.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",
@@ -21,6 +21,6 @@
21
21
  "devDependencies": {
22
22
  "@types/node": "^18.15.0",
23
23
  "ts-node": "^10.9.1",
24
- "typescript": "^4.9.5"
24
+ "typescript": "^5.4.4"
25
25
  }
26
26
  }