ava 3.15.0 → 4.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.
Files changed (72) hide show
  1. package/entrypoints/cli.mjs +4 -0
  2. package/entrypoints/eslint-plugin-helper.cjs +109 -0
  3. package/entrypoints/main.cjs +2 -0
  4. package/entrypoints/main.mjs +1 -0
  5. package/entrypoints/plugin.cjs +2 -0
  6. package/entrypoints/plugin.mjs +4 -0
  7. package/index.d.ts +6 -816
  8. package/lib/api.js +108 -49
  9. package/lib/assert.js +255 -270
  10. package/lib/chalk.js +9 -14
  11. package/lib/cli.js +118 -112
  12. package/lib/code-excerpt.js +12 -17
  13. package/lib/concordance-options.js +29 -65
  14. package/lib/context-ref.js +3 -6
  15. package/lib/create-chain.js +32 -20
  16. package/lib/environment-variables.js +1 -4
  17. package/lib/eslint-plugin-helper-worker.js +73 -0
  18. package/lib/extensions.js +2 -2
  19. package/lib/fork.js +81 -84
  20. package/lib/glob-helpers.cjs +140 -0
  21. package/lib/globs.js +136 -163
  22. package/lib/{ipc-flow-control.js → ipc-flow-control.cjs} +1 -0
  23. package/lib/is-ci.js +4 -2
  24. package/lib/like-selector.js +7 -13
  25. package/lib/line-numbers.js +11 -18
  26. package/lib/load-config.js +56 -180
  27. package/lib/module-types.js +3 -7
  28. package/lib/node-arguments.js +4 -5
  29. package/lib/{now-and-timers.js → now-and-timers.cjs} +0 -0
  30. package/lib/parse-test-args.js +22 -11
  31. package/lib/pkg.cjs +2 -0
  32. package/lib/plugin-support/shared-worker-loader.js +45 -48
  33. package/lib/plugin-support/shared-workers.js +24 -46
  34. package/lib/provider-manager.js +20 -14
  35. package/lib/reporters/beautify-stack.js +6 -12
  36. package/lib/reporters/colors.js +40 -15
  37. package/lib/reporters/default.js +114 -364
  38. package/lib/reporters/format-serialized-error.js +7 -18
  39. package/lib/reporters/improper-usage-messages.js +8 -9
  40. package/lib/reporters/prefix-title.js +17 -15
  41. package/lib/reporters/tap.js +18 -25
  42. package/lib/run-status.js +29 -23
  43. package/lib/runner.js +157 -172
  44. package/lib/scheduler.js +53 -0
  45. package/lib/serialize-error.js +61 -64
  46. package/lib/snapshot-manager.js +271 -289
  47. package/lib/test.js +135 -291
  48. package/lib/watcher.js +69 -44
  49. package/lib/worker/base.js +208 -0
  50. package/lib/worker/channel.cjs +290 -0
  51. package/lib/worker/dependency-tracker.js +24 -23
  52. package/lib/worker/{ensure-forked.js → guard-environment.cjs} +5 -4
  53. package/lib/worker/line-numbers.js +58 -20
  54. package/lib/worker/main.cjs +12 -0
  55. package/lib/worker/{options.js → options.cjs} +0 -0
  56. package/lib/worker/{plugin.js → plugin.cjs} +30 -21
  57. package/lib/worker/state.cjs +5 -0
  58. package/lib/worker/utils.cjs +6 -0
  59. package/package.json +71 -68
  60. package/plugin.d.ts +51 -53
  61. package/readme.md +5 -13
  62. package/types/assertions.d.ts +327 -0
  63. package/types/subscribable.ts +6 -0
  64. package/types/test-fn.d.ts +231 -0
  65. package/types/try-fn.d.ts +58 -0
  66. package/cli.js +0 -11
  67. package/eslint-plugin-helper.js +0 -201
  68. package/index.js +0 -8
  69. package/lib/worker/ipc.js +0 -201
  70. package/lib/worker/main.js +0 -21
  71. package/lib/worker/subprocess.js +0 -266
  72. package/plugin.js +0 -9
