supertape 7.7.1 → 8.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.
package/ChangeLog CHANGED
@@ -1,3 +1,28 @@
1
+ 2022.09.07, v8.0.0
2
+
3
+ fix:
4
+ - @supertape/formatter-short: drop support of node < 16
5
+ - @supertape/formatter-tap: drop support of node < 16
6
+ - @supertape/formatter-tap: get back commonjs, since @supertape/formatter-fail is commonjs
7
+
8
+ feature:
9
+ - package: @supertape/formatter-progress-bar v3.0.0
10
+ - formatters: convert to ESM
11
+ - supertape: add ability to use 'createFormatter()' to create formatters
12
+ - @putout/formatter-progress-bar: convert to ESM
13
+ - package: @supertape/formatter-fail v3.0.0
14
+ - @supertape/formatter-json-lines: drop support of node < 16
15
+ - @supertape/formatter-fail: drop support of node < 16
16
+ - package: @supertape/formatter-tap v3.0.1
17
+ - package: @supertape/formatter-json-lines v2.0.0
18
+ - package: @supertape/formatter-short v2.0.0
19
+ - package: @supertape/formatter-tap v3.0.0
20
+ - @supertape/formatter-short: convert to ESM
21
+ - @supertape/formatter-tap: convert to ESM
22
+ - @supertape/formatter-json-lines: convert to ESM
23
+ - supertape: add support of ESM formatters
24
+ - supertape: actual -> result
25
+
1
26
  2022.08.29, v7.7.1
2
27
 
3
28
  feature:
package/README.md CHANGED
@@ -21,6 +21,7 @@ and has a couple differences. It contains:
21
21
  - as many `only` as you wish;
22
22
  - ability to extend;
23
23
  - smart timeouts for long running tests 🏃‍♂️(configured with `SUPERTAPE_TIMEOUT`);
24
+ - outputs `result` instead of `actual`;
24
25
  - more natural assertions: `expected, result` -> `result, expected`, for example:
25
26
 
26
27
  ```js
@@ -196,31 +197,31 @@ Assert that `value` is truthy with an optional description of the assertion `msg
196
197
 
197
198
  Assert that `value` is falsy with an optional description of the assertion `msg`.
198
199
 
199
- ## t.match(actual, pattern[, msg])
200
+ ## t.match(result, pattern[, msg])
200
201
 
201
- Assert that `pattern: string | regexp` matches `actual` with an optional description of the assertion `msg`.
202
+ Assert that `pattern: string | regexp` matches `result` with an optional description of the assertion `msg`.
202
203
 
203
- ## t.notMatch(actual, pattern[, msg])
204
+ ## t.notMatch(result, pattern[, msg])
204
205
 
205
- Assert that `pattern: string | regexp` not matches `actual` with an optional description of the assertion `msg`.
206
+ Assert that `pattern: string | regexp` not matches `result` with an optional description of the assertion `msg`.
206
207
 
207
- ## t.equal(actual, expected, msg)
208
+ ## t.equal(result, expected, msg)
208
209
 
209
- Assert that `Object.is(actual, expected)` with an optional description of the assertion `msg`.
210
+ Assert that `Object.is(result, expected)` with an optional description of the assertion `msg`.
210
211
 
211
- ## t.notEqual(actual, expected, msg)
212
+ ## t.notEqual(result, expected, msg)
212
213
 
213
- Assert that `!Object.is(actual, expected)` with an optional description of the assertion `msg`.
214
+ Assert that `!Object.is(result, expected)` with an optional description of the assertion `msg`.
214
215
 
215
- ## t.deepEqual(actual, expected, msg)
216
+ ## t.deepEqual(result, expected, msg)
216
217
 
217
- Assert that `actual` and `expected` have the same structure and nested values using
218
+ Assert that `result` and `expected` have the same structure and nested values using
218
219
  [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal)
219
220
  with strict comparisons (`===`) on leaf nodes and an optional description of the assertion `msg`.
