ava 3.10.1 → 3.12.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/index.d.ts CHANGED
@@ -433,7 +433,7 @@ export interface CbExecutionContext<Context = unknown> extends ExecutionContext<
433
433
  end(error?: any): void;
434
434
  }
435
435
 
436
- export type ImplementationResult = PromiseLike<void> | Subscribable | void; // eslint-disable-line @typescript-eslint/no-invalid-void-type
436
+ export type ImplementationResult = PromiseLike<void> | Subscribable | void;
437
437
  export type Implementation<Context = unknown> = (t: ExecutionContext<Context>) => ImplementationResult;
438
438
  export type CbImplementation<Context = unknown> = (t: CbExecutionContext<Context>) => ImplementationResult;
439
439
 
package/lib/api.js CHANGED
@@ -147,7 +147,7 @@ class Api extends Emittery {
147
147
  runStatus = new RunStatus(selectedFiles.length, null);
148
148
  }
149
149
 
150
- const debugWithoutSpecificFile = Boolean(this.options.debug) && selectedFiles.length !== 1;
150
+ const debugWithoutSpecificFile = Boolean(this.options.debug) && !this.options.debug.active && selectedFiles.length !== 1;
151
151
 
152
152
  await this.emit('run', {
153
153
  bailWithoutReporting: debugWithoutSpecificFile,
package/lib/assert.js CHANGED
@@ -399,15 +399,6 @@ class Assertions {
399
399
  });
400
400
 
401
401
  this.like = withSkip((actual, selector, message) => {
402
- if (!experiments.likeAssertion) {
403
- fail(new AssertionError({
404
- assertion: 'like',
405
- improperUsage: true,
406
- message: 'You must enable the `likeAssertion` experiment in order to use `t.like()`'
407
- }));
408
- return;
409
- }
410
-
411
402
  if (!checkMessage('like', message)) {
412
403
  return;
413
404
  }
package/lib/cli.js CHANGED
@@ -88,7 +88,19 @@ exports.run = async () => { // eslint-disable-line complexity
88
88
  confError = error;
89
89
  }
90
90
 
91
- let debug = null;
91
+ // Enter debug mode if the main process is being inspected. This assumes the
92
+ // worker processes are automatically inspected, too. It is not necessary to
93
+ // run AVA with the debug command, though it's allowed.
94
+ const activeInspector = require('inspector').url() !== undefined; // eslint-disable-line node/no-unsupported-features/node-builtins
95
+ let debug = activeInspector ?
96
+ {
97
+ active: true,
98
+ break: false,
99
+ files: [],
100
+ host: undefined,
101
+ port: undefined
102
+ } : null;
103
+
92
104
  let resetCache = false;
93
105
  const {argv} = yargs
94
106
  .parserConfiguration({
@@ -122,7 +134,11 @@ exports.run = async () => { // eslint-disable-line complexity
122
134
  array: true,
123
135
  describe: 'Glob patterns to select what test files to run. Leave empty if you want AVA to run all test files instead. Add a colon and specify line numbers of specific tests to run',
124
136
  type: 'string'
125
- }))
137
+ }), argv => {
138
+ if (activeInspector) {
139
+ debug.files = argv.pattern || [];
140
+ }
141
+ })
126
142
  .command(
127
143
  'debug [<pattern>...]',
128
144
  'Activate Node.js inspector and run a single test file',
@@ -148,6 +164,7 @@ exports.run = async () => { // eslint-disable-line complexity
148
164
  }),