@@ -1,42 +1,45 @@
1
- 'use strict';
2
- const path = require('path');
3
- const cleanYamlObject = require('clean-yaml-object');
4
- const concordance = require('concordance');
5
- const isError = require('is-error');
6
- const slash = require('slash');
7
- const StackUtils = require('stack-utils');
8
- const assert = require('./assert');
9
- const concordanceOptions = require('./concordance-options').default;
1
+ import path from 'node:path';
2
+ import process from 'node:process';
3
+ import {fileURLToPath, pathToFileURL} from 'node:url';
4
+
5
+ import cleanYamlObject from 'clean-yaml-object';
6
+ import concordance from 'concordance';
7
+ import isError from 'is-error';
8
+ import StackUtils from 'stack-utils';
9
+
10
+ import {AssertionError} from './assert.js';
11
+ import concordanceOptions from './concordance-options.js';
10
12
 
11
13
  function isAvaAssertionError(source) {
12
- return source instanceof assert.AssertionError;
14
+ return source instanceof AssertionError;
13
15
  }
14
16
 
15
17
  function filter(propertyName, isRoot) {
16
18
  return !isRoot || (propertyName !== 'message' && propertyName !== 'name' && propertyName !== 'stack');
17
19
  }
18
20
 
21
+ function normalizeFile(file, ...base) {
22
+ return file.startsWith('file://') ? file : pathToFileURL(path.resolve(...base, file)).toString();
23
+ }
24
+
19
25
  const stackUtils = new StackUtils();
