ava 0.16.0 → 0.17.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/types/make.js CHANGED
@@ -40,19 +40,27 @@ function generatePrefixed(prefix) {
40
40
  continue;
41
41
  }
42
42
 
43
+ // If `parts` is not sorted, we alias it to the sorted chain.
44
+ if (!isSorted(parts)) {
45
+ const chain = parts.sort().join('.');
46
+ if (exists(parts)) {
47
+ output += '\texport const ' + part + ': typeof test.' + chain + ';\n';
48
+ }
49
+ continue;
50
+ }
51
+
43
52
  // Check that `part` is a valid function name.
44
53
  // `always` is a valid prefix, for instance of `always.after`,
45
54
  // but not a valid function name.
46
55
  if (verify(parts, false)) {
47
- if (!isSorted(parts)) {
48
- output += '\texport const ' + part + ': typeof test.' + parts.sort().join('.') + ';\n';
49
- continue;
50
- } else if (prefix.includes(parts, 'todo')) {
56
+ if (prefix.includes(parts, 'todo')) {
51
57
  output += '\t' + writeFunction(part, 'name: string', 'void');
52
58
  } else {
53
59
  const type = testType(parts);
54
60
  output += '\t' + writeFunction(part, 'name: string, implementation: ' + type);
55
61
  output += '\t' + writeFunction(part, 'implementation: ' + type);
62
+ output += '\t' + writeFunction(part, 'name: string, implementation: Macros<' + type + 'Context>, ...args: any[]');
63
+ output += '\t' + writeFunction(part, 'implementation: Macros<' + type + 'Context>, ...args: any[]');
56
64
  }
57
65
  }
58
66
 
@@ -70,6 +78,10 @@ function writeFunction(name, args) {
70
78
  return 'export function ' + name + '(' + args + '): void;\n';
71
79
  }
72
80
 
81
+ // Checks whether a chain is a valid function name (when `asPrefix === false`)
82
+ // or a valid prefix that could contain members.
83
+ // For instance, `test.always` is not a valid function name, but it is a valid
84
+ // prefix of `test.always.after`.
73
85
  function verify(parts, asPrefix) {
74
86
  const has = arrayHas(parts);
75
87
 
@@ -93,19 +105,39 @@ function verify(parts, asPrefix) {
93
105
  // `always` can only be used with `after` or `afterEach`.
94
106
  // Without it can still be a valid prefix
95
107
  if (has('after') || has('afterEach')) {
96
- if (!asPrefix) {
97
- return false;
98
- }
99
- } else if (!verify(parts.concat(['after'])) && !verify(parts.concat(['afterEach']))) {
108
+ return true;
109
+ }
110
+ if (!verify(parts.concat(['after']), false) && !verify(parts.concat(['afterEach']), false)) {
100
111
  // If `after` nor `afterEach` cannot be added to this prefix,
101
112
  // `always` is not allowed here.
102
113
  return false;
103
114
  }
115
+ // Only allowed as a prefix
116
+ return asPrefix;
104
117
  }
105
118
 
106
119
  return true;
107
120
  }
108
121
 
122
+ // Checks whether a chain is a valid function name or a valid prefix with some member
123
+ function exists(parts) {
124
+ if (verify(parts, false)) {
125
+ // valid function name
126
+ return true;
127
+ }
128
+ if (!verify(parts, true)) {
129
+ // not valid prefix
130
+ return false;
131
+ }
132
+ // valid prefix, check whether it has members
133
+ for (const prefix of allParts) {
134
+ if (!parts.includes(prefix) && exists(parts.concat([prefix]))) {
135
+ return true;
136
+ }
137
+ }
138
+ return false;
139
+ }
140
+
109
141
  // Checks that an array is sorted
110
142
  function isSorted(a) {
111
143
  for (let i = 1; i < a.length; i++) {
@@ -126,7 +158,7 @@ function testType(parts) {
126
158
  type = 'Callback' + type;
127
159
  }
128
160
 
129
- if (!has('beforeEach') && !has('afterEach')) {
161
+ if (!has('before') && !has('after')) {
130
162
  type = 'Contextual' + type;
131
163
  }
132
164
 
package/lib/send.js DELETED
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- // utility to send messages to processes
4
- module.exports = function (ps, name, data) {
5
- if (typeof ps === 'string') {
6
- data = name || {};
7
- name = ps;
8
- ps = process;
9
- }
10
-
11
- ps.send({
12
- name: 'ava-' + name,
13
- data: data,
14
- ava: true
15
- });
16
- };