220
221
 
221
- ## t.notDeepEqual(actual, expected, msg)
222
+ ## t.notDeepEqual(result, expected, msg)
222
223
 
223
- Assert that `actual` and `expected` do not have the same structure and nested values using
224
+ Assert that `result` and `expected` do not have the same structure and nested values using
224
225
  [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal)
225
226
  with strict comparisons (`===`) on leaf nodes and an optional description of the assertion `msg`.
226
227
 
package/lib/cli.js CHANGED
@@ -169,7 +169,9 @@ async function cli({argv, cwd, stdout, isStop}) {
169
169
  checkAssertionsCount,
170
170
  });
171
171
 
172
- supertape.createStream().pipe(stdout);
172
+ const stream = await supertape.createStream();
173
+
174
+ stream.pipe(stdout);
173
175
 
174
176
  const promises = [];
175
177
  const files = removeDuplicates(allFiles);
@@ -40,7 +40,7 @@ function prepare(reporter) {
40
40
  success: stub,
41
41
  comment: stub,
42
42
  end: stub,
43
- ...reporter,
43
+ ...reporter.createFormatter?.() || reporter,
44
44
  });
45
45
 
46
46
  return result;
@@ -3,11 +3,12 @@
3
3
  const {EventEmitter} = require('events');
4
4
  const {createHarness} = require('./harness');
5
5
 
6
- const resolveFormatter = (name) => require(`@supertape/formatter-${name}`);
6
+ const resolveFormatter = async (name) => await import(`@supertape/formatter-${name}`);
7
+ const isString = (a) => typeof a === 'string';
7
8
 
