qunitx 0.7.0 → 0.8.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/.dockerignore +1 -0
- package/README.md +95 -34
- package/build.js +54 -0
- package/deno.json +2 -2
- package/deno.lock +3 -3744
- package/package.json +27 -43
- package/{index.js → shims/browser/index.js} +2 -4
- package/shims/deno/assert.js +228 -0
- package/shims/{deno.js → deno/index.js} +1 -1
- package/shims/node/assert.js +222 -0
- package/shims/{nodejs.js → node/index.js} +2 -2
- package/shims/shared/index.js +29 -0
- package/vendor/package.json +1 -4
- package/cli.js +0 -25
- package/deno/cli.js +0 -21
- package/lib/boilerplates/default-project-config-values.js +0 -6
- package/lib/boilerplates/setup/tests.hbs +0 -15
- package/lib/boilerplates/setup/tsconfig.json +0 -109
- package/lib/boilerplates/test.js +0 -25
- package/lib/commands/generate.js +0 -33
- package/lib/commands/help.js +0 -38
- package/lib/commands/init.js +0 -70
- package/lib/commands/run/tests-in-browser.js +0 -162
- package/lib/commands/run.js +0 -119
- package/lib/servers/http.js +0 -233
- package/lib/setup/bind-server-to-port.js +0 -14
- package/lib/setup/browser.js +0 -55
- package/lib/setup/config.js +0 -46
- package/lib/setup/file-watcher.js +0 -72
- package/lib/setup/fs-tree.js +0 -48
- package/lib/setup/keyboard-events.js +0 -34
- package/lib/setup/test-file-paths.js +0 -79
- package/lib/setup/web-server.js +0 -241
- package/lib/setup/write-output-static-files.js +0 -22
- package/lib/tap/display-final-result.js +0 -15
- package/lib/tap/display-test-result.js +0 -73
- package/lib/utils/find-internal-assets-from-html.js +0 -16
- package/lib/utils/find-project-root.js +0 -17
- package/lib/utils/indent-string.js +0 -11
- package/lib/utils/listen-to-keyboard-key.js +0 -44
- package/lib/utils/parse-cli-flags.js +0 -57
- package/lib/utils/path-exists.js +0 -11
- package/lib/utils/resolve-port-number-for.js +0 -27
- package/lib/utils/run-user-module.js +0 -18
- package/lib/utils/search-in-parent-directories.js +0 -15
- package/lib/utils/time-counter.js +0 -8
- package/shims/deno-assert.js +0 -55
- package/shims/nodejs-assert.js +0 -55
package/.dockerignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node_modules
|
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/build.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
}
|
package/deno.json
CHANGED