ava 0.16.0 → 0.18.2

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
@@ -14,9 +14,10 @@
14
14
 
15
15
  const path = require('path');
16
16
  const fs = require('fs');
17
+ const isArraySorted = require('is-array-sorted');
17
18
  const runner = require('../lib/runner');
18
19
 
19
- const arrayHas = parts => part => parts.includes(part);
20
+ const arrayHas = parts => part => parts.indexOf(part) !== -1;
20
21
 
21
22
  const base = fs.readFileSync(path.join(__dirname, 'base.d.ts'), 'utf8');
22
23
 
@@ -35,24 +36,34 @@ function generatePrefixed(prefix) {
35
36
  for (const part of allParts) {
36
37
  const parts = prefix.concat([part]);
37
38
 
38
- if (prefix.includes(part) || !verify(parts, true)) {
39
+ if (prefix.indexOf(part) !== -1 || !verify(parts, true)) {
39
40
  // Function already in prefix or not allowed here
40
41
  continue;
41
42
  }
42
43
 
44
+ // If `parts` is not sorted, we alias it to the sorted chain
45
+ if (!isArraySorted(parts)) {
46
+ const chain = parts.sort().join('.');
47
+
48
+ if (exists(parts)) {
49
+ output += `\texport const ${part}: typeof test.${chain};\n`;
50
+ }
51
+
52
+ continue;
53
+ }
54
+
43
55
  // Check that `part` is a valid function name.
44
56
  // `always` is a valid prefix, for instance of `always.after`,
45
57
  // but not a valid function name.
46
58
  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')) {
59
+ if (parts.indexOf('todo') !== -1) { // eslint-disable-line no-negated-condition
51
60
  output += '\t' + writeFunction(part, 'name: string', 'void');
52
61
  } else {
53
62
  const type = testType(parts);
54
- output += '\t' + writeFunction(part, 'name: string, implementation: ' + type);
55
- output += '\t' + writeFunction(part, 'implementation: ' + type);
63
+ output += '\t' + writeFunction(part, `name: string, implementation: ${type}`);
64
+ output += '\t' + writeFunction(part, `implementation: ${type}`);
65
+ output += '\t' + writeFunction(part, `name: string, implementation: Macros<${type}Context>, ...args: any[]`);
66
+ output += '\t' + writeFunction(part, `implementation: Macros<${type}Context>, ...args: any[]`);
56
67
  }
57
68
  }
58
69
 
@@ -63,13 +74,19 @@ function generatePrefixed(prefix) {
63
74
  return children;
64
75
  }
65
76
 
66
- return 'export namespace ' + ['test'].concat(prefix).join('.') + ' {\n' + output + '}\n' + children;
77
+ const namespace = ['test'].concat(prefix).join('.');
78
+
79
+ return `export namespace ${namespace} {\n${output}}\n${children}`;
67
80
  }
68
81
 
69
82
  function writeFunction(name, args) {
70
- return 'export function ' + name + '(' + args + '): void;\n';
83
+ return `export function ${name}(${args}): void;\n`;
71
84
  }
72
85
 
86
+ // Checks whether a chain is a valid function name (when `asPrefix === false`)
87
+ // or a valid prefix that could contain members.
88
+ // For instance, `test.always` is not a valid function name, but it is a valid
89
+ // prefix of `test.always.after`.
73
90
  function verify(parts, asPrefix) {
74
91
  const has = arrayHas(parts);
75
92
 
@@ -93,28 +110,42 @@ function verify(parts, asPrefix) {
93
110
  // `always` can only be used with `after` or `afterEach`.
94
111
  // Without it can still be a valid prefix
95
112
  if (has('after') || has('afterEach')) {
96
- if (!asPrefix) {
97
- return false;
98
- }
99
- } else if (!verify(parts.concat(['after'])) && !verify(parts.concat(['afterEach']))) {
113
+ return true;
114
+ }
115
+
116
+ if (!verify(parts.concat(['after']), false) && !verify(parts.concat(['afterEach']), false)) {
100
117
  // If `after` nor `afterEach` cannot be added to this prefix,
101
118
  // `always` is not allowed here.
102
119
  return false;
103
120
  }
121
+
122
+ // Only allowed as a prefix
123
+ return asPrefix;
104
124
  }
105
125
 
106
126
  return true;
107
127
  }
108
128
 
109
- // Checks that an array is sorted
110
- function isSorted(a) {
111
- for (let i = 1; i < a.length; i++) {
112
- if (a[i - 1] >= a[i]) {
113
- return false;
129
+ // Checks whether a chain is a valid function name or a valid prefix with some member
130
+ function exists(parts) {
131
+ if (verify(parts, false)) {
132
+ // Valid function name
133
+ return true;
134
+ }
135
+
136
+ if (!verify(parts, true)) {
137
+ // Not valid prefix
138
+ return false;
139
+ }
140
+
141
+ // Valid prefix, check whether it has members
142
+ for (const prefix of allParts) {
143
+ if (parts.indexOf(prefix) === -1 && exists(parts.concat([prefix]))) {
144
+ return true;
114
145
  }
115
146
  }
116
147
 
117
- return true;
148
+ return false;
118
149
  }
119
150
 
120
151
  // Returns the type name of for the test implementation
@@ -123,11 +154,11 @@ function testType(parts) {
123
154
  let type = 'Test';
124
155
 
125
156
  if (has('cb')) {
126
- type = 'Callback' + type;
157
+ type = `Callback${type}`;
127
158
  }
128
159
 
129
- if (!has('beforeEach') && !has('afterEach')) {
130
- type = 'Contextual' + type;
160
+ if (!has('before') && !has('after')) {
161
+ type = `Contextual${type}`;
131
162
  }
132
163
 
133
164
  return type;
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
- };