ava 5.2.0 → 5.3.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/lib/assert.js CHANGED
@@ -55,7 +55,7 @@ export class AssertionError extends Error {
55
55
  }
56
56
 
57
57
  export function checkAssertionMessage(assertion, message) {
58
- if (typeof message === 'undefined' || typeof message === 'string') {
58
+ if (message === undefined || typeof message === 'string') {
59
59
  return true;
60
60
  }
61
61
 
@@ -253,7 +253,7 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
253
253
  });
254
254
  }
255
255
 
256
- if (typeof expectations.code !== 'undefined' && actual.code !== expectations.code) {
256
+ if (expectations.code !== undefined && actual.code !== expectations.code) {
257
257
  throw new AssertionError({
258
258
  assertion,
259
259
  message,
package/lib/cli.js CHANGED
@@ -5,7 +5,6 @@ import process from 'node:process';
5
5
 
6
6
  import arrify from 'arrify';
7
7
  import ciParallelVars from 'ci-parallel-vars';
8
- import {deleteAsync} from 'del';
9
8
  import figures from 'figures';
10
9
  import yargs from 'yargs';
11
10
  import {hideBin} from 'yargs/helpers'; // eslint-disable-line n/file-extension-in-import
@@ -140,6 +139,7 @@ export default async function loadCli() { // eslint-disable-line complexity
140
139
 
141
140
  let resetCache = false;
142
141
  const {argv} = yargs(hideBin(process.argv))
142
+ .scriptName('ava')
143
143
  .version(pkg.version)
144
144
  .parserConfiguration({
145
145
  'boolean-negation': true,
@@ -260,11 +260,23 @@ export default async function loadCli() { // eslint-disable-line complexity
260
260
  const {nonSemVerExperiments: experiments, projectDir} = conf;
261
261
  if (resetCache) {
262
262
  const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava');
263
-
264
263
  try {
265
- const deletedFilePaths = await deleteAsync('*', {cwd: cacheDir});
264
+ let entries;
265
+ try {
266
+ entries = fs.readdirSync(cacheDir);
267
+ } catch (error) {
268
+ if (error.code === 'ENOENT') {
269
+ entries = [];
270
+ } else {
271
+ throw error;
272
+ }
273
+ }
274
+
275
+ for (const entry of entries) {
276
+ fs.rmSync(path.join(cacheDir, entry), {recursive: true, force: true});
277
+ }
266
278
 
267
- if (deletedFilePaths.length === 0) {
279
+ if (entries.length === 0) {
268
280
  console.log(`\n${chalk.green(figures.tick)} No cache files to remove`);
269
281
  } else {
270
282
  console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`);
@@ -4,7 +4,8 @@ const process = require('node:process');
4
4
 
5
5
  const ignoreByDefault = require('ignore-by-default');
6
6
  const picomatch = require('picomatch');
7
- const slash = require('slash');
7
+
8
+ const slash = require('./slash.cjs');
8
9
 
9
10
  const defaultIgnorePatterns = [...ignoreByDefault.directories(), '**/node_modules'];
10
11
  exports.defaultIgnorePatterns = defaultIgnorePatterns;
@@ -1,29 +1,40 @@
1
+ const isPrimitive = value => value === null || typeof value !== 'object';
2
+
1
3
  export function isLikeSelector(selector) {
2
- return selector !== null
3
- && typeof selector === 'object'
4
- && Reflect.getPrototypeOf(selector) === Object.prototype
5
- && Reflect.ownKeys(selector).length > 0;
4
+ // Require selector to be an array or plain object.
5
+ if (
6
+ isPrimitive(selector)
7
+ || (!Array.isArray(selector) && Reflect.getPrototypeOf(selector) !== Object.prototype)
8
+ ) {
9
+ return false;
10
+ }
11
+
12
+ // Also require at least one enumerable property.
13
+ const descriptors = Object.getOwnPropertyDescriptors(selector);
14
+ return Reflect.ownKeys(descriptors).some(key => descriptors[key].enumerable === true);
6
15
  }
7
16
 
8
17
  export const CIRCULAR_SELECTOR = new Error('Encountered a circular selector');
9
18
 
10
- export function selectComparable(lhs, selector, circular = new Set()) {
11
- if (circular.has(selector)) {
12
- throw CIRCULAR_SELECTOR;
19
+ export function selectComparable(actual, selector, circular = [selector]) {
20
+ if (isPrimitive(actual)) {
21
+ return actual;
13
22
  }
14
23
 
15
- circular.add(selector);
16
-
17
- if (lhs === null || typeof lhs !== 'object') {
18
- return lhs;
19
- }
24
+ const comparable = Array.isArray(selector) ? [] : {};
25
+ const enumerableKeys = Reflect.ownKeys(selector).filter(key => Reflect.getOwnPropertyDescriptor(selector, key).enumerable);
26
+ for (const key of enumerableKeys) {
27
+ const subselector = Reflect.get(selector, key);
28
+ if (isLikeSelector(subselector)) {
29
+ if (circular.includes(subselector)) {
30
+ throw CIRCULAR_SELECTOR;
31
+ }
20
32
 
21
- const comparable = {};
22
- for (const [key, rhs] of Object.entries(selector)) {
23
- if (isLikeSelector(rhs)) {
24
- comparable[key] = selectComparable(Reflect.get(lhs, key), rhs, circular);
33
+ circular.push(subselector);
34
+ comparable[key] = selectComparable(Reflect.get(actual, key), subselector, circular);
35
+ circular.pop();
25
36
  } else {
26
- comparable[key] = Reflect.get(lhs, key);
37
+ comparable[key] = Reflect.get(actual, key);
27
38
  }
28
39
  }
29
40
 
package/lib/slash.cjs ADDED
@@ -0,0 +1,36 @@
1
+ /*
2
+ Inlined from
3
+ <https://github.com/sindresorhus/slash/blob/98b618f5a3bfcb5dd374b204868818845b87bb2f/index.js>,
4
+ since we need a CJS version.
5
+
6
+ Copyright 2023 Sindre Sorhus
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
9
+ this software and associated documentation files (the “Software”), to deal in
10
+ the Software without restriction, including without limitation the rights to
11
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12
+ the Software, and to permit persons to whom the Software is furnished to do so,
13
+ subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ */
25
+
26
+ function slash(path) {
27
+ const isExtendedLengthPath = path.startsWith('\\\\?\\');
28
+
29
+ if (isExtendedLengthPath) {
30
+ return path;
31
+ }
32
+
33
+ return path.replace(/\\/g, '/');
34
+ }
35
+
36
+ module.exports = slash;
@@ -10,10 +10,10 @@ import cbor from 'cbor';
10
10
  import concordance from 'concordance';
11
11
  import indentString from 'indent-string';
12
12
  import mem from 'mem';
13
- import slash from 'slash';
14
13
  import writeFileAtomic from 'write-file-atomic';
15
14
 
16
15
  import {snapshotManager as concordanceOptions} from './concordance-options.js';
16
+ import slash from './slash.cjs';
17
17
 
18
18
  // Increment if encoding layout or Concordance serialization versions change. Previous AVA versions will not be able to
19
19
  // decode buffers generated by a newer version, so changing this value will require a major version bump of AVA itself.
package/lib/test.js CHANGED
@@ -7,6 +7,22 @@ import concordanceOptions from './concordance-options.js';
7
7
  import nowAndTimers from './now-and-timers.cjs';
8
8
  import parseTestArgs from './parse-test-args.js';
9
9
 
10
+ const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
11
+
12
+ function isExternalAssertError(error) {
13
+ if (typeof error !== 'object' || error === null) {
14
+ return false;
15
+ }
16
+
17
+ // Match errors thrown by <https://www.npmjs.com/package/expect>.
18
+ if (hasOwnProperty(error, 'matcherResult')) {
19
+ return true;
20
+ }
21
+
22
+ // Match errors thrown by <https://www.npmjs.com/package/chai> and <https://nodejs.org/api/assert.html>.
23
+ return hasOwnProperty(error, 'actual') && hasOwnProperty(error, 'expected');
24
+ }
25
+
10
26
  function formatErrorValue(label, error) {
11
27
  const formatted = concordance.format(error, concordanceOptions);
12
28
  return {label, formatted};
@@ -519,11 +535,19 @@ export default class Test {
519
535
 
520
536
  const result = this.callFn();
521
537
  if (!result.ok) {
522
- this.saveFirstError(new AssertionError({
523
- message: 'Error thrown in test',
524
- savedError: result.error instanceof Error && result.error,
525
- values: [formatErrorValue('Error thrown in test:', result.error)],
526
- }));
538
+ if (isExternalAssertError(result.error)) {
539
+ this.saveFirstError(new AssertionError({
540
+ message: 'Assertion failed',
541
+ savedError: result.error instanceof Error && result.error,
542
+ values: [{label: 'Assertion failed: ', formatted: result.error.message}],
543
+ }));
544
+ } else {
545
+ this.saveFirstError(new AssertionError({
546
+ message: 'Error thrown in test',
547
+ savedError: result.error instanceof Error && result.error,
548
+ values: [formatErrorValue('Error thrown in test:', result.error)],
549
+ }));
550
+ }
527
551
 
528
552
  return this.finish();
529
553
  }
@@ -564,11 +588,19 @@ export default class Test {
564
588
 
565
589
  promise
566
590
  .catch(error => {
567
- this.saveFirstError(new AssertionError({
568
- message: 'Rejected promise returned by test',
569
- savedError: error instanceof Error && error,
570
- values: [formatErrorValue('Rejected promise returned by test. Reason:', error)],
571
- }));
591
+ if (isExternalAssertError(error)) {
592
+ this.saveFirstError(new AssertionError({
593
+ message: 'Assertion failed',
594
+ savedError: error instanceof Error && error,
595
+ values: [{label: 'Assertion failed: ', formatted: error.message}],
596
+ }));
597
+ } else {
598
+ this.saveFirstError(new AssertionError({
599
+ message: 'Rejected promise returned by test',
600
+ savedError: error instanceof Error && error,
601
+ values: [formatErrorValue('Rejected promise returned by test. Reason:', error)],
602
+ }));
603
+ }
572
604
  })
573
605
  .then(() => resolve(this.finish()));
574
606
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ava",
3
- "version": "5.2.0",
3
+ "version": "5.3.1",
4
4
  "description": "Node.js test runner that lets you develop with confidence.",
5
5
  "license": "MIT",
6
6
  "repository": "avajs/ava",
@@ -81,7 +81,7 @@
81
81
  "typescript"
82
82
  ],
83
83
  "dependencies": {
84
- "acorn": "^8.8.1",
84
+ "acorn": "^8.8.2",
85
85
  "acorn-walk": "^8.2.0",
86
86
  "ansi-styles": "^6.2.1",
87
87
  "arrgv": "^1.0.2",
@@ -91,7 +91,7 @@
91
91
  "chalk": "^5.2.0",
92
92
  "chokidar": "^3.5.3",
93
93
  "chunkd": "^2.0.1",
94
- "ci-info": "^3.7.1",
94
+ "ci-info": "^3.8.0",
95
95
  "ci-parallel-vars": "^1.0.1",
96
96
  "clean-yaml-object": "^0.1.0",
97
97
  "cli-truncate": "^3.1.0",
@@ -100,10 +100,9 @@
100
100
  "concordance": "^5.0.4",
101
101
  "currently-unhandled": "^0.4.1",
102
102
  "debug": "^4.3.4",
103
- "del": "^7.0.0",
104
103
  "emittery": "^1.0.1",
105
104
  "figures": "^5.0.0",
106
- "globby": "^13.1.3",
105
+ "globby": "^13.1.4",
107
106
  "ignore-by-default": "^2.1.0",
108
107
  "indent-string": "^5.0.0",
109
108
  "is-error": "^2.2.2",
@@ -119,33 +118,33 @@
119
118
  "plur": "^5.1.0",
120
119
  "pretty-ms": "^8.0.0",
121
120
  "resolve-cwd": "^3.0.0",
122
- "slash": "^3.0.0",
123
121
  "stack-utils": "^2.0.6",
124
122
  "strip-ansi": "^7.0.1",
125
123
  "supertap": "^3.0.1",
126
124
  "temp-dir": "^3.0.0",
127
- "write-file-atomic": "^5.0.0",
128
- "yargs": "^17.6.2"
125
+ "write-file-atomic": "^5.0.1",
126
+ "yargs": "^17.7.2"
129
127
  },
130
128
  "devDependencies": {
131
129
  "@ava/test": "github:avajs/test",
132
- "@ava/typescript": "^3.0.1",
130
+ "@ava/typescript": "^4.0.0",
133
131
  "@sindresorhus/tsconfig": "^3.0.1",
134
- "ansi-escapes": "^6.0.0",
135
- "c8": "^7.12.0",
132
+ "ansi-escapes": "^6.2.0",
133
+ "c8": "^7.13.0",
136
134
  "delay": "^5.0.0",
137
- "execa": "^6.1.0",
138
- "fs-extra": "^11.1.0",
135
+ "execa": "^7.1.1",
136
+ "expect": "^29.5.0",
137
+ "fs-extra": "^11.1.1",
139
138
  "get-stream": "^6.0.1",
140
139
  "replace-string": "^4.0.0",
141
- "sinon": "^15.0.1",
142
- "tap": "^16.3.3",
140
+ "sinon": "^15.1.0",
141
+ "tap": "^16.3.4",
143
142
  "temp-write": "^5.0.0",
144
143
  "tempy": "^3.0.0",
145
144
  "touch": "^3.1.0",
146
- "tsd": "^0.25.0",
147
- "typescript": "^4.9.4",
148
- "xo": "^0.53.1",
145
+ "tsd": "^0.28.1",
146
+ "typescript": "^4.9.5",
147
+ "xo": "^0.54.2",
149
148
  "zen-observable": "^0.10.0"
150
149
  },
151
150
  "peerDependencies": {
@@ -157,7 +156,6 @@
157
156
  }
158
157
  },
159
158
  "volta": {
160
- "node": "18.13.0",
161
- "npm": "9.3.0"
159
+ "node": "20.2.0"
162
160
  }
163
161
  }