ava 3.14.0 → 4.0.0-rc.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.
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 +3 -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 +103 -49
  9. package/lib/assert.js +255 -270
  10. package/lib/chalk.js +10 -14
  11. package/lib/cli.js +115 -114
  12. package/lib/code-excerpt.js +12 -11
  13. package/lib/concordance-options.js +27 -64
  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 +137 -162
  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 +70 -95
  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 +28 -25
  42. package/lib/run-status.js +29 -23
  43. package/lib/runner.js +162 -160
  44. package/lib/scheduler.js +53 -0
  45. package/lib/serialize-error.js +61 -64
  46. package/lib/snapshot-manager.js +294 -277
  47. package/lib/test.js +137 -289
  48. package/lib/watcher.js +69 -44
  49. package/lib/worker/base.js +208 -0
  50. package/lib/worker/channel.cjs +258 -0
  51. package/lib/worker/dependency-tracker.js +24 -23
  52. package/lib/worker/{ensure-forked.js → guard-environment.cjs} +5 -3
  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 +72 -66
  60. package/plugin.d.ts +51 -53
  61. package/readme.md +6 -16
  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 -96
  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
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import run from '../lib/cli.js';
3
+
4
+ run();
@@ -0,0 +1,109 @@
1
+ 'use strict';
2
+ const path = require('path');
3
+ const url = require('url');
4
+ const v8 = require('v8');
5
+ const {Worker} = require('worker_threads');
6
+
7
+ const {
8
+ classify,
9
+ hasExtension,
10
+ isHelperish,
11
+ matches,
12
+ normalizeFileForMatching,
13
+ normalizePatterns,
14
+ } = require('../lib/glob-helpers.cjs');
15
+
16
+ const MAX_DATA_LENGTH_EXCLUSIVE = 100 * 1024; // Allocate 100 KiB to exchange globs.
17
+
18
+ let data;
19
+ let sync;
20
+ let worker;
21
+
22
+ const resolveGlobsSync = (projectDir, overrideExtensions, overrideFiles) => {
23
+ if (worker === undefined) {
24
+ const dataBuffer = new SharedArrayBuffer(MAX_DATA_LENGTH_EXCLUSIVE);
25
+ data = new Uint8Array(dataBuffer);
26
+
27
+ const syncBuffer = new SharedArrayBuffer(4);
28
+ sync = new Int32Array(syncBuffer);
29
+
30
+ const filename = path.join(__dirname, '../lib/eslint-plugin-helper-worker.js');
31
+ worker = new Worker(url.pathToFileURL(filename), {
32
+ workerData: {
33
+ dataBuffer,
34
+ syncBuffer,
35
+ firstMessage: {projectDir, overrideExtensions, overrideFiles},
36
+ },
37
+ });
38
+ worker.unref();
39
+ } else {
40
+ worker.postMessage({projectDir, overrideExtensions, overrideFiles});
41
+ }
42
+
43
+ const synchronize = Atomics.wait(sync, 0, 0, 10_000);
44
+ if (synchronize === 'timed-out') {
45
+ throw new Error('Timed out resolving AVA configuration');
46
+ }
47
+
48
+ const byteLength = Atomics.exchange(sync, 0, 0);
49
+ if (byteLength === MAX_DATA_LENGTH_EXCLUSIVE) {
50
+ throw new Error('Globs are over 100 KiB and cannot be resolved');
51
+ }
52
+
53
+ const globsOrError = v8.deserialize(data.slice(0, byteLength));
54
+ if (globsOrError instanceof Error) {
55
+ throw globsOrError;
56
+ }
57
+
58
+ return globsOrError;
59
+ };
60
+
61
+ const helperCache = new Map();
62
+
63
+ function load(projectDir, overrides) {
64
+ const cacheKey = `${JSON.stringify(overrides)}\n${projectDir}`;
65
+ if (helperCache.has(cacheKey)) {
66
+ return helperCache.get(cacheKey);
67
+ }
68
+
69
+ let helperPatterns = [];
70
+ if (overrides && overrides.helpers !== undefined) {
71
+ if (!Array.isArray(overrides.helpers) || overrides.helpers.length === 0) {
72
+ throw new Error('The ’helpers’ override must be an array containing glob patterns.');
73
+ }
74
+
75
+ helperPatterns = normalizePatterns(overrides.helpers);
76
+ }
77
+
78
+ const globs = resolveGlobsSync(projectDir, overrides && overrides.extensions, overrides && overrides.files);
79
+
80
+ const classifyForESLint = file => {
81
+ const {isTest} = classify(file, globs);
82
+ let isHelper = false;
83
+ if (!isTest && hasExtension(globs.extensions, file)) {
84
+ file = normalizeFileForMatching(projectDir, file);
85
+ isHelper = isHelperish(file) || (helperPatterns.length > 0 && matches(file, helperPatterns));
86
+ }
87
+
88
+ return {isHelper, isTest};
89
+ };
90
+
91
+ const helper = Object.freeze({
92
+ classifyFile: classifyForESLint,
93
+ classifyImport: importPath => {
94
+ if (hasExtension(globs.extensions, importPath)) {
95
+ // The importPath has one of the test file extensions: we can classify
96
+ // it directly.
97
+ return classifyForESLint(importPath);
98
+ }
99
+
100
+ // Add the first extension. If multiple extensions are available, assume
101
+ // patterns are not biased to any particular extension.
102
+ return classifyForESLint(`${importPath}.${globs.extensions[0]}`);
103
+ },
104
+ });
105
+ helperCache.set(cacheKey, helper);
106
+ return helper;
107
+ }
108
+
109
+ exports.load = load;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ module.exports = require('../lib/worker/main.cjs');
@@ -0,0 +1,3 @@
1
+ import test from '../lib/worker/main.cjs';
2
+
3
+ export default test;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ module.exports = require('../lib/worker/plugin.cjs');
@@ -0,0 +1,4 @@
1
+ import * as plugin from '../lib/worker/plugin.cjs';
2
+
3
+ const {registerSharedWorker} = plugin;
4
+ export {registerSharedWorker};