tape-six 1.3.5 → 1.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/README.md +8 -0
- package/index.d.ts +57 -0
- package/package.json +12 -3
- package/src/OK.js +47 -0
- package/src/Tester.js +2 -2
- package/src/test.js +3 -1
- package/src/utils/config.js +9 -1
package/README.md
CHANGED
|
@@ -34,6 +34,8 @@ with existing unit test libraries:
|
|
|
34
34
|
- It just workss: modern runtimes (Node, Deno, Bun) support running TypeScript natively without transpilation by ignoring type information and running the code directly.
|
|
35
35
|
- The [DX](https://en.wikipedia.org/wiki/User_experience#Developer_experience) in browsers are usually abysmal.
|
|
36
36
|
- Both console-based debugging and a UI to navigate results are properly supported.
|
|
37
|
+
- Integration with browser automation tools is supported for automated testing.
|
|
38
|
+
- Examples for such tools are [Playwright](https://playwright.dev/) and [Puppeteer](https://pptr.dev/) are provided.
|
|
37
39
|
|
|
38
40
|
## Docs
|
|
39
41
|
|
|
@@ -230,6 +232,10 @@ The following methods are available (all `msg` arguments are optional):
|
|
|
230
232
|
- `comment(msg)` — sends a comment to the test harness. Rarely used.
|
|
231
233
|
- `skipTest(...args, msg)` — skips the current test yet sends a message to the test harness.
|
|
232
234
|
- `bailOut(msg)` — stops the test suite and sends a message to the test harness.
|
|
235
|
+
- Evaluators:
|
|
236
|
+
- `OK(condition, msg, options)` — a high-level helper for evaluating simple expressions.
|
|
237
|
+
- _Available since 1.4.0._
|
|
238
|
+
- See [Tester](https://github.com/uhop/tape-six/wiki/Tester) for description and examples.
|
|
233
239
|
|
|
234
240
|
In all cases, the `msg` message is optional. If it is not provided, some suitable generic message will be used.
|
|
235
241
|
|
|
@@ -312,6 +318,8 @@ Test output can be controlled by flags. See [Supported flags](https://github.com
|
|
|
312
318
|
|
|
313
319
|
The most recent releases:
|
|
314
320
|
|
|
321
|
+
- 1.4.1 _Added browser automation support._
|
|
322
|
+
- 1.4.0 _Added a high-level helper `OK()` for evaluating simple expressions._
|
|
315
323
|
- 1.3.5 _Minor improvements, better docs._
|
|
316
324
|
- 1.3.4 _Minor bugfixes and improvements._
|
|
317
325
|
- 1.3.3 _Added a way to hide console/streams output, better support for file tests, better TTY formatting._
|
package/index.d.ts
CHANGED
|
@@ -345,6 +345,25 @@ export declare interface Test {
|
|
|
345
345
|
*/
|
|
346
346
|
resolves(promise: Promise<unknown>, message?: string): Promise<void>;
|
|
347
347
|
|
|
348
|
+
/**
|
|
349
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
350
|
+
* @param condition - The JS condition to check as a string
|
|
351
|
+
* @param message - Message to display if the assertion fails
|
|
352
|
+
* @param options - Optional options object. `self` is the name of the tester argument, which should be used in the code. Default: `"t"`.
|
|
353
|
+
*/
|
|
354
|
+
OK(condition: string, message: string, options?: {self?: string}): string;
|
|
355
|
+
/**
|
|
356
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
357
|
+
* @param condition - The JS condition to check as a string
|
|
358
|
+
* @param options - Optional options object. `self` is the name of the tester argument, which should be used in the code. Default: `"t"`.
|
|
359
|
+
*/
|
|
360
|
+
OK(condition: string, options: {self?: string}): string;
|
|
361
|
+
/**
|
|
362
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
363
|
+
* @param condition - The JS condition to check as a string
|
|
364
|
+
*/
|
|
365
|
+
OK(condition: string): string;
|
|
366
|
+
|
|
348
367
|
// aliases
|
|
349
368
|
|
|
350
369
|
/**
|
|
@@ -601,6 +620,44 @@ export declare interface Test {
|
|
|
601
620
|
* @param message - Optional message to display if the assertion fails
|
|
602
621
|
*/
|
|
603
622
|
doesNotReject(promise: Promise<unknown>, message?: string): Promise<void>;
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
626
|
+
* @param condition - The JS condition to check as a string
|
|
627
|
+
* @param message - Message to display if the assertion fails
|
|
628
|
+
* @param options - Optional options object. `self` is the name of the tester argument, which should be used in the code. Default: `"t"`.
|
|
629
|
+
*/
|
|
630
|
+
TRUE(condition: string, message: string, options?: {self?: string}): string;
|
|
631
|
+
/**
|
|
632
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
633
|
+
* @param condition - The JS condition to check as a string
|
|
634
|
+
* @param options - Optional options object. `self` is the name of the tester argument, which should be used in the code. Default: `"t"`.
|
|
635
|
+
*/
|
|
636
|
+
TRUE(condition: string, options: {self?: string}): string;
|
|
637
|
+
/**
|
|
638
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
639
|
+
* @param condition - The JS condition to check as a string
|
|
640
|
+
*/
|
|
641
|
+
TRUE(condition: string): string;
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
645
|
+
* @param condition - The JS condition to check as a string
|
|
646
|
+
* @param message - Message to display if the assertion fails
|
|
647
|
+
* @param options - Optional options object. `self` is the name of the tester argument, which should be used in the code. Default: `"t"`.
|
|
648
|
+
*/
|
|
649
|
+
ASSERT(condition: string, message: string, options?: {self?: string}): string;
|
|
650
|
+
/**
|
|
651
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
652
|
+
* @param condition - The JS condition to check as a string
|
|
653
|
+
* @param options - Optional options object. `self` is the name of the tester argument, which should be used in the code. Default: `"t"`.
|
|
654
|
+
*/
|
|
655
|
+
ASSERT(condition: string, options: {self?: string}): string;
|
|
656
|
+
/**
|
|
657
|
+
* Returns a code as a string for evaluation that checks if the condition is truthy.
|
|
658
|
+
* @param condition - The JS condition to check as a string
|
|
659
|
+
*/
|
|
660
|
+
ASSERT(condition: string): string;
|
|
604
661
|
}
|
|
605
662
|
|
|
606
663
|
export declare interface Test {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tape-six",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "TAP the test harness for the modern JavaScript (ES6).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"test": "node ./bin/tape6.js --flags FO",
|
|
29
29
|
"test:bun": "bun run ./bin/tape6-bun.js --flags FO",
|
|
30
30
|
"test:deno": "deno run -A ./bin/tape6-deno.js --flags FO",
|
|
31
|
-
"test:
|
|
31
|
+
"test:puppeteer": "node tests/puppeteer-chrome.js",
|
|
32
|
+
"test:playwright": "node tests/playwright-chrome.js",
|
|
32
33
|
"ts-check": "tsc --noEmit",
|
|
33
34
|
"ts-test": "node ./bin/tape6.js --flags FO '/ts-tests/test-*.ts'",
|
|
34
35
|
"ts-test:bun": "bun run ./bin/tape6-bun.js --flags FO '/ts-tests/test-*.ts'",
|
|
@@ -61,7 +62,14 @@
|
|
|
61
62
|
],
|
|
62
63
|
"tape6": {
|
|
63
64
|
"tests": [
|
|
64
|
-
"/tests/test
|
|
65
|
+
"/tests/test-*.js",
|
|
66
|
+
"/tests/test-*.mjs"
|
|
67
|
+
],
|
|
68
|
+
"cli": [
|
|
69
|
+
"/tests/test-*.cjs"
|
|
70
|
+
],
|
|
71
|
+
"browser": [
|
|
72
|
+
"/tests/web/test-*.html"
|
|
65
73
|
],
|
|
66
74
|
"importmap": {
|
|
67
75
|
"imports": {
|
|
@@ -72,6 +80,7 @@
|
|
|
72
80
|
},
|
|
73
81
|
"devDependencies": {
|
|
74
82
|
"@types/node": "^25.0.9",
|
|
83
|
+
"playwright": "^1.57.0",
|
|
75
84
|
"puppeteer": "^24.35.0",
|
|
76
85
|
"typescript": "^5.9.3"
|
|
77
86
|
}
|
package/src/OK.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {Tester, setAliases} from './Tester.js';
|
|
2
|
+
|
|
3
|
+
// code mostly borrowed from https://github.com/heya/ice/blob/master/assert.js under BSD-3
|
|
4
|
+
|
|
5
|
+
const listVariables = (code, self) => {
|
|
6
|
+
const vars =
|
|
7
|
+
code
|
|
8
|
+
.replace(
|
|
9
|
+
/(?:\b[A-Z]|\.[a-zA-Z_$])[a-zA-Z_$\d]*\b|\b[a-zA-Z_$][a-zA-Z_$\d]*:|\b(?:function|return|if|else|switch|case|while|for|do|break|continue|var|try|catch|finally|throw|with|debugger|default|this|true|false|null|undefined|typeof|instanceof|in|delete|new|void|arguments|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|escape|eval|isFinite|isNaN|parseFloat|parseInt|unescape|window|document)\b|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g,
|
|
10
|
+
''
|
|
11
|
+
)
|
|
12
|
+
.match(/(\b[a-z_$][a-z_$\d]*\b)/gi) || [];
|
|
13
|
+
const result = [],
|
|
14
|
+
resultSet = {};
|
|
15
|
+
for (const name of vars) {
|
|
16
|
+
const key = '-' + name;
|
|
17
|
+
if (name != self && !resultSet[key]) {
|
|
18
|
+
result.push("'" + name + "':" + name);
|
|
19
|
+
resultSet[key] = 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return '{' + result.join(',') + '}';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
Tester.prototype.OK = function OK(condition, msg, options) {
|
|
26
|
+
if (typeof condition != 'string') {
|
|
27
|
+
throw new TypeError('Condition must be a string');
|
|
28
|
+
}
|
|
29
|
+
if (typeof msg == 'object') {
|
|
30
|
+
options = msg;
|
|
31
|
+
msg = undefined;
|
|
32
|
+
}
|
|
33
|
+
const {self = 't'} = options || {};
|
|
34
|
+
return `(${self}.state.emit({
|
|
35
|
+
name: ${JSON.stringify(msg || condition)},
|
|
36
|
+
test: ${self}.testNumber,
|
|
37
|
+
marker: new Error(),
|
|
38
|
+
time: ${self}.state.timer.now(),
|
|
39
|
+
operator: 'ok',
|
|
40
|
+
fail: !(${condition}),
|
|
41
|
+
data: {
|
|
42
|
+
actual: ${listVariables(condition, self)}
|
|
43
|
+
}
|
|
44
|
+
}))`;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
setAliases('OK', 'TRUE, ASSERT');
|
package/src/Tester.js
CHANGED
|
@@ -9,7 +9,7 @@ const throwHelper = fn => {
|
|
|
9
9
|
return null;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
class Tester {
|
|
12
|
+
export class Tester {
|
|
13
13
|
constructor(state, testNumber) {
|
|
14
14
|
this.state = state;
|
|
15
15
|
this.testNumber = testNumber;
|
|
@@ -400,7 +400,7 @@ class Tester {
|
|
|
400
400
|
}
|
|
401
401
|
Tester.prototype.any = Tester.prototype._ = any;
|
|
402
402
|
|
|
403
|
-
const setAliases = (source, aliases) =>
|
|
403
|
+
export const setAliases = (source, aliases) =>
|
|
404
404
|
aliases.split(', ').forEach(alias => (Tester.prototype[alias] = Tester.prototype[source]));
|
|
405
405
|
|
|
406
406
|
setAliases('ok', 'true, assert');
|
package/src/test.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {selectTimer} from './utils/timer.js';
|
|
2
2
|
import State, {StopTest} from './State.js';
|
|
3
|
-
import Tester from './Tester.js';
|
|
4
3
|
import getDeferred from './utils/getDeferred.js';
|
|
5
4
|
import timeout from './utils/timeout.js';
|
|
6
5
|
import {formatTime} from './utils/formatters.js';
|
|
7
6
|
import defer from './utils/defer.js';
|
|
8
7
|
|
|
8
|
+
import Tester from './Tester.js';
|
|
9
|
+
import './OK.js';
|
|
10
|
+
|
|
9
11
|
let tests = [],
|
|
10
12
|
reporter = null,
|
|
11
13
|
testCounter = 0,
|
package/src/utils/config.js
CHANGED
|
@@ -37,7 +37,7 @@ export const getConfig = async (rootFolder, traceFn) => {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// check well-known files
|
|
40
|
-
if (!cfg) cfg = {tests: ['/tests/test
|
|
40
|
+
if (!cfg) cfg = {tests: ['/tests/test-*.js', '/tests/test-*.mjs'], cli: ['/tests/test-*.cjs']};
|
|
41
41
|
|
|
42
42
|
return cfg;
|
|
43
43
|
};
|
|
@@ -55,6 +55,14 @@ export const resolveTests = async (rootFolder, type, traceFn) => {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
if (type !== 'browser') {
|
|
59
|
+
if (Array.isArray(cfg.cli)) {
|
|
60
|
+
patterns = patterns.concat(cfg.cli);
|
|
61
|
+
} else if (typeof cfg.cli == 'string') {
|
|
62
|
+
patterns.push(cfg.cli);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
58
66
|
if (Array.isArray(cfg.tests)) {
|
|
59
67
|
patterns = patterns.concat(cfg.tests);
|
|
60
68
|
} else if (typeof cfg.tests == 'string') {
|