20
26
  function extractSource(stack, testFile) {
21
27
  if (!stack || !testFile) {
22
28
  return null;
23
29
  }
24
30
 
25
- // Normalize the test file so it matches `callSite.file`.
26
- const relFile = path.relative(process.cwd(), testFile);
27
- const normalizedFile = process.platform === 'win32' ? slash(relFile) : relFile;
31
+ testFile = normalizeFile(testFile);
32
+
28
33
  for (const line of stack.split('\n')) {
29
- try {
30
- const callSite = stackUtils.parseLine(line);
31
- if (callSite.file === normalizedFile) {
32
- return {
33
- isDependency: false,
34
- isWithinProject: true,
35
- file: path.resolve(process.cwd(), callSite.file),
36
- line: callSite.line
37
- };
38
- }
39
- } catch {}
34
+ const callSite = stackUtils.parseLine(line);
35
+ if (callSite && normalizeFile(callSite.file) === testFile) {
36
+ return {
37
+ isDependency: false,
38
+ isWithinProject: true,
39
+ file: testFile,
40
+ line: callSite.line,
41
+ };
42
+ }
40
43
  }
41
44
 
42
45
  return null;
@@ -52,8 +55,8 @@ function buildSource(source) {
52
55
  // directory set to the project directory.
53
56
  const projectDir = process.cwd();
54
57
 
55
- const file = path.resolve(projectDir, source.file.trim());
56
- const rel = path.relative(projectDir, file);
58
+ const file = normalizeFile(source.file.trim(), projectDir);
59
+ const rel = path.relative(projectDir, fileURLToPath(file));
57
60
 
58
61
  const [segment] = rel.split(path.sep);
59
62
  const isWithinProject = segment !== '..' && (process.platform !== 'win32' || !segment.includes(':'));
@@ -63,60 +66,59 @@ function buildSource(source) {
63
66
  isDependency,
64
67
  isWithinProject,
65
68
  file,
66
- line: source.line
69
+ line: source.line,
67
70
  };
68
71
  }
69
72
 
70
- function trySerializeError(err, shouldBeautifyStack, testFile) {
71
- const stack = err.savedError ? err.savedError.stack : err.stack;
73
+ function trySerializeError(error, shouldBeautifyStack, testFile) {
74
+ const stack = error.savedError ? error.savedError.stack : error.stack;
72
75
 
73
76
  const retval = {
74
- avaAssertionError: isAvaAssertionError(err),
77
+ avaAssertionError: isAvaAssertionError(error),
75
78
  nonErrorObject: false,
76
79
  source: extractSource(stack, testFile),
77
80
  stack,
78
- shouldBeautifyStack
81
+ shouldBeautifyStack,
79
82
  };
80
83
 
81
- if (err.actualStack) {
82
- retval.stack = err.actualStack;
84
+ if (error.actualStack) {
85
+ retval.stack = error.actualStack;
83
86
  }
84
87
 
85
88
  if (retval.avaAssertionError) {
86
- retval.improperUsage = err.improperUsage;
87
- retval.message = err.message;
88
- retval.name = err.name;
89
- retval.statements = err.statements;
90
- retval.values = err.values;
91
-
92
- if (err.fixedSource) {
93
- const source = buildSource(err.fixedSource);
89
+ retval.improperUsage = error.improperUsage;
90
+ retval.message = error.message;
91
+ retval.name = error.name;
92
+ retval.values = error.values;
93
+
94
+ if (error.fixedSource) {
95
+ const source = buildSource(error.fixedSource);
94
96
  if (source) {
95
97
  retval.source = source;
96
98
  }
97
99
  }
98
100
 
99
- if (err.assertion) {
100
- retval.assertion = err.assertion;
101
+ if (error.assertion) {
102
+ retval.assertion = error.assertion;
101
103
  }
102
104
 
103
- if (err.operator) {
104
- retval.operator = err.operator;
105
+ if (error.operator) {
106
+ retval.operator = error.operator;
105
107
  }
106
108
  } else {
107
- retval.object = cleanYamlObject(err, filter); // Cleanly copy non-standard properties
108
- if (typeof err.message === 'string') {
109
- retval.message = err.message;
109
+ retval.object = cleanYamlObject(error, filter); // Cleanly copy non-standard properties
110
+ if (typeof error.message === 'string') {
111
+ retval.message = error.message;
110
112
  }
111
113
 
112
- if (typeof err.name === 'string') {
113
- retval.name = err.name;
114
+ if (typeof error.name === 'string') {
115
+ retval.name = error.name;
114
116
  }
115
117
  }
116
118
 
117
- if (typeof err.stack === 'string') {
118
- const lines = err.stack.split('\n');
119
- if (err.name === 'SyntaxError' && !lines[0].startsWith('SyntaxError')) {
119
+ if (typeof error.stack === 'string') {
120
+ const lines = error.stack.split('\n');
121
+ if (error.name === 'SyntaxError' && !lines[0].startsWith('SyntaxError')) {
120
122
  retval.summary = '';
121
123
  for (const line of lines) {
122
124
  retval.summary += line + '\n';
@@ -127,11 +129,8 @@ function trySerializeError(err, shouldBeautifyStack, testFile) {
127
129
 
128
130
  retval.summary = retval.summary.trim();
129
131
  } else {
130
- // Skip the source line header inserted by `esm`:
131
- // <https://github.com/standard-things/esm/wiki/improved-errors>
132
- const start = lines.findIndex(line => !/:\d+$/.test(line));
133
132
  retval.summary = '';
134
- for (let index = start; index < lines.length; index++) {
133
+ for (let index = 0; index < lines.length; index++) {
135
134
  if (lines[index].startsWith(' at')) {
136
135
  break;
137
136
  }
@@ -146,17 +145,17 @@ function trySerializeError(err, shouldBeautifyStack, testFile) {
146
145
  return retval;
147
146
  }
148
147
 
149
- function serializeError(origin, shouldBeautifyStack, err, testFile) {
150
- if (!isError(err)) {
148
+ export default function serializeError(origin, shouldBeautifyStack, error, testFile) {
149
+ if (!isError(error)) {
151
150
  return {
152
151
  avaAssertionError: false,
153
152
  nonErrorObject: true,
154
- formatted: concordance.formatDescriptor(concordance.describe(err, concordanceOptions), concordanceOptions)
153
+ formatted: concordance.formatDescriptor(concordance.describe(error, concordanceOptions), concordanceOptions),
155
154
  };
156
155
  }
157
156
 
158
157
  try {
159
- return trySerializeError(err, shouldBeautifyStack, testFile);
158
+ return trySerializeError(error, shouldBeautifyStack, testFile);
160
159
  } catch {
161
160
  const replacement = new Error(`${origin}: Could not serialize error`);
162
161
  return {
@@ -165,9 +164,7 @@ function serializeError(origin, shouldBeautifyStack, err, testFile) {
165
164
  name: replacement.name,
166
165
  message: replacement.message,
167
166
  stack: replacement.stack,
168
- summary: replacement.message
167
+ summary: replacement.message,
169
168
  };
170
169
  }
171
170
  }
172
-
173
- module.exports = serializeError;