149
165
  argv => {
150
166
  debug = {
167
+ active: activeInspector,
151
168
  break: argv.break === true,
152
169
  files: argv.pattern,
153
170
  host: argv.host,
@@ -267,6 +284,7 @@ exports.run = async () => { // eslint-disable-line complexity
267
284
  const TapReporter = require('./reporters/tap');
268
285
  const Watcher = require('./watcher');
269
286
  const normalizeExtensions = require('./extensions');
287
+ const normalizeModuleTypes = require('./module-types');
270
288
  const {normalizeGlobs, normalizePattern} = require('./globs');
271
289
  const normalizeNodeArguments = require('./node-arguments');
272
290
  const validateEnvironmentVariables = require('./environment-variables');
@@ -284,12 +302,6 @@ exports.run = async () => { // eslint-disable-line complexity
284
302
 
285
303
  const {type: defaultModuleType = 'commonjs'} = pkg || {};
286
304
 
287
- const moduleTypes = {
288
- cjs: 'commonjs',
289
- mjs: 'module',
290
- js: defaultModuleType
291
- };
292
-
293
305
  const providers = [];
294
306
  if (Reflect.has(conf, 'babel')) {
295
307
  try {
@@ -331,6 +343,13 @@ exports.run = async () => { // eslint-disable-line complexity
331
343
  exit(error.message);
332
344
  }
333
345
 
346
+ let moduleTypes;
347
+ try {
348
+ moduleTypes = normalizeModuleTypes(conf.extensions, defaultModuleType, experiments);
349
+ } catch (error) {
350
+ exit(error.message);
351
+ }
352
+
334
353
  let globs;
335
354
  try {
336
355
  globs = normalizeGlobs({files: conf.files, ignoredByWatcher: conf.ignoredByWatcher, extensions, providers});
@@ -444,14 +463,14 @@ exports.run = async () => { // eslint-disable-line complexity
444
463
  } else {
445
464
  let debugWithoutSpecificFile = false;
446
465
  api.on('run', plan => {
447
- if (plan.debug && plan.files.length !== 1) {
466
+ if (debug !== null && plan.files.length !== 1) {
448
467
  debugWithoutSpecificFile = true;
449
468
  }
450
469
  });
451
470
 
452
471
  const runStatus = await api.run({filter});
453
472
 
454
- if (debugWithoutSpecificFile) {
473
+ if (debugWithoutSpecificFile && !debug.active) {
455
474
  exit('Provide the path to the test file you wish to debug');
456
475
  return;
457
476
  }
package/lib/extensions.js CHANGED
@@ -2,8 +2,11 @@ module.exports = (configuredExtensions, providers = []) => {
2
2
  // Combine all extensions possible for testing. Remove duplicate extensions.
3
3
  const duplicates = new Set();
4
4
  const seen = new Set();
5
+
6
+ const normalize = extensions => Array.isArray(extensions) ? extensions : Object.keys(extensions);
7
+
5
8
  const combine = extensions => {
6
- for (const ext of extensions) {
9
+ for (const ext of normalize(extensions)) {
7
10
  if (seen.has(ext)) {
8
11
  duplicates.add(ext);
9
12
  } else {
@@ -7,7 +7,7 @@ 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(['disableSnapshotsInHooks', 'likeAssertion', 'reverseTeardowns']);
10
+ const EXPERIMENTS = new Set(['configurableModuleFormat', 'disableSnapshotsInHooks', 'reverseTeardowns']);
11
11
 
12
12
  // *Very* rudimentary support for loading ava.config.js files containing an `export default` statement.
13
13
  const evaluateJsConfig = configFile => {
@@ -0,0 +1,75 @@
1
+ const requireTrueValue = value => {
2
+ if (value !== true) {
3
+ throw new TypeError('When specifying module types, use `true` for ’cjs’, ’mjs’ and ’js’ extensions');
4
+ }
5
+ };
6
+
7
+ const normalize = (extension, type, defaultModuleType) => {
8
+ switch (extension) {
9
+ case 'cjs':
10
+ requireTrueValue(type);
11
+ return 'commonjs';
12
+ case 'mjs':
13
+ requireTrueValue(type);
14
+ return 'module';
15
+ case 'js':
16
+ requireTrueValue(type);
17
+ return defaultModuleType;
18
+ default:
19
+ if (type !== 'commonjs' && type !== 'module') {
20
+ throw new TypeError(`Module type for ’${extension}’ must be ’commonjs’ or ’module’`);
21
+ }
22
+
23
+ return type;
24
+ }
25
+ };
26
+
27
+ const deriveFromObject = (extensionsObject, defaultModuleType) => {
28
+ const moduleTypes = {};
29
+ for (const [extension, type] of Object.entries(extensionsObject)) {
30
+ moduleTypes[extension] = normalize(extension, type, defaultModuleType);
31
+ }
32
+
33
+ return moduleTypes;
34
+ };
35
+
36
+ const deriveFromArray = (extensions, defaultModuleType) => {
37
+ const moduleTypes = {};
38
+ for (const extension of extensions) {
39
+ switch (extension) {
40
+ case 'cjs':
41
+ moduleTypes.cjs = 'commonjs';
42
+ break;
43
+ case 'mjs':
44
+ moduleTypes.mjs = 'module';
45
+ break;
46
+ case 'js':
47
+ moduleTypes.js = defaultModuleType;
48
+ break;
49
+ default:
50
+ moduleTypes[extension] = 'commonjs';
51
+ }
52
+ }
53
+
54
+ return moduleTypes;
55
+ };
56
+
57
+ module.exports = (configuredExtensions, defaultModuleType, experiments) => {
58
+ if (configuredExtensions === undefined) {
59
+ return {
60
+ cjs: 'commonjs',
61
+ mjs: 'module',
62
+ js: defaultModuleType
63
+ };
64
+ }
65
+
66
+ if (Array.isArray(configuredExtensions)) {
67
+ return deriveFromArray(configuredExtensions, defaultModuleType);
68
+ }
69
+
70
+ if (!experiments.configurableModuleFormat) {
71
+ throw new Error('You must enable the `configurableModuleFormat` experiment in order to specify module types');
72
+ }
73
+
74
+ return deriveFromObject(configuredExtensions, defaultModuleType);
75
+ };
@@ -21,7 +21,7 @@ function load(providerModule, projectDir) {
21
21
  let level;
22
22
  const provider = makeProvider({
23
23
  negotiateProtocol(identifiers, {version}) {
24
- const [identifier] = identifiers.filter(identifier => Reflect.has(levelsByProtocol, identifier));
24
+ const identifier = identifiers.find(identifier => Reflect.has(levelsByProtocol, identifier));
25
25
 
26
26
  if (identifier === undefined) {
27
27
  fatal = new Error(`This version of AVA (${ava.version}) is not compatible with ${providerModule}@${version}`);
@@ -18,7 +18,6 @@ const colors = require('./colors');
18
18
  const formatSerializedError = require('./format-serialized-error');
19
19
  const improperUsageMessages = require('./improper-usage-messages');
20
20
  const prefixTitle = require('./prefix-title');
21
- const whileCorked = require('./while-corked');
22
21
 
23
22
  const nodeInternals = require('stack-utils').nodeInternals();
24
23
 
@@ -97,6 +96,48 @@ class LineWriterWithSpinner extends LineWriter {
97
96
  }
98
97
  }
99
98
 
99
+ function manageCorking(stream) {
100
+ let corked = false;
101
+ const cork = () => {
102
+ corked = true;
103
+ stream.cork();
104
+ };
105
+
106
+ const uncork = () => {
107
+ corked = false;
108
+ stream.uncork();
109
+ };
110
+
111
+ return {
112
+ decorateFlushingWriter(fn) {
113
+ return function (...args) {
114
+ if (corked) {
115
+ stream.uncork();
116
+ }
117
+
118
+ try {
119
+ return fn.apply(this, args);
120
+ } finally {
121
+ if (corked) {
122
+ stream.cork();
123
+ }
124
+ }
125
+ };
126
+ },
127
+
128
+ decorateWriter(fn) {
129
+ return function (...args) {
130
+ cork();
131
+ try {
132
+ return fn.apply(this, args);
133
+ } finally {
134
+ uncork();
135
+ }
136
+ };
137
+ }
138
+ };
139
+ }
140
+
100
141
  class Reporter {
101
142
  constructor({
102
143
  verbose,
@@ -112,13 +153,16 @@ class Reporter {
112
153
  this.stdStream = stdStream;
113
154
  this.watching = watching;
114
155
  this.relativeFile = file => path.relative(projectDir, file);
115
- this.consumeStateChange = whileCorked(this.reportStream, this.consumeStateChange);
156
+
157
+ const {decorateWriter, decorateFlushingWriter} = manageCorking(this.reportStream);
158
+ this.consumeStateChange = decorateWriter(this.consumeStateChange);
159
+ this.endRun = decorateWriter(this.endRun);
116
160
 
117
161
  if (this.verbose) {
118
162
  this.durationThreshold = durationThreshold || 100;
119
163
  this.spinner = null;
164
+ this.clearSpinner = () => {};
120
165
  this.lineWriter = new LineWriter(this.reportStream);
121
- this.endRun = whileCorked(this.reportStream, this.endRun);
122
166
  } else {
123
167
  this.spinner = ora({
124
168
  isEnabled: true,
@@ -128,8 +172,8 @@ class Reporter {
128
172
  spinner: spinner || (process.platform === 'win32' ? 'line' : 'dots'),
129
173
  stream: reportStream
130
174
  });
175
+ this.clearSpinner = decorateFlushingWriter(this.spinner.clear.bind(this.spinner));
131
176
  this.lineWriter = new LineWriterWithSpinner(this.reportStream, this.spinner);
132
- this.endRun = whileCorked(this.reportStream, whileCorked(this.lineWriter, this.endRun));
133
177
  }
134
178
 
135
179
  this.reset();
@@ -362,9 +406,7 @@ class Reporter {
362
406
 
363
407
  case 'worker-stderr': {
364
408
  // Forcibly clear the spinner, writing the chunk corrupts the TTY.
365
- if (this.spinner !== null) {
366
- this.spinner.clear();
367
- }
409
+ this.clearSpinner();
368
410
 
369
411
  this.stdStream.write(event.chunk);
370
412
  // If the chunk does not end with a linebreak, *forcibly* write one to
@@ -386,9 +428,7 @@ class Reporter {
386
428
 
387
429
  case 'worker-stdout': {
388
430
  // Forcibly clear the spinner, writing the chunk corrupts the TTY.
389
- if (this.spinner !== null) {
390
- this.spinner.clear();
391
- }
431
+ this.clearSpinner();
392
432
 
393
433
  this.stdStream.write(event.chunk);
394
434
  // If the chunk does not end with a linebreak, *forcibly* write one to
@@ -205,8 +205,14 @@ ipc.options.then(async options => {
205
205
  // to make sure we also track dependencies with custom require hooks
206
206
  dependencyTracking.install(testPath);
207
207
 
208
- if (options.debug) {
209
- require('inspector').open(options.debug.port, options.debug.host, true); // eslint-disable-line node/no-unsupported-features/node-builtins
208
+ if (options.debug && options.debug.port !== undefined && options.debug.host !== undefined) {
209
+ // If an inspector was active when the main process started, and is
210
+ // already active for the worker process, do not open a new one.
211
+ const inspector = require('inspector'); // eslint-disable-line node/no-unsupported-features/node-builtins
212
+ if (!options.debug.active || inspector.url() === undefined) {
213
+ inspector.open(options.debug.port, options.debug.host, true);
214
+ }
215
+
210
216
  if (options.debug.break) {
211
217
  debugger; // eslint-disable-line no-debugger
212
218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ava",
3
- "version": "3.10.1",
3
+ "version": "3.12.1",
4
4
  "description": "Node.js test runner that lets you develop with confidence.",
5
5
  "license": "MIT",
6
6
  "repository": "avajs/ava",
@@ -56,14 +56,14 @@
56
56
  ],
57
57
  "dependencies": {
58
58
  "@concordance/react": "^2.0.0",
59
- "acorn": "^7.3.1",
60
- "acorn-walk": "^7.2.0",
59
+ "acorn": "^8.0.1",
60
+ "acorn-walk": "^8.0.0",
61
61
  "ansi-styles": "^4.2.1",
62
62
  "arrgv": "^1.0.2",
63
63
  "arrify": "^2.0.1",
64
64
  "callsites": "^3.1.0",
65
65
  "chalk": "^4.1.0",
66
- "chokidar": "^3.4.0",
66
+ "chokidar": "^3.4.2",
67
67
  "chunkd": "^2.0.1",
68
68
  "ci-info": "^2.0.0",
69
69
  "ci-parallel-vars": "^1.0.1",
@@ -72,12 +72,12 @@
72
72
  "cli-truncate": "^2.1.0",
73
73
  "code-excerpt": "^3.0.0",
74
74
  "common-path-prefix": "^3.0.0",
75
- "concordance": "^5.0.0",
75
+ "concordance": "^5.0.1",
76
76
  "convert-source-map": "^1.7.0",
77
77
  "currently-unhandled": "^0.4.1",
78
78
  "debug": "^4.1.1",
79
79
  "del": "^5.1.0",
80
- "emittery": "^0.7.0",
80
+ "emittery": "^0.7.1",
81
81
  "equal-length": "^1.0.0",
82
82
  "figures": "^3.2.0",
83
83
  "globby": "^11.0.1",
@@ -85,14 +85,14 @@
85
85
  "import-local": "^3.0.2",
86
86
  "indent-string": "^4.0.0",
87
87
  "is-error": "^2.2.2",
88
- "is-plain-object": "^3.0.1",
88
+ "is-plain-object": "^4.1.1",
89
89
  "is-promise": "^4.0.0",
90
- "lodash": "^4.17.15",
90
+ "lodash": "^4.17.20",
91
91
  "matcher": "^3.0.0",
92
92
  "md5-hex": "^3.0.1",
93
93
  "mem": "^6.1.0",
94
94
  "ms": "^2.1.2",
95
- "ora": "^4.0.4",
95
+ "ora": "^5.0.0",
96
96
  "p-map": "^4.0.0",
97
97
  "picomatch": "^2.2.2",
98
98
  "pkg-conf": "^3.1.0",
@@ -107,9 +107,9 @@
107
107
  "supertap": "^1.0.0",
108
108
  "temp-dir": "^2.0.0",
109
109
  "trim-off-newlines": "^1.0.1",
110
- "update-notifier": "^4.1.0",
110
+ "update-notifier": "^4.1.1",
111
111
  "write-file-atomic": "^3.0.3",
112
- "yargs": "^15.4.0"
112
+ "yargs": "^15.4.1"
113
113
  },
114
114
  "devDependencies": {
115
115
  "@ava/babel": "^1.0.1",
@@ -117,25 +117,25 @@
117
117
  "@babel/plugin-proposal-do-expressions": "^7.10.4",
118
118
  "@sinonjs/fake-timers": "^6.0.1",
119
119
  "ansi-escapes": "^4.3.1",
120
- "c8": "^7.2.0",
121
- "delay": "^4.3.0",
120
+ "c8": "^7.3.0",
121
+ "delay": "^4.4.0",
122
122
  "esm": "^3.2.25",
123
- "execa": "^4.0.2",
124
- "get-stream": "^5.1.0",
123
+ "execa": "^4.0.3",
124
+ "get-stream": "^6.0.0",
125
125
  "p-event": "^4.2.0",
126
126
  "proxyquire": "^2.1.3",
127
127
  "react": "^16.13.1",
128
128
  "react-test-renderer": "^16.13.1",
129
129
  "replace-string": "^3.1.0",
130
- "sinon": "^9.0.2",
130
+ "sinon": "^9.0.3",
131
131
  "source-map-fixtures": "^2.1.0",
132
- "tap": "^14.10.7",
132
+ "tap": "^14.10.8",
133
133
  "temp-write": "^4.0.0",
134
- "tempy": "^0.5.0",
134
+ "tempy": "^0.6.0",
135
135
  "touch": "^3.1.0",
136
136
  "tsd": "^0.13.1",
137
- "typescript": "^3.9.6",
138
- "xo": "^0.32.1",
137
+ "typescript": "^3.9.7",
138
+ "xo": "^0.33.0",
139
139
  "zen-observable": "^0.8.15"
140
140
  }
141
141
  }
package/readme.md CHANGED
@@ -211,9 +211,9 @@ It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
211
211
 
212
212
  ## Team
213
213
 
214
- [![Mark Wubben](https://github.com/novemberborn.png?size=100)](https://github.com/novemberborn) | [![Sindre Sorhus](https://github.com/sindresorhus.png?size=100)](https://github.com/sindresorhus) | [![Vadim Demedes](https://github.com/vadimdemedes.png?size=100)](https://github.com/vadimdemedes)
215
- ---|---|---
216
- [Mark Wubben](https://novemberborn.net) | [Sindre Sorhus](https://sindresorhus.com) | [Vadim Demedes](https://github.com/vadimdemedes)
214
+ [![Mark Wubben](https://github.com/novemberborn.png?size=100)](https://github.com/novemberborn) | [![Sindre Sorhus](https://github.com/sindresorhus.png?size=100)](https://github.com/sindresorhus)
215
+ ---|---
216
+ [Mark Wubben](https://novemberborn.net) | [Sindre Sorhus](https://sindresorhus.com)
217
217
 
218
218
  ###### Former
219
219
 
@@ -221,6 +221,7 @@ It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
221
221
  - [James Talmage](https://github.com/jamestalmage)
222
222
  - [Juan Soto](https://github.com/sotojuan)
223
223
  - [Jeroen Engels](https://github.com/jfmengels)
224
+ - [Vadim Demedes](https://github.com/vadimdemedes)
224
225
 
225
226
 
226
227
  <div align="center">
@@ -1,13 +0,0 @@
1
- 'use strict';
2
- function whileCorked(stream, fn) {
3
- return function (...args) {
4
- stream.cork();
5
- try {
6
- fn.apply(this, args);
7
- } finally {
8
- stream.uncork();
9
- }
10
- };
11
- }
12
-
13
- module.exports = whileCorked;