ava 3.3.0 → 3.4.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/index.d.ts +1 -8
- package/lib/assert.js +2 -2
- package/lib/beautify-stack.js +1 -1
- package/lib/load-config.js +5 -34
- package/lib/test.js +6 -8
- package/lib/worker/subprocess.js +17 -13
- package/package.json +8 -9
- package/lib/esm-probe.mjs +0 -2
package/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node"/>
|
|
2
|
-
|
|
3
1
|
export interface Subscribable {
|
|
4
2
|
subscribe(observer: {
|
|
5
3
|
error(err: any): void,
|
|
@@ -247,16 +245,11 @@ export interface SnapshotAssertion {
|
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
export interface ThrowsAssertion {
|
|
250
|
-
/**
|
|
251
|
-
* Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
|
|
252
|
-
*/
|
|
253
|
-
<ThrownError extends Error>(fn: () => any, expectations?: null, message?: string): ThrownError;
|
|
254
|
-
|
|
255
248
|
/**
|
|
256
249
|
* Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
|
|
257
250
|
* The error must satisfy all expectations.
|
|
258
251
|
*/
|
|
259
|
-
<ThrownError extends Error>(fn: () => any, expectations
|
|
252
|
+
<ThrownError extends Error>(fn: () => any, expectations?: ThrowsExpectation | null, message?: string): ThrownError;
|
|
260
253
|
|
|
261
254
|
/** Skip this assertion. */
|
|
262
255
|
skip(fn: () => any, expectations?: any, message?: string): void;
|
package/lib/assert.js
CHANGED
|
@@ -73,7 +73,7 @@ function getErrorWithLongStackTrace() {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function validateExpectations(assertion, expectations, numArgs) { // eslint-disable-line complexity
|
|
76
|
-
if (numArgs === 1 || expectations === null) {
|
|
76
|
+
if (numArgs === 1 || expectations === null || expectations === undefined) {
|
|
77
77
|
expectations = {};
|
|
78
78
|
} else if (
|
|
79
79
|
typeof expectations === 'function' ||
|
|
@@ -85,7 +85,7 @@ function validateExpectations(assertion, expectations, numArgs) { // eslint-disa
|
|
|
85
85
|
) {
|
|
86
86
|
throw new AssertionError({
|
|
87
87
|
assertion,
|
|
88
|
-
message: `The second argument to \`t.${assertion}()\` must be an expectation object or \`
|
|
88
|
+
message: `The second argument to \`t.${assertion}()\` must be an expectation object, \`null\` or \`undefined\``,
|
|
89
89
|
values: [formatWithLabel('Called with:', expectations)]
|
|
90
90
|
});
|
|
91
91
|
} else {
|
package/lib/beautify-stack.js
CHANGED
|
@@ -8,7 +8,7 @@ let ignoreStackLines = [];
|
|
|
8
8
|
|
|
9
9
|
const avaInternals = /\/ava\/(?:lib\/|lib\/worker\/)?[\w-]+\.js:\d+:\d+\)?$/;
|
|
10
10
|
const avaDependencies = /\/node_modules\/(?:@ava\/babel|@ava\/require-precompiled|append-transform|empower-core|nyc|require-precompiled|(?:ava\/node_modules\/)?(?:babel-runtime|core-js))\//;
|
|
11
|
-
const stackFrameLine = /^.+( \(.+:\d+:\d+\)|:\d+:\d+)$/;
|
|
11
|
+
const stackFrameLine = /^.+( \(.+:\d+:\d+\)|:\d+:\d+)$/;
|
|
12
12
|
|
|
13
13
|
if (!debug.enabled) {
|
|
14
14
|
ignoreStackLines = StackUtils.nodeInternals();
|
package/lib/load-config.js
CHANGED
|
@@ -7,42 +7,17 @@ const pkgConf = require('pkg-conf');
|
|
|
7
7
|
|
|
8
8
|
const NO_SUCH_FILE = Symbol('no ava.config.js file');
|
|
9
9
|
const MISSING_DEFAULT_EXPORT = Symbol('missing default export');
|
|
10
|
-
const EXPERIMENTS = new Set(
|
|
11
|
-
|
|
12
|
-
class LegacyCommonJsAccessError extends Error {
|
|
13
|
-
constructor(thing, fileForErrorMessage) {
|
|
14
|
-
super(`${thing} is not available in ${fileForErrorMessage}. Use a .cjs file instead`);
|
|
15
|
-
this.name = 'LegacyCommonJsAccessError';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
10
|
+
const EXPERIMENTS = new Set();
|
|
18
11
|
|
|
19
12
|
// *Very* rudimentary support for loading ava.config.js files containing an `export default` statement.
|
|
20
|
-
const evaluateJsConfig =
|
|
13
|
+
const evaluateJsConfig = configFile => {
|
|
21
14
|
const contents = fs.readFileSync(configFile, 'utf8');
|
|
22
15
|
const script = new vm.Script(`'use strict';(()=>{let __export__;\n${contents.replace(/export default/g, '__export__ =')};return __export__;})()`, {
|
|
23
16
|
filename: configFile,
|
|
24
17
|
lineOffset: -1
|
|
25
18
|
});
|
|
26
19
|
return {
|
|
27
|
-
default: script.
|
|
28
|
-
console,
|
|
29
|
-
process,
|
|
30
|
-
get __dirname() {
|
|
31
|
-
throw new LegacyCommonJsAccessError('__dirname', fileForErrorMessage);
|
|
32
|
-
},
|
|
33
|
-
get __filename() {
|
|
34
|
-
throw new LegacyCommonJsAccessError('__filename', fileForErrorMessage);
|
|
35
|
-
},
|
|
36
|
-
get module() {
|
|
37
|
-
throw new LegacyCommonJsAccessError('module', fileForErrorMessage);
|
|
38
|
-
},
|
|
39
|
-
get exports() {
|
|
40
|
-
throw new LegacyCommonJsAccessError('exports', fileForErrorMessage);
|
|
41
|
-
},
|
|
42
|
-
get require() {
|
|
43
|
-
throw new LegacyCommonJsAccessError('require()', fileForErrorMessage);
|
|
44
|
-
}
|
|
45
|
-
})
|
|
20
|
+
default: script.runInThisContext()
|
|
46
21
|
};
|
|
47
22
|
};
|
|
48
23
|
|
|
@@ -55,17 +30,13 @@ const loadJsConfig = ({projectDir, configFile = path.join(projectDir, 'ava.confi
|
|
|
55
30
|
|
|
56
31
|
let config;
|
|
57
32
|
try {
|
|
58
|
-
({default: config = MISSING_DEFAULT_EXPORT} = evaluateJsConfig(configFile
|
|
33
|
+
({default: config = MISSING_DEFAULT_EXPORT} = evaluateJsConfig(configFile));
|
|
59
34
|
} catch (error) {
|
|
60
35
|
if (error.code === 'ENOENT') {
|
|
61
36
|
return null;
|
|
62
37
|
}
|
|
63
38
|
|
|
64
|
-
|
|
65
|
-
throw error;
|
|
66
|
-
} else {
|
|
67
|
-
throw Object.assign(new Error(`Error loading ${fileForErrorMessage}`), {parent: error});
|
|
68
|
-
}
|
|
39
|
+
throw Object.assign(new Error(`Error loading ${fileForErrorMessage}: ${error.message}`), {parent: error});
|
|
69
40
|
}
|
|
70
41
|
|
|
71
42
|
if (config === MISSING_DEFAULT_EXPORT) {
|
package/lib/test.js
CHANGED
|
@@ -69,22 +69,20 @@ class ExecutionContext extends assert.Assertions {
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
this.try = async (...attemptArgs) => {
|
|
72
|
-
if (test.experiments.tryAssertion !== true) {
|
|
73
|
-
throw new Error('t.try() is currently an experiment. Opt in by setting `nonSemVerExperiments.tryAssertion` to `true`.');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
72
|
const {args, buildTitle, implementations, receivedImplementationArray} = parseTestArgs(attemptArgs);
|
|
77
73
|
|
|
78
74
|
if (implementations.length === 0) {
|
|
79
75
|
throw new TypeError('Expected an implementation.');
|
|
80
76
|
}
|
|
81
77
|
|
|
82
|
-
const attemptPromises = implementations.map(implementation => {
|
|
78
|
+
const attemptPromises = implementations.map((implementation, index) => {
|
|
83
79
|
let {title, isSet, isValid, isEmpty} = buildTitle(implementation);
|
|
84
80
|
|
|
85
81
|
if (!isSet || isEmpty) {
|
|
86
|
-
title = `${test.title}
|
|
87
|
-
} else if (
|
|
82
|
+
title = `${test.title} ─ attempt ${test.attemptCount + 1 + index}`;
|
|
83
|
+
} else if (isValid) {
|
|
84
|
+
title = `${test.title} ─ ${title}`;
|
|
85
|
+
} else {
|
|
88
86
|
throw new TypeError('`t.try()` titles must be strings'); // Throw synchronously!
|
|
89
87
|
}
|
|
90
88
|
|
|
@@ -594,7 +592,7 @@ class Test {
|
|
|
594
592
|
if (this.metadata.callback) {
|
|
595
593
|
if (returnedObservable || returnedPromise) {
|
|
596
594
|
const asyncType = returnedObservable ? 'observables' : 'promises';
|
|
597
|
-
this.saveFirstError(new Error(`Do not return ${asyncType} from tests declared via \`test.cb(...)
|
|
595
|
+
this.saveFirstError(new Error(`Do not return ${asyncType} from tests declared via \`test.cb(...)\`. Use \`test.cb(...)\` for legacy callback APIs. When using promises, observables or async functions, use \`test(...)\`.`));
|
|
598
596
|
return this.finishPromised();
|
|
599
597
|
}
|
|
600
598
|
|
package/lib/worker/subprocess.js
CHANGED
|
@@ -6,6 +6,15 @@ require('./ensure-forked'); // eslint-disable-line import/no-unassigned-import
|
|
|
6
6
|
|
|
7
7
|
const ipc = require('./ipc');
|
|
8
8
|
|
|
9
|
+
const supportsESM = async () => {
|
|
10
|
+
try {
|
|
11
|
+
await import('data:text/javascript,');
|
|
12
|
+
return true;
|
|
13
|
+
} catch {}
|
|
14
|
+
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
|
|
9
18
|
ipc.send({type: 'ready-for-options'});
|
|
10
19
|
ipc.options.then(async options => {
|
|
11
20
|
require('./options').set(options);
|
|
@@ -134,23 +143,18 @@ ipc.options.then(async options => {
|
|
|
134
143
|
return null;
|
|
135
144
|
}).filter(provider => provider !== null);
|
|
136
145
|
|
|
137
|
-
// Lazily determine support since this prints an experimental warning.
|
|
138
|
-
let supportsESM = async () => {
|
|
139
|
-
try {
|
|
140
|
-
await import('../esm-probe.mjs');
|
|
141
|
-
supportsESM = async () => true;
|
|
142
|
-
} catch {
|
|
143
|
-
supportsESM = async () => false;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return supportsESM();
|
|
147
|
-
};
|
|
148
|
-
|
|
149
146
|
let requireFn = require;
|
|
147
|
+
let isESMSupported;
|
|
150
148
|
const load = async ref => {
|
|
151
149
|
for (const extension of extensionsToLoadAsModules) {
|
|
152
150
|
if (ref.endsWith(`.${extension}`)) {
|
|
153
|
-
if (
|
|
151
|
+
if (typeof isESMSupported !== 'boolean') {
|
|
152
|
+
// Lazily determine support since this prints an experimental warning.
|
|
153
|
+
// eslint-disable-next-line no-await-in-loop
|
|
154
|
+
isESMSupported = await supportsESM();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (isESMSupported) {
|
|
154
158
|
return import(pathToFileURL(ref));
|
|
155
159
|
}
|
|
156
160
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ava",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Testing can be a drag. AVA helps you get it done.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "avajs/ava",
|
|
@@ -95,8 +95,8 @@
|
|
|
95
95
|
"p-map": "^3.0.0",
|
|
96
96
|
"picomatch": "^2.2.1",
|
|
97
97
|
"pkg-conf": "^3.1.0",
|
|
98
|
-
"plur": "^
|
|
99
|
-
"pretty-ms": "^
|
|
98
|
+
"plur": "^4.0.0",
|
|
99
|
+
"pretty-ms": "^6.0.0",
|
|
100
100
|
"read-pkg": "^5.2.0",
|
|
101
101
|
"resolve-cwd": "^3.0.0",
|
|
102
102
|
"slash": "^3.0.0",
|
|
@@ -106,33 +106,32 @@
|
|
|
106
106
|
"supertap": "^1.0.0",
|
|
107
107
|
"temp-dir": "^2.0.0",
|
|
108
108
|
"trim-off-newlines": "^1.0.1",
|
|
109
|
-
"update-notifier": "^4.
|
|
109
|
+
"update-notifier": "^4.1.0",
|
|
110
110
|
"write-file-atomic": "^3.0.1",
|
|
111
111
|
"yargs": "^15.1.0"
|
|
112
112
|
},
|
|
113
113
|
"devDependencies": {
|
|
114
114
|
"@ava/babel": "^1.0.1",
|
|
115
|
-
"@
|
|
115
|
+
"@sinonjs/fake-timers": "^6.0.0",
|
|
116
116
|
"ansi-escapes": "^4.3.0",
|
|
117
117
|
"delay": "^4.3.0",
|
|
118
118
|
"esm": "^3.2.25",
|
|
119
119
|
"execa": "^4.0.0",
|
|
120
120
|
"get-stream": "^5.1.0",
|
|
121
|
-
"lolex": "^5.1.2",
|
|
122
121
|
"p-event": "^4.1.0",
|
|
123
122
|
"proxyquire": "^2.1.3",
|
|
124
123
|
"react": "^16.12.0",
|
|
125
124
|
"react-test-renderer": "^16.12.0",
|
|
126
125
|
"replace-string": "^3.0.0",
|
|
127
|
-
"sinon": "^8.1.
|
|
126
|
+
"sinon": "^8.1.1",
|
|
128
127
|
"source-map-fixtures": "^2.1.0",
|
|
129
128
|
"tap": "^14.10.6",
|
|
130
129
|
"temp-write": "^4.0.0",
|
|
131
|
-
"tempy": "^0.
|
|
130
|
+
"tempy": "^0.4.0",
|
|
132
131
|
"touch": "^3.1.0",
|
|
133
132
|
"ts-node": "^8.6.2",
|
|
134
133
|
"typescript": "^3.7.5",
|
|
135
|
-
"xo": "^0.
|
|
134
|
+
"xo": "^0.26.1",
|
|
136
135
|
"zen-observable": "^0.8.15"
|
|
137
136
|
},
|
|
138
137
|
"xo": {
|
package/lib/esm-probe.mjs
DELETED