qunitx 0.8.0 → 0.8.2
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/README.md +95 -34
- package/deno.lock +11 -0
- package/package.json +11 -7
- package/shims/deno/assert.js +208 -35
- package/shims/node/assert.js +204 -37
- package/shims/node/index.js +1 -1
- package/shims/shared/index.js +29 -0
- package/build.js +0 -54
package/README.md
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
|
+

|
|
2
|
+
[](https://badge.fury.io/js/qunitx)
|
|
3
|
+
|
|
1
4
|
# QUnitX
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
***Truly universal testing for JavaScript with the oldest, most mature & flexible
|
|
7
|
+
testing API in the JavaScript ecosystem. Run the same test file in node.js, deno or in the browser***
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
Your test JS/TS file(s) can now run interchangably in different runtimes with
|
|
10
|
+
the default test runner of node.js or deno, or with a browser runner of your
|
|
11
|
+
choice!
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
output in anyway you like. Example:
|
|
13
|
+
[](https://asciinema.org/a/597066?autoplay=1)
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
15
|
+
In the browser you can use the same browser test/filter UI of
|
|
16
|
+
[QUnit](https://github.com/qunitjs/qunit) and share the web links with your
|
|
17
|
+
colleagues thanks to the test filters through query params feature of QUnit:
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
[QUnit Test Suite Example](https://objectmodel.js.org/test/?moduleId=6e15ed5f&moduleId=950ec9c5)
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
npm install -g qunitx
|
|
21
|
+
**UI visual automated tests also possible with QUnit!**
|
|
19
22
|
|
|
20
|
-
qunitx
|
|
21
|
-
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
### Installation: Node & Deno
|
|
26
|
+
|
|
27
|
+
This is a 0-dependency test library that runs code in your target runtime(node,
|
|
28
|
+
deno or browser) test runner. Since a default test runner is a new feature of node.js, please use node.js v20.3+.
|
|
22
29
|
|
|
23
|
-
In order to use qunitx to
|
|
30
|
+
In order to use qunitx to convert qunit tests files please change:
|
|
24
31
|
|
|
25
32
|
```js
|
|
26
33
|
import { module, test } from 'qunit';
|
|
@@ -32,7 +39,7 @@ import { module, test } from 'qunitx';
|
|
|
32
39
|
Example:
|
|
33
40
|
|
|
34
41
|
```js
|
|
35
|
-
// in some-test.js: (typescript
|
|
42
|
+
// in some-test.js: (typescript also works)
|
|
36
43
|
import { module, test } from 'qunitx';
|
|
37
44
|
import $ from 'jquery';
|
|
38
45
|
|
|
@@ -56,37 +63,91 @@ module('Basic sanity check', function (hooks) {
|
|
|
56
63
|
# you can run the test in node with ES modules package.json{ "type": "module" }
|
|
57
64
|
$ node --test some-test.js
|
|
58
65
|
|
|
59
|
-
#
|
|
66
|
+
# TypeScript also works, make sure on node.js mode, tsconfig.json exists with compilerOptions.module & compilerOptions.moduleResolution set to "NodeNext":
|
|
67
|
+
$ node --loader=ts-node/esm/transpile-only --test some-test.ts
|
|
68
|
+
|
|
69
|
+
# You can use the new watch mode of node.js to watch for files or folder patterns
|
|
70
|
+
$ node --test --watch some-test.js some-folder/*.js
|
|
71
|
+
|
|
72
|
+
# You can also run this test on deno. Unfortunately today deno requires one extra step to create a deno.json file:
|
|
73
|
+
$ echo '{"imports": { "qunitx": "https://esm.sh/qunitx/shims/deno/index.js" } }' > deno.json
|
|
74
|
+
|
|
75
|
+
# then run the tests in default deno test runner:
|
|
76
|
+
$ deno test some-test.js
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Installation: Browser
|
|
80
|
+
|
|
81
|
+
QUnitX mainly proxies to [QUnit
|
|
82
|
+
API](https://api.qunitjs.com/QUnit/module/#hooks-on-nested-modules) in browser.
|
|
83
|
+
You can use [QUnitX CLI](https://github.com/izelnakri/qunitx-cli) to get your
|
|
84
|
+
browser tests to stdout/CI or use the watch mode during the development.
|
|
60
85
|
|
|
86
|
+
```zsh
|
|
87
|
+
# Install QUnitX browser runner/cli:
|
|
88
|
+
$ npm install -g qunitx-cli
|
|
89
|
+
$ qunitx
|
|
61
90
|
$ qunitx some-test.js
|
|
62
91
|
|
|
63
92
|
# with browser output enabled:
|
|
64
|
-
|
|
65
93
|
$ qunitx some-test.js --debug
|
|
66
94
|
|
|
67
|
-
|
|
95
|
+
```
|
|
68
96
|
|
|
69
|
-
|
|
97
|
+
### Concurrency options
|
|
70
98
|
|
|
71
|
-
|
|
99
|
+
QUnitX API accepts an optional options object as 2nd argument to:
|
|
100
|
+
- `QUnit.module(testName, optionsOrHandler?, handler?)`
|
|
101
|
+
- `QUnit.test(testName, optionsOrHandler?, handler?)`
|
|
72
102
|
|
|
73
|
-
|
|
103
|
+
So you can run tests in parallel(default) or in series. You can even run them
|
|
104
|
+
through the [node.js test runner run()
|
|
105
|
+
api](https://nodejs.org/api/test.html#runoptions):
|
|
74
106
|
|
|
75
|
-
|
|
107
|
+
```js
|
|
108
|
+
// in some-test.js: (typescript also works)
|
|
109
|
+
import { module, test } from 'qunitx';
|
|
110
|
+
import $ from 'jquery';
|
|
76
111
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
112
|
+
module('Basic sanity check', function (hooks) {
|
|
113
|
+
test('it works', { concurrency: false }, function (assert) {
|
|
114
|
+
assert.equal(true, true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
module('More advanced cases', { concurrency: false, permissions: { read: true }, sanitizeExit: false }, function (hooks) {
|
|
118
|
+
test('deepEqual works', function (assert) {
|
|
119
|
+
assert.deepEqual({ username: 'izelnakri' }, { username: 'izelnakri' });
|
|
120
|
+
});
|
|
121
|
+
test('can import ES & npm modules', function (assert) {
|
|
122
|
+
assert.ok(Object.keys($));
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
80
126
|
```
|
|
81
127
|
|
|
82
|
-
|
|
128
|
+
### Code coverage
|
|
129
|
+
|
|
130
|
+
Since QUnitX proxies to default node.js test runner in when executed with node,
|
|
131
|
+
you can use any code coverage tool you like. When running the tests in
|
|
132
|
+
`qunit`(the browser mode) code coverage support is limited.
|
|
83
133
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
includes in the code, this cannot be filtered since potential filtering can only occur after the `esbuild` bundling.
|
|
88
|
-
When chrome browser and puppeteer fully supports ES asset maps we can remove esbuild from the browser mode, run
|
|
89
|
-
everything in deno and make instrumentation for code coverage possible with the default v8 instrumentation.
|
|
134
|
+
```zsh
|
|
135
|
+
$ c8 node --test test/attachments test/user
|
|
136
|
+
```
|
|
90
137
|
|
|
91
|
-
|
|
92
|
-
|
|
138
|
+
You can browse [c8 documentation](https://github.com/bcoe/c8) for all
|
|
139
|
+
configuration options.
|
|
140
|
+
|
|
141
|
+
Implementing code coverage for the browser mode is currently not possible
|
|
142
|
+
because we use esbuild --bundle feature to create a JS bundles for testing in
|
|
143
|
+
the browser, this could be instrumented with `puppeteer-to-istanbul` however
|
|
144
|
+
instrumentation includes transpiled npm imports of `qunitx` and other potential
|
|
145
|
+
npm imports developer includes in the code, this cannot be filtered since
|
|
146
|
+
potential filtering can only occur after the `esbuild` bundling. When chrome
|
|
147
|
+
browser and puppeteer fully supports ES asset maps we can remove esbuild from
|
|
148
|
+
the browser mode, run everything in deno and make instrumentation for code
|
|
149
|
+
coverage possible with the default v8 instrumentation.
|
|
150
|
+
|
|
151
|
+
Esbuild plugin interface is an ongoing development, we might be able to figure
|
|
152
|
+
out a way to generate this instrumentation with esbuild in the future, which
|
|
153
|
+
could allow code coverage for --browser mode.
|
package/deno.lock
CHANGED
|
@@ -7,5 +7,16 @@
|
|
|
7
7
|
"https://deno.land/std@0.192.0/testing/_test_suite.ts": "30f018feeb3835f12ab198d8a518f9089b1bcb2e8c838a8b615ab10d5005465c",
|
|
8
8
|
"https://deno.land/std@0.192.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f",
|
|
9
9
|
"https://deno.land/std@0.192.0/testing/bdd.ts": "59f7f7503066d66a12e50ace81bfffae5b735b6be1208f5684b630ae6b4de1d0"
|
|
10
|
+
},
|
|
11
|
+
"npm": {
|
|
12
|
+
"specifiers": {
|
|
13
|
+
"@types/node": "@types/node@18.16.19"
|
|
14
|
+
},
|
|
15
|
+
"packages": {
|
|
16
|
+
"@types/node@18.16.19": {
|
|
17
|
+
"integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==",
|
|
18
|
+
"dependencies": {}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
10
21
|
}
|
|
11
22
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qunitx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.8.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.8.2",
|
|
5
|
+
"description": "A universal test framework for testing any js file on node.js, browser or deno with QUnit API",
|
|
6
6
|
"author": "Izel Nakri",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"keywords": [
|
|
@@ -45,16 +45,20 @@
|
|
|
45
45
|
"release:alpha": "node_modules/.bin/release-it --preRelease=alpha --no-git.requireUpstream",
|
|
46
46
|
"release:beta": "node_modules/.bin/release-it --preRelease=beta --no-git.requireUpstream",
|
|
47
47
|
"release": "node_modules/.bin/release-it",
|
|
48
|
-
"test": "
|
|
49
|
-
"test:
|
|
50
|
-
"test:
|
|
48
|
+
"test": "npm run test:browser && npm run test:node && npm run test:deno",
|
|
49
|
+
"test:dev": "npm run test | tee test-output.log",
|
|
50
|
+
"test:browser": "qunitx test/index.js --debug",
|
|
51
|
+
"test:deno": "deno test --allow-read --allow-env --allow-run test/index.js",
|
|
52
|
+
"test:node": "node --test test/index.js"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
|
-
"ts-node": ">=10.7.0",
|
|
54
55
|
"auto-changelog": "^2.4.0",
|
|
55
56
|
"prettier": "^3.0.0",
|
|
56
57
|
"qunit": "^2.19.4",
|
|
57
|
-
"
|
|
58
|
+
"qunitx": "^0.8.0",
|
|
59
|
+
"qunitx-cli": "^0.1.0",
|
|
60
|
+
"release-it": "^16.1.0",
|
|
61
|
+
"ts-node": ">=10.7.0"
|
|
58
62
|
},
|
|
59
63
|
"volta": {
|
|
60
64
|
"node": "20.4.0"
|
package/shims/deno/assert.js
CHANGED
|
@@ -1,55 +1,228 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AssertionError as DenoAssertionError, assertRejects, assertThrows } from "https://deno.land/std@0.192.0/testing/asserts.ts";
|
|
2
|
+
import '../../vendor/qunit.js';
|
|
3
|
+
import { objectValuesSubset } from '../shared/index.js';
|
|
4
|
+
import util from 'node:util';
|
|
2
5
|
|
|
3
|
-
class AssertionError extends
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
super(message);
|
|
6
|
+
export class AssertionError extends DenoAssertionError {
|
|
7
|
+
constructor(object) {
|
|
8
|
+
super(object.message);
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
11
|
|
|
12
|
+
// NOTE: Maybe do the expect, steps in some object, and also do timeout and async(?)
|
|
10
13
|
export default {
|
|
11
14
|
_steps: [],
|
|
12
|
-
|
|
13
|
-
return
|
|
15
|
+
timeout() {
|
|
16
|
+
return true; // NOTE: NOT implemented
|
|
17
|
+
},
|
|
18
|
+
step(value = '') {
|
|
19
|
+
this._steps.push(value);
|
|
20
|
+
},
|
|
21
|
+
verifySteps(steps, message = 'Verify steps failed!') {
|
|
22
|
+
const result = this.deepEqual(this._steps, steps, message);
|
|
23
|
+
|
|
24
|
+
this._steps.length = 0;
|
|
25
|
+
|
|
26
|
+
return result;
|
|
14
27
|
},
|
|
15
|
-
deepEqual: assertEquals,
|
|
16
|
-
equal: assertEquals,
|
|
17
28
|
expect() {
|
|
18
29
|
return () => {}; // NOTE: NOT implemented
|
|
19
30
|
},
|
|
20
|
-
|
|
21
|
-
return
|
|
31
|
+
async() {
|
|
32
|
+
return () => {}; // NOTE: noop, node should have sanitizeResources
|
|
33
|
+
},
|
|
34
|
+
pushResult(resultInfo = {}) {
|
|
35
|
+
if (!result) {
|
|
36
|
+
throw new AssertionError({
|
|
37
|
+
actual: resultInfo.actual,
|
|
38
|
+
expected: resultInfo.expected,
|
|
39
|
+
message: result.Infomessage || 'Custom assertion failed!',
|
|
40
|
+
stackStartFn: this.pushResult,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
ok(state, message) {
|
|
45
|
+
if (!state) {
|
|
46
|
+
throw new AssertionError({
|
|
47
|
+
actual: state,
|
|
48
|
+
expected: true,
|
|
49
|
+
message: message || `Expected argument to be truthy, it was: ${inspect(state)}`,
|
|
50
|
+
stackStartFn: this.ok,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
22
53
|
},
|
|
23
|
-
notDeepEqual: assertNotEquals,
|
|
24
|
-
notEqual: assertNotEquals,
|
|
25
54
|
notOk(state, message) {
|
|
26
|
-
|
|
55
|
+
if (state) {
|
|
56
|
+
throw new AssertionError({
|
|
57
|
+
actual: state,
|
|
58
|
+
expected: false,
|
|
59
|
+
message: message || `Expected argument to be falsy, it was: ${inspect(state)}`,
|
|
60
|
+
stackStartFn: this.notOk,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
27
63
|
},
|
|
28
|
-
|
|
29
|
-
|
|
64
|
+
true(state, message) {
|
|
65
|
+
if (state === true) {
|
|
66
|
+
throw new AssertionError({
|
|
67
|
+
actual: state,
|
|
68
|
+
expected: true,
|
|
69
|
+
message: message || `Expected argument to be true, it was: ${inspect(state)}`,
|
|
70
|
+
stackStartFn: this.true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
30
73
|
},
|
|
31
|
-
|
|
32
|
-
|
|
74
|
+
false(state, message) {
|
|
75
|
+
if (state === false) {
|
|
76
|
+
throw new AssertionError({
|
|
77
|
+
actual: state,
|
|
78
|
+
expected: true,
|
|
79
|
+
message: message || `Expected argument to be false, it was: ${inspect(state)}`,
|
|
80
|
+
stackStartFn: this.false,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
33
83
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
84
|
+
equal(actual, expected, message) {
|
|
85
|
+
if (actual == expected) {
|
|
86
|
+
throw new AssertionError({
|
|
87
|
+
actual,
|
|
88
|
+
expected,
|
|
89
|
+
message: message || `Expected: ${defaultMessage(actual, 'should equal to:', expected)}`,
|
|
90
|
+
operator: '==',
|
|
91
|
+
stackStartFn: this.equal,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
39
94
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
95
|
+
notEqual(actual, expected, message) {
|
|
96
|
+
if (actual != expected) {
|
|
97
|
+
throw new AssertionError({
|
|
98
|
+
actual,
|
|
99
|
+
expected,
|
|
100
|
+
operator: '!=',
|
|
101
|
+
message: message || `Expected: ${defaultMessage(actual, 'should notEqual to:', expected)}`,
|
|
102
|
+
stackStartFn: this.notEqual,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
43
105
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
106
|
+
propEqual(actual, expected, message) {
|
|
107
|
+
let targetActual = objectValues(actual);
|
|
108
|
+
let targetExpected = objectValues(expected);
|
|
109
|
+
if (!window.QUnit.window.QUnit.equiv(targetActual, targetExpected)) {
|
|
110
|
+
throw new AssertionError({
|
|
111
|
+
actual: targetActual,
|
|
112
|
+
expected: targetExpected,
|
|
113
|
+
message: message || `Expected properties to be propEqual: ${defaultMessage(targetActual, 'should propEqual to:', targetExpected)}`,
|
|
114
|
+
stackStartFn: this.propEqual,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
48
117
|
},
|
|
49
|
-
|
|
50
|
-
|
|
118
|
+
notPropEqual(actual, expected, message) {
|
|
119
|
+
let targetActual = objectValues(actual);
|
|
120
|
+
let targetExpected = objectValues(expected);
|
|
121
|
+
if (window.QUnit.equiv(targetActual, targetExpected)) {
|
|
122
|
+
throw new AssertionError({
|
|
123
|
+
actual: targetActual,
|
|
124
|
+
expected: targetExpected,
|
|
125
|
+
message: message || `Expected properties to NOT be propEqual: ${defaultMessage(targetActual, 'should notPropEqual to:', targetExpected)}`,
|
|
126
|
+
stackStartFn: this.notPropEqual,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
51
129
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
130
|
+
propContains(actual, expected, message) {
|
|
131
|
+
let targetActual = objectValuesSubset(actual, expected);
|
|
132
|
+
let targetExpected = objectValues(expected, false);
|
|
133
|
+
if (!window.QUnit.equiv(targetActual, targetExpected)) {
|
|
134
|
+
throw new AssertionError({
|
|
135
|
+
actual: targetActual,
|
|
136
|
+
expected: targetExpected,
|
|
137
|
+
message: message || `propContains assertion fail on: ${defaultMessage(targetActual, 'should propContains to:', targetExpected)}`,
|
|
138
|
+
stackStartFn: this.propContains,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
notPropContains(actual, expected, message) {
|
|
143
|
+
let targetActual = objectValuesSubset(actual, expected);
|
|
144
|
+
let targetExpected = objectValues(expected);
|
|
145
|
+
if (window.QUnit.equiv(targetActual, targetExpected)) {
|
|
146
|
+
throw new AssertionError({
|
|
147
|
+
actual: targetActual,
|
|
148
|
+
expected: targetExpected,
|
|
149
|
+
message: message || `notPropContains assertion fail on: ${defaultMessage(targetActual, 'should notPropContains of:', targetExpected)}`,
|
|
150
|
+
stackStartFn: this.notPropContains,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
deepEqual(actual, expected, message) {
|
|
155
|
+
if (!window.QUnit.equiv(actual, expected)) {
|
|
156
|
+
throw new AssertionError({
|
|
157
|
+
actual,
|
|
158
|
+
expected,
|
|
159
|
+
message: message || `Expected values to be deepEqual: ${defaultMessage(actual, 'should deepEqual to:', expected)}`,
|
|
160
|
+
operator: 'deepEqual',
|
|
161
|
+
stackStartFn: this.deepEqual,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
notDeepEqual(actual, expected, message) {
|
|
166
|
+
if (window.QUnit.equiv(actual, expected)) {
|
|
167
|
+
throw new AssertionError({
|
|
168
|
+
actual,
|
|
169
|
+
expected,
|
|
170
|
+
message: message || `Expected values to be NOT deepEqual: ${defaultMessage(actual, 'should notDeepEqual to:', expected)}`,
|
|
171
|
+
operator: 'notDeepEqual',
|
|
172
|
+
stackStartFn: this.notDeepEqual,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
strictEqual(actual, expected, message) {
|
|
177
|
+
if (actual !== expected) {
|
|
178
|
+
throw new AssertionError({
|
|
179
|
+
actual,
|
|
180
|
+
expected,
|
|
181
|
+
message: message || `Expected: ${defaultMessage(actual, 'is strictEqual to:', expected)}`,
|
|
182
|
+
operator: 'strictEqual',
|
|
183
|
+
stackStartFn: this.strictEqual,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
notStrictEqual(actual, expected, message) {
|
|
188
|
+
if (actual === expected) {
|
|
189
|
+
throw new AssertionError({
|
|
190
|
+
actual,
|
|
191
|
+
expected,
|
|
192
|
+
message: message || `Expected: ${defaultMessage(actual, 'is notStrictEqual to:', expected)}`,
|
|
193
|
+
operator: 'notStrictEqual',
|
|
194
|
+
stackStartFn: this.notStrictEqual,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
throws: assertThrows,
|
|
199
|
+
rejects: assertRejects,
|
|
55
200
|
};
|
|
201
|
+
|
|
202
|
+
function objectValues(obj) {
|
|
203
|
+
let allowArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
204
|
+
let vals = allowArray && is('array', obj) ? [] : {};
|
|
205
|
+
|
|
206
|
+
for (var key in obj) {
|
|
207
|
+
if (hasOwn$1.call(obj, key)) {
|
|
208
|
+
let val = obj[key];
|
|
209
|
+
vals[key] = val === Object(val) ? objectValues(val, allowArray) : val;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return vals;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function defaultMessage(actual, description, expected) {
|
|
217
|
+
return `
|
|
218
|
+
|
|
219
|
+
${inspect(actual)}
|
|
220
|
+
|
|
221
|
+
${description}
|
|
222
|
+
|
|
223
|
+
${inspect(expected)}`
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function inspect(value) {
|
|
227
|
+
return util.inspect(value, { depth: 10, colors: true, compact: false });
|
|
228
|
+
}
|
package/shims/node/assert.js
CHANGED
|
@@ -1,55 +1,222 @@
|
|
|
1
|
-
import
|
|
1
|
+
import QUnit from '../../vendor/qunit.js';
|
|
2
|
+
import { objectValuesSubset } from '../shared/index.js';
|
|
3
|
+
import assert, { AssertionError } from 'node:assert';
|
|
4
|
+
import util from 'node:util';
|
|
2
5
|
|
|
3
|
-
//
|
|
4
|
-
// TODO: basically keep going until const { message } = new assert.AssertionError({ actual, expected, operator, message });
|
|
6
|
+
// NOTE: Maybe do the expect, steps in some object, and also do timeout and async(?)
|
|
5
7
|
export default {
|
|
6
8
|
_steps: [],
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
+
timeout() {
|
|
10
|
+
return true; // NOTE: NOT implemented
|
|
11
|
+
},
|
|
12
|
+
step(value = '') {
|
|
13
|
+
this._steps.push(value);
|
|
14
|
+
},
|
|
15
|
+
verifySteps(steps, message = 'Verify steps failed!') {
|
|
16
|
+
const result = this.deepEqual(this._steps, steps, message);
|
|
17
|
+
|
|
18
|
+
this._steps.length = 0;
|
|
19
|
+
|
|
20
|
+
return result;
|
|
9
21
|
},
|
|
10
|
-
deepEqual: assert.deepStrictEqual,
|
|
11
|
-
equal: assert.strictEqual,
|
|
12
22
|
expect() {
|
|
13
23
|
return () => {}; // NOTE: NOT implemented
|
|
14
24
|
},
|
|
15
|
-
|
|
16
|
-
return
|
|
25
|
+
async() {
|
|
26
|
+
return () => {}; // NOTE: noop, node should have sanitizeResources
|
|
27
|
+
},
|
|
28
|
+
pushResult(resultInfo = {}) {
|
|
29
|
+
if (!result) {
|
|
30
|
+
throw new AssertionError({
|
|
31
|
+
actual: resultInfo.actual,
|
|
32
|
+
expected: resultInfo.expected,
|
|
33
|
+
message: result.Infomessage || 'Custom assertion failed!',
|
|
34
|
+
stackStartFn: this.pushResult,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
ok(state, message) {
|
|
39
|
+
if (!state) {
|
|
40
|
+
throw new AssertionError({
|
|
41
|
+
actual: state,
|
|
42
|
+
expected: true,
|
|
43
|
+
message: message || `Expected argument to be truthy, it was: ${inspect(state)}`,
|
|
44
|
+
stackStartFn: this.ok,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
17
47
|
},
|
|
18
|
-
notDeepEqual: assert.notDeepStrictEqual,
|
|
19
|
-
notEqual: assert.notStrictEqual,
|
|
20
48
|
notOk(state, message) {
|
|
21
|
-
|
|
49
|
+
if (state) {
|
|
50
|
+
throw new AssertionError({
|
|
51
|
+
actual: state,
|
|
52
|
+
expected: false,
|
|
53
|
+
message: message || `Expected argument to be falsy, it was: ${inspect(state)}`,
|
|
54
|
+
stackStartFn: this.notOk,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
22
57
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
58
|
+
true(state, message) {
|
|
59
|
+
if (state === true) {
|
|
60
|
+
throw new AssertionError({
|
|
61
|
+
actual: state,
|
|
62
|
+
expected: true,
|
|
63
|
+
message: message || `Expected argument to be true, it was: ${inspect(state)}`,
|
|
64
|
+
stackStartFn: this.true,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
26
67
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
68
|
+
false(state, message) {
|
|
69
|
+
if (state === false) {
|
|
70
|
+
throw new AssertionError({
|
|
71
|
+
actual: state,
|
|
72
|
+
expected: true,
|
|
73
|
+
message: message || `Expected argument to be false, it was: ${inspect(state)}`,
|
|
74
|
+
stackStartFn: this.false,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
30
77
|
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
78
|
+
equal(actual, expected, message) {
|
|
79
|
+
if (actual == expected) {
|
|
80
|
+
throw new AssertionError({
|
|
81
|
+
actual,
|
|
82
|
+
expected,
|
|
83
|
+
message: message || `Expected: ${defaultMessage(actual, 'should equal to:', expected)}`,
|
|
84
|
+
operator: '==',
|
|
85
|
+
stackStartFn: this.equal,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
36
88
|
},
|
|
37
|
-
|
|
38
|
-
|
|
89
|
+
notEqual(actual, expected, message) {
|
|
90
|
+
if (actual != expected) {
|
|
91
|
+
throw new AssertionError({
|
|
92
|
+
actual,
|
|
93
|
+
expected,
|
|
94
|
+
operator: '!=',
|
|
95
|
+
message: message || `Expected: ${defaultMessage(actual, 'should notEqual to:', expected)}`,
|
|
96
|
+
stackStartFn: this.notEqual,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
39
99
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
100
|
+
propEqual(actual, expected, message) {
|
|
101
|
+
let targetActual = objectValues(actual);
|
|
102
|
+
let targetExpected = objectValues(expected);
|
|
103
|
+
if (!QUnit.equiv(targetActual, targetExpected)) {
|
|
104
|
+
throw new AssertionError({
|
|
105
|
+
actual: targetActual,
|
|
106
|
+
expected: targetExpected,
|
|
107
|
+
message: message || `Expected properties to be propEqual: ${defaultMessage(targetActual, 'should propEqual to:', targetExpected)}`,
|
|
108
|
+
stackStartFn: this.propEqual,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
43
111
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
112
|
+
notPropEqual(actual, expected, message) {
|
|
113
|
+
let targetActual = objectValues(actual);
|
|
114
|
+
let targetExpected = objectValues(expected);
|
|
115
|
+
if (QUnit.equiv(targetActual, targetExpected)) {
|
|
116
|
+
throw new AssertionError({
|
|
117
|
+
actual: targetActual,
|
|
118
|
+
expected: targetExpected,
|
|
119
|
+
message: message || `Expected properties to NOT be propEqual: ${defaultMessage(targetActual, 'should notPropEqual to:', targetExpected)}`,
|
|
120
|
+
stackStartFn: this.notPropEqual,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
48
123
|
},
|
|
49
|
-
|
|
50
|
-
|
|
124
|
+
propContains(actual, expected, message) {
|
|
125
|
+
let targetActual = objectValuesSubset(actual, expected);
|
|
126
|
+
let targetExpected = objectValues(expected, false);
|
|
127
|
+
if (!QUnit.equiv(targetActual, targetExpected)) {
|
|
128
|
+
throw new AssertionError({
|
|
129
|
+
actual: targetActual,
|
|
130
|
+
expected: targetExpected,
|
|
131
|
+
message: message || `propContains assertion fail on: ${defaultMessage(targetActual, 'should propContains to:', targetExpected)}`,
|
|
132
|
+
stackStartFn: this.propContains,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
51
135
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
136
|
+
notPropContains(actual, expected, message) {
|
|
137
|
+
let targetActual = objectValuesSubset(actual, expected);
|
|
138
|
+
let targetExpected = objectValues(expected);
|
|
139
|
+
if (QUnit.equiv(targetActual, targetExpected)) {
|
|
140
|
+
throw new AssertionError({
|
|
141
|
+
actual: targetActual,
|
|
142
|
+
expected: targetExpected,
|
|
143
|
+
message: message || `notPropContains assertion fail on: ${defaultMessage(targetActual, 'should notPropContains of:', targetExpected)}`,
|
|
144
|
+
stackStartFn: this.notPropContains,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
deepEqual(actual, expected, message) {
|
|
149
|
+
if (!QUnit.equiv(actual, expected)) {
|
|
150
|
+
throw new AssertionError({
|
|
151
|
+
actual,
|
|
152
|
+
expected,
|
|
153
|
+
message: message || `Expected values to be deepEqual: ${defaultMessage(actual, 'should deepEqual to:', expected)}`,
|
|
154
|
+
operator: 'deepEqual',
|
|
155
|
+
stackStartFn: this.deepEqual,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
notDeepEqual(actual, expected, message) {
|
|
160
|
+
if (QUnit.equiv(actual, expected)) {
|
|
161
|
+
throw new AssertionError({
|
|
162
|
+
actual,
|
|
163
|
+
expected,
|
|
164
|
+
message: message || `Expected values to be NOT deepEqual: ${defaultMessage(actual, 'should notDeepEqual to:', expected)}`,
|
|
165
|
+
operator: 'notDeepEqual',
|
|
166
|
+
stackStartFn: this.notDeepEqual,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
strictEqual(actual, expected, message) {
|
|
171
|
+
if (actual !== expected) {
|
|
172
|
+
throw new AssertionError({
|
|
173
|
+
actual,
|
|
174
|
+
expected,
|
|
175
|
+
message: message || `Expected: ${defaultMessage(actual, 'is strictEqual to:', expected)}`,
|
|
176
|
+
operator: 'strictEqual',
|
|
177
|
+
stackStartFn: this.strictEqual,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
notStrictEqual(actual, expected, message) {
|
|
182
|
+
if (actual === expected) {
|
|
183
|
+
throw new AssertionError({
|
|
184
|
+
actual,
|
|
185
|
+
expected,
|
|
186
|
+
message: message || `Expected: ${defaultMessage(actual, 'is notStrictEqual to:', expected)}`,
|
|
187
|
+
operator: 'notStrictEqual',
|
|
188
|
+
stackStartFn: this.notStrictEqual,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
throws: assert.throws,
|
|
193
|
+
rejects: assert.rejects,
|
|
55
194
|
};
|
|
195
|
+
|
|
196
|
+
function objectValues(obj) {
|
|
197
|
+
let allowArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
198
|
+
let vals = allowArray && is('array', obj) ? [] : {};
|
|
199
|
+
|
|
200
|
+
for (var key in obj) {
|
|
201
|
+
if (hasOwn$1.call(obj, key)) {
|
|
202
|
+
let val = obj[key];
|
|
203
|
+
vals[key] = val === Object(val) ? objectValues(val, allowArray) : val;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return vals;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function defaultMessage(actual, description, expected) {
|
|
211
|
+
return `
|
|
212
|
+
|
|
213
|
+
${inspect(actual)}
|
|
214
|
+
|
|
215
|
+
${description}
|
|
216
|
+
|
|
217
|
+
${inspect(expected)}`
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function inspect(value) {
|
|
221
|
+
return util.inspect(value, { depth: 10, colors: true, compact: false });
|
|
222
|
+
}
|
package/shims/node/index.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively clone an object into a plain object, taking only the
|
|
3
|
+
* subset of own enumerable properties that exist a given model.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} obj
|
|
6
|
+
* @param {any} model
|
|
7
|
+
* @return {Object}
|
|
8
|
+
*/
|
|
9
|
+
export function objectValuesSubset(obj, model) {
|
|
10
|
+
// Return primitive values unchanged to avoid false positives or confusing
|
|
11
|
+
// results from assert.propContains().
|
|
12
|
+
// E.g. an actual null or false wrongly equaling an empty object,
|
|
13
|
+
// or an actual string being reported as object not matching a partial object.
|
|
14
|
+
if (obj !== Object(obj)) {
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Unlike objectValues(), subset arrays to a plain objects as well.
|
|
19
|
+
// This enables subsetting [20, 30] with {1: 30}.
|
|
20
|
+
var subset = {};
|
|
21
|
+
for (var key in model) {
|
|
22
|
+
if (hasOwn$1.call(model, key) && hasOwn$1.call(obj, key)) {
|
|
23
|
+
subset[key] = objectValuesSubset(obj[key], model[key]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return subset;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default { objectValuesSubset };
|
package/build.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
|
|
3
|
-
let [qunitJS, qunitCSS, _] = await Promise.all([
|
|
4
|
-
fs.readFile('./node_modules/qunit/qunit/qunit.js'),
|
|
5
|
-
fs.readFile('./node_modules/qunit/qunit/qunit.css'),
|
|
6
|
-
fs.mkdir('./vendor', { recursive: true })
|
|
7
|
-
]);
|
|
8
|
-
|
|
9
|
-
let newQUnit = qunitJS.toString().replace(
|
|
10
|
-
'start: function start(count) {',
|
|
11
|
-
`reset: function() {
|
|
12
|
-
ProcessingQueue.finished = false;
|
|
13
|
-
globalStartCalled = false;
|
|
14
|
-
runStarted = false;
|
|
15
|
-
|
|
16
|
-
config.queue.length = 0;
|
|
17
|
-
config.modules.length = 0;
|
|
18
|
-
config.autostart = false;
|
|
19
|
-
|
|
20
|
-
Object.assign(config.stats, { total: 0, passed: 0, failed: 0, skipped: 0, todo: 0 });
|
|
21
|
-
|
|
22
|
-
[
|
|
23
|
-
"started", "updateRate", "filter", "depth", "current",
|
|
24
|
-
"pageLoaded", "timeoutHandler", "timeout", "pollution"
|
|
25
|
-
].forEach( ( key ) => delete config[ key ] );
|
|
26
|
-
|
|
27
|
-
const suiteReport = config.currentModule.suiteReport;
|
|
28
|
-
|
|
29
|
-
suiteReport.childSuites.length = 0;
|
|
30
|
-
delete suiteReport._startTime;
|
|
31
|
-
delete suiteReport._endTime;
|
|
32
|
-
|
|
33
|
-
config.modules.push( config.currentModule );
|
|
34
|
-
},
|
|
35
|
-
start: function start(count) {`);
|
|
36
|
-
|
|
37
|
-
await Promise.all([
|
|
38
|
-
fs.writeFile('./vendor/qunit.js', newQUnit),
|
|
39
|
-
fs.writeFile('./vendor/qunit.css', qunitCSS),
|
|
40
|
-
createPackageJSONIfNotExists()
|
|
41
|
-
]);
|
|
42
|
-
|
|
43
|
-
async function createPackageJSONIfNotExists() {
|
|
44
|
-
try {
|
|
45
|
-
await fs.stat('./vendor/package.json');
|
|
46
|
-
|
|
47
|
-
return true;
|
|
48
|
-
} catch (error) {
|
|
49
|
-
await fs.writeFile('./vendor/package.json', JSON.stringify({
|
|
50
|
-
name: 'qunitx-vendor',
|
|
51
|
-
version: '0.0.1'
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
54
|
-
}
|