8
- module.exports.createFormatter = (name) => {
9
+ module.exports.createFormatter = async (name) => {
9
10
  const formatter = new EventEmitter();
10
- const harness = createHarness(resolveFormatter(name));
11
+ const harness = createHarness(!isString(name) ? name : await resolveFormatter(name));
11
12
 
12
13
  formatter.on('start', ({total}) => {
13
14
  harness.write({
@@ -48,14 +49,14 @@ module.exports.createFormatter = (name) => {
48
49
  });
49
50
  });
50
51
 
51
- formatter.on('test:fail', ({at, count, message, operator, actual, expected, output, errorStack}) => {
52
+ formatter.on('test:fail', ({at, count, message, operator, result, expected, output, errorStack}) => {
52
53
  harness.write({
53
54
  type: 'fail',
54
55
  at,
55
56
  count,
56
57
  message,
57
58
  operator,
58
- actual,
59
+ result,
59
60
  expected,
60
61
  output,
61
62
  errorStack,
package/lib/operators.mjs CHANGED
@@ -16,17 +16,17 @@ const isObj = (a) => typeof a === 'object';
16
16
 
17
17
  const end = () => {};
18
18
 
19
- const ok = (actual, message = 'should be truthy') => ({
20
- is: Boolean(actual),
19
+ const ok = (result, message = 'should be truthy') => ({
20
+ is: Boolean(result),
21
21
  expected: true,
22
- actual,
22
+ result,
23
23
  message,
24
24
  });
25
25
 
26
- const notOk = (actual, message = 'should be falsy') => ({
27
- is: !actual,
26
+ const notOk = (result, message = 'should be falsy') => ({
27
+ is: !result,
28
28
  expected: false,
29
- actual: actual && stringify(actual),
29
+ result: result && stringify(result),
30
30
  message,
31
31
  });
32
32
 
@@ -42,56 +42,56 @@ const validateRegExp = (regexp) => {
42
42
 
43
43
  const {stringify} = JSON;
44
44
 
45
- function match(actual, regexp, message = 'should match') {
45
+ function match(result, regexp, message = 'should match') {
46
46
  const error = validateRegExp(regexp);
47
47
 
48
48
  if (error)
49
49
  return fail(error);
50
50
 
51
- const is = maybeRegExp(regexp).test(actual);
51
+ const is = maybeRegExp(regexp).test(result);
52
52
 
53
53
  return {
54
54
  is,
55
- actual,
55
+ result,
56
56
  expected: regexp,
57
57
  message,
58
58
  };
59
59
  }
60
60
 
61
- function notMatch(actual, regexp, message = 'should not match') {
62
- const {is} = match(actual, regexp, message);
61
+ function notMatch(result, regexp, message = 'should not match') {
62
+ const {is} = match(result, regexp, message);
63
63
 
64
64
  return {
65
65
  is: !is,
66
- actual,
66
+ result,
67
67
  expected: regexp,
68
68
  message,
69
69
  };
70
70
  }
71
71
 
72
- function equal(actual, expected, message = 'should equal') {
72
+ function equal(result, expected, message = 'should equal') {
73
73
  let output = '';
74
- const is = Object.is(actual, expected);
74
+ const is = Object.is(result, expected);
75
75
 
76
76
  if (!is)
77
- output = diff(expected, actual) || ' result: values not equal, but deepEqual';
77
+ output = diff(expected, result) || ' result: values not equal, but deepEqual';
78
78
 
79
79
  return {
80
80
  is,
81
- actual,
81
+ result,
82
82
  expected,
83
83
  message,
84
84
  output,
85
85
  };
86
86
  }
87
87
 
88
- function notEqual(actual, expected, message = 'should not equal') {
89
- const is = !Object.is(actual, expected);
90
- const output = is ? '' : diff(expected, actual);
88
+ function notEqual(result, expected, message = 'should not equal') {
89
+ const is = !Object.is(result, expected);
90
+ const output = is ? '' : diff(expected, result);
91
91
 
92
92
  return {
93
93
  is,
94
- actual,
94
+ result,
95
95
  expected,
96
96
  message,
97
97
  output,
@@ -112,26 +112,26 @@ const fail = (error, at) => ({
112
112
  at,
113
113
  });
114
114
 
115
- const deepEqual = (actual, expected, message = 'should deep equal') => {
116
- const is = deepEqualCheck(actual, expected);
117
- const output = is ? '' : diff(expected, actual);
115
+ const deepEqual = (result, expected, message = 'should deep equal') => {
116
+ const is = deepEqualCheck(result, expected);
117
+ const output = is ? '' : diff(expected, result);
118
118
 
119
119
  return {
120
120
  is: is || !output,
121
- actual,
121
+ result,
122
122
  expected,
123
123
  message,
124
124
  output,
125
125
  };
126
126
  };
127
127
 
128
- const notDeepEqual = (actual, expected, message = 'should not deep equal') => {
129
- const is = !deepEqualCheck(actual, expected);
130
- const output = is ? '' : diff(expected, actual);
128
+ const notDeepEqual = (result, expected, message = 'should not deep equal') => {
129
+ const is = !deepEqualCheck(result, expected);
130
+ const output = is ? '' : diff(expected, result);
131
131
 
132
132
  return {
133
133
  is,
134
- actual,
134
+ result,
135
135
  expected,
136
136
  message,
137
137
  output,
@@ -245,7 +245,7 @@ function run(name, {formatter, count, incCount, incPassed, incFailed}, testState
245
245
  is,
246
246
  message,
247
247
  expected,
248
- actual,
248
+ result,
249
249
  output,
250
250
  stack,
251
251
  at,
@@ -272,7 +272,7 @@ function run(name, {formatter, count, incCount, incPassed, incFailed}, testState
272
272
  count: count(),
273
273
  message,
274
274
  operator: name,
275
- actual,
275
+ result,
276
276
  expected,
277
277
  output,
278
278
  errorStack: formatOutput(errorStack),
@@ -5,30 +5,30 @@ import {
5
5
  Stub,
6
6
  } from '@cloudcmd/stub';
7
7
 
8
- type Result = {
8
+ type OperationResult = {
9
9
  is: boolean,
10
10
  expected: unknown,
11
- actual: unknown,
11
+ result: unknown,
12
12
  message: string,
13
13
  output: string,
14
14
  };
15
15
 
16
16
  type Operator = {
17
- [index: string]: (...args: any[]) => Result
17
+ [index: string]: (...args: any[]) => OperationResult;
18
18
  };
19
19
 
20
20
  type Test = Operator & OperatorStub & {
21
- equal: (result: unknown, expected: unknown, message?: string) => Result;
22
- notEqual: (result: unknown, expected: unknown, message?: string) => Result;
23
- deepEqual: (result: unknown, expected: unknown, message?: string) => Result;
24
- notDeepEqual: (result: unknown, expected: unknown, message?: string) => Result;
25
- fail: (message: string) => Result;
26
- pass: (message: string) => Result;
27
- ok: (result: boolean | unknown, message?: string) => Result;
28
- comment: (message: string) => Result;
29
- notOk: (result: boolean | unknown, message?: string) => Result;
30
- match: (result: string, pattern: string | RegExp, message?: string) => Result;
31
- notMatch: (result: string, pattern: string | RegExp, message?: string) => Result;
21
+ equal: (result: unknown, expected: unknown, message?: string) => OperationResult;
22
+ notEqual: (result: unknown, expected: unknown, message?: string) => OperationResult;
23
+ deepEqual: (result: unknown, expected: unknown, message?: string) => OperationResult;
24
+ notDeepEqual: (result: unknown, expected: unknown, message?: string) => OperationResult;
25
+ fail: (message: string) => OperationResult;
26
+ pass: (message: string) => OperationResult;
27
+ ok: (result: boolean | unknown, message?: string) => OperationResult;
28
+ comment: (message: string) => OperationResult;
29
+ notOk: (result: boolean | unknown, message?: string) => OperationResult;
30
+ match: (result: string, pattern: string | RegExp, message?: string) => OperationResult;
31
+ notMatch: (result: string, pattern: string | RegExp, message?: string) => OperationResult;
32
32
  end: () => void;
33
33
  };
34
34
 
@@ -47,7 +47,7 @@ declare namespace test {
47
47
  export default test;
48
48
 
49
49
  type CustomOperator = {
50
- [index: string]: (operator: Operator) => (...args: any[]) => Result
50
+ [index: string]: (operator: Operator) => (...args: any[]) => OperationResult
51
51
  };
52
52
 
53
53
  declare function extend(customOperator: CustomOperator): typeof test;
package/lib/supertape.js CHANGED
@@ -1,13 +1,16 @@
1
1
  'use strict';
2
2
 
3
3
  const {EventEmitter} = require('events');
4
+ const {PassThrough} = require('stream');
5
+
4
6
  const once = require('once');
5
7
 
6
8
  const options = require('../supertape.json');
7
9
 
8
10
  const {getAt, setValidations} = require('./validator');
9
11
  const runTests = require('./run-tests');
10
- const createFormatter = once(require('./formatter').createFormatter);
12
+ const _createFormatter = require('./formatter').createFormatter;
13
+ const createFormatter = once(_createFormatter);
11
14
 
12
15
  const createEmitter = once(_createEmitter);
13
16
 
@@ -38,7 +41,7 @@ const defaultOptions = {
38
41
  checkScopes: true,
39
42
  };
40
43
 
41
- function _createEmitter({quiet, format, getOperators, isStop}) {
44
+ function _createEmitter({quiet, stream = stdout, format, getOperators, isStop, readyFormatter}) {
42
45
  const tests = [];
43
46
  const emitter = new EventEmitter();
44
47
 
@@ -62,10 +65,10 @@ function _createEmitter({quiet, format, getOperators, isStop}) {
62
65
  });
63
66
 
64
67
  emitter.on('run', async () => {
65
- const {harness, formatter} = createFormatter(format);
68
+ const {harness, formatter} = readyFormatter || await createFormatter(format);
66
69
 
67
70
  if (!quiet)
68
- harness.pipe(stdout);
71
+ harness.pipe(stream);
69
72
 
70
73
  const operators = await getOperators();
71
74
  const result = await runTests(tests, {
@@ -90,14 +93,45 @@ module.exports.init = (options) => {
90
93
  assign(initedOptions, options);
91
94
  };
92
95
 
93
- const createStream = () => {
96
+ const createStream = async () => {
94
97
  const {format} = initedOptions;
95
- const {harness} = createFormatter(format);
98
+ const {harness} = await createFormatter(format);
96
99
 
97
100
  return harness;
98
101
  };
99
102
 
100
103
  module.exports.createStream = createStream;
104
+ module.exports.createTest = async (testOptions = {}) => {
105
+ const {format = 'tap', formatter} = testOptions;
106
+ const readyFormatter = await _createFormatter(formatter || format);
107
+
108
+ const stream = new PassThrough();
109
+ const emitter = _createEmitter({
110
+ ...defaultOptions,
111
+ ...testOptions,
112
+ readyFormatter,
113
+ stream,
114
+ });
115
+
116
+ const fn = (message, fn, options = {}) => {
117
+ return test(message, fn, {
118
+ ...testOptions,
119
+ ...options,
120
+ emitter,
121
+ });
122
+ };
123
+
124
+ assign(fn, {
125
+ stream,
126
+ ...test,
127
+ test: fn,
128
+ run: () => {
129
+ emitter.emit('run');
130
+ },
131
+ });
132
+
133
+ return fn;
134
+ };
101
135
 
102
136
  function test(message, fn, options = {}) {
103
137
  const {
@@ -130,7 +164,7 @@ function test(message, fn, options = {}) {
130
164
 
131
165
  const at = getAt();
132
166
 
133
- const emitter = createEmitter({
167
+ const emitter = options.emitter || createEmitter({
134
168
  format,
135
169
  quiet,
136
170
  getOperators,
package/lib/supertape.mjs CHANGED
@@ -1,6 +1,13 @@
1
1
  import test from './supertape.js';
2
2
 
3
- const {extend, stub} = test;
3
+ const {
4
+ extend,
5
+ stub,
6
+ createStream,
7
+ init,
8
+ run,
9
+ createTest,
10
+ } = test;
4
11
 
5
12
  export default test;
6
13
 
@@ -8,4 +15,8 @@ export {
8
15
  extend,
9
16
  test,
10
17
  stub,
18
+ createStream,
19
+ init,
20
+ run,
21
+ createTest,
11
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supertape",
3
- "version": "7.7.1",
3
+ "version": "8.0.0",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "📼 Supertape simplest high speed test runner with superpowers",
6
6
  "homepage": "http://github.com/coderaiser/supertape",
@@ -44,11 +44,11 @@
44
44
  "@putout/cli-keypress": "^1.0.0",
45
45
  "@putout/cli-validate-args": "^1.0.1",
46
46
  "@supertape/engine-loader": "^1.0.0",
47
- "@supertape/formatter-fail": "^2.0.0",
48
- "@supertape/formatter-json-lines": "^1.0.0",
49
- "@supertape/formatter-progress-bar": "^2.0.0",
50
- "@supertape/formatter-short": "^1.0.0",
51
- "@supertape/formatter-tap": "^2.0.0",
47
+ "@supertape/formatter-fail": "^3.0.0",
48
+ "@supertape/formatter-json-lines": "^2.0.0",
49
+ "@supertape/formatter-progress-bar": "^3.0.0",
50
+ "@supertape/formatter-short": "^2.0.0",
51
+ "@supertape/formatter-tap": "^3.0.0",
52
52
  "@supertape/operator-stub": "^2.0.0",
53
53
  "cli-progress": "^3.8.2",
54
54
  "deep-equal": "^2.0.3",