@adonisjs/assembler 6.1.3-9 → 7.0.0-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/README.md +418 -11
- package/build/index.js +999 -11
- package/build/index.js.map +1 -0
- package/build/src/bundler.d.ts +3 -1
- package/build/src/code_transformer/main.d.ts +48 -0
- package/build/src/code_transformer/main.js +478 -0
- package/build/src/code_transformer/main.js.map +1 -0
- package/build/src/code_transformer/rc_file_transformer.d.ts +43 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/dev_server.d.ts +2 -2
- package/build/src/helpers.d.ts +7 -6
- package/build/src/test_runner.d.ts +8 -7
- package/build/src/types.d.ts +157 -20
- package/package.json +72 -46
- package/build/src/assets_dev_server.js +0 -158
- package/build/src/bundler.js +0 -223
- package/build/src/dev_server.js +0 -253
- package/build/src/helpers.js +0 -142
- package/build/src/test_runner.js +0 -287
- package/build/src/types.js +0 -9
package/build/src/test_runner.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/assembler
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import picomatch from 'picomatch';
|
|
10
|
-
import { cliui } from '@poppinss/cliui';
|
|
11
|
-
import { AssetsDevServer } from './assets_dev_server.js';
|
|
12
|
-
import { getPort, isDotEnvFile, runNode, watch } from './helpers.js';
|
|
13
|
-
/**
|
|
14
|
-
* Instance of CLIUI
|
|
15
|
-
*/
|
|
16
|
-
const ui = cliui();
|
|
17
|
-
/**
|
|
18
|
-
* Exposes the API to start the development. Optionally, the watch API can be
|
|
19
|
-
* used to watch for file changes and restart the development server.
|
|
20
|
-
*
|
|
21
|
-
* The Dev server performs the following actions
|
|
22
|
-
*
|
|
23
|
-
* - Assigns a random PORT, when PORT inside .env file is in use
|
|
24
|
-
* - Uses tsconfig.json file to collect a list of files to watch.
|
|
25
|
-
* - Uses metaFiles from .adonisrc.json file to collect a list of files to watch.
|
|
26
|
-
* - Restart HTTP server on every file change.
|
|
27
|
-
*/
|
|
28
|
-
export class TestRunner {
|
|
29
|
-
#cwd;
|
|
30
|
-
#logger = ui.logger;
|
|
31
|
-
#options;
|
|
32
|
-
#scriptFile = 'bin/test.js';
|
|
33
|
-
#isMetaFile;
|
|
34
|
-
#isTestFile;
|
|
35
|
-
/**
|
|
36
|
-
* In watch mode, after a file is changed, we wait for the current
|
|
37
|
-
* set of tests to finish before triggering a re-run. Therefore,
|
|
38
|
-
* we use this flag to know if we are already busy in running
|
|
39
|
-
* tests and ignore file-changes.
|
|
40
|
-
*/
|
|
41
|
-
#isBusy = false;
|
|
42
|
-
#onError;
|
|
43
|
-
#onClose;
|
|
44
|
-
#testScript;
|
|
45
|
-
#watcher;
|
|
46
|
-
#assetsServer;
|
|
47
|
-
/**
|
|
48
|
-
* Getting reference to colors library from logger
|
|
49
|
-
*/
|
|
50
|
-
get #colors() {
|
|
51
|
-
return this.#logger.getColors();
|
|
52
|
-
}
|
|
53
|
-
constructor(cwd, options) {
|
|
54
|
-
this.#cwd = cwd;
|
|
55
|
-
this.#options = options;
|
|
56
|
-
this.#isMetaFile = picomatch((this.#options.metaFiles || []).map(({ pattern }) => pattern));
|
|
57
|
-
this.#isTestFile = picomatch(this.#options.suites
|
|
58
|
-
.filter((suite) => {
|
|
59
|
-
if (this.#options.filters.suites) {
|
|
60
|
-
this.#options.filters.suites.includes(suite.name);
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
})
|
|
64
|
-
.map((suite) => suite.files)
|
|
65
|
-
.flat(1));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Converts all known filters to CLI args.
|
|
69
|
-
*
|
|
70
|
-
* The following code snippet may seem like repetitive code. But, it
|
|
71
|
-
* is done intentionally to have visibility around how each filter
|
|
72
|
-
* is converted to an arg.
|
|
73
|
-
*/
|
|
74
|
-
#convertFiltersToArgs(filters) {
|
|
75
|
-
const args = [];
|
|
76
|
-
if (filters.suites) {
|
|
77
|
-
args.push(...filters.suites);
|
|
78
|
-
}
|
|
79
|
-
if (filters.files) {
|
|
80
|
-
args.push('--files');
|
|
81
|
-
args.push(filters.files.join(','));
|
|
82
|
-
}
|
|
83
|
-
if (filters.groups) {
|
|
84
|
-
args.push('--groups');
|
|
85
|
-
args.push(filters.groups.join(','));
|
|
86
|
-
}
|
|
87
|
-
if (filters.tags) {
|
|
88
|
-
args.push('--tags');
|
|
89
|
-
args.push(filters.tags.join(','));
|
|
90
|
-
}
|
|
91
|
-
if (filters.ignoreTags) {
|
|
92
|
-
args.push('--ignore-tags');
|
|
93
|
-
args.push(filters.ignoreTags.join(','));
|
|
94
|
-
}
|
|
95
|
-
if (filters.tests) {
|
|
96
|
-
args.push('--ignore-tests');
|
|
97
|
-
args.push(filters.tests.join(','));
|
|
98
|
-
}
|
|
99
|
-
return args;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Conditionally clear the terminal screen
|
|
103
|
-
*/
|
|
104
|
-
#clearScreen() {
|
|
105
|
-
if (this.#options.clearScreen) {
|
|
106
|
-
process.stdout.write('\u001Bc');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Runs tests
|
|
111
|
-
*/
|
|
112
|
-
#runTests(port, filtersArgs, mode) {
|
|
113
|
-
this.#isBusy = true;
|
|
114
|
-
this.#testScript = runNode(this.#cwd, {
|
|
115
|
-
script: this.#scriptFile,
|
|
116
|
-
env: { PORT: port, ...this.#options.env },
|
|
117
|
-
nodeArgs: this.#options.nodeArgs,
|
|
118
|
-
scriptArgs: filtersArgs.concat(this.#options.scriptArgs),
|
|
119
|
-
});
|
|
120
|
-
this.#testScript
|
|
121
|
-
.then((result) => {
|
|
122
|
-
if (mode === 'nonblocking') {
|
|
123
|
-
this.#onClose?.(result.exitCode);
|
|
124
|
-
this.close();
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
.catch((error) => {
|
|
128
|
-
if (mode === 'nonblocking') {
|
|
129
|
-
this.#onError?.(error);
|
|
130
|
-
this.close();
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
.finally(() => {
|
|
134
|
-
this.#isBusy = false;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Restarts the HTTP server
|
|
139
|
-
*/
|
|
140
|
-
#rerunTests(port, filtersArgs) {
|
|
141
|
-
if (this.#testScript) {
|
|
142
|
-
this.#testScript.removeAllListeners();
|
|
143
|
-
this.#testScript.kill('SIGKILL');
|
|
144
|
-
}
|
|
145
|
-
this.#runTests(port, filtersArgs, 'blocking');
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Starts the assets server
|
|
149
|
-
*/
|
|
150
|
-
#startAssetsServer() {
|
|
151
|
-
this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets);
|
|
152
|
-
this.#assetsServer.setLogger(this.#logger);
|
|
153
|
-
this.#assetsServer.start();
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Handles a non TypeScript file change
|
|
157
|
-
*/
|
|
158
|
-
#handleFileChange(action, port, filters, relativePath) {
|
|
159
|
-
if (this.#isBusy) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (isDotEnvFile(relativePath) || this.#isMetaFile(relativePath)) {
|
|
163
|
-
this.#clearScreen();
|
|
164
|
-
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
165
|
-
this.#rerunTests(port, filters);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Handles TypeScript source file change
|
|
170
|
-
*/
|
|
171
|
-
#handleSourceFileChange(action, port, filters, relativePath) {
|
|
172
|
-
if (this.#isBusy) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
this.#clearScreen();
|
|
176
|
-
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
177
|
-
/**
|
|
178
|
-
* If changed file is a test file after considering the initial filters,
|
|
179
|
-
* then only run that file
|
|
180
|
-
*/
|
|
181
|
-
if (this.#isTestFile(relativePath)) {
|
|
182
|
-
this.#rerunTests(port, this.#convertFiltersToArgs({
|
|
183
|
-
...this.#options.filters,
|
|
184
|
-
files: [relativePath],
|
|
185
|
-
}));
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
this.#rerunTests(port, filters);
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Set a custom CLI UI logger
|
|
192
|
-
*/
|
|
193
|
-
setLogger(logger) {
|
|
194
|
-
this.#logger = logger;
|
|
195
|
-
this.#assetsServer?.setLogger(logger);
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Add listener to get notified when dev server is
|
|
200
|
-
* closed
|
|
201
|
-
*/
|
|
202
|
-
onClose(callback) {
|
|
203
|
-
this.#onClose = callback;
|
|
204
|
-
return this;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Add listener to get notified when dev server exists
|
|
208
|
-
* with an error
|
|
209
|
-
*/
|
|
210
|
-
onError(callback) {
|
|
211
|
-
this.#onError = callback;
|
|
212
|
-
return this;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Close watchers and running child processes
|
|
216
|
-
*/
|
|
217
|
-
async close() {
|
|
218
|
-
await this.#watcher?.close();
|
|
219
|
-
this.#assetsServer?.stop();
|
|
220
|
-
if (this.#testScript) {
|
|
221
|
-
this.#testScript.removeAllListeners();
|
|
222
|
-
this.#testScript.kill('SIGKILL');
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Runs tests
|
|
227
|
-
*/
|
|
228
|
-
async run() {
|
|
229
|
-
const port = String(await getPort(this.#cwd));
|
|
230
|
-
const initialFilters = this.#convertFiltersToArgs(this.#options.filters);
|
|
231
|
-
this.#clearScreen();
|
|
232
|
-
this.#startAssetsServer();
|
|
233
|
-
this.#logger.info('booting application to run tests...');
|
|
234
|
-
this.#runTests(port, initialFilters, 'nonblocking');
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Run tests in watch mode
|
|
238
|
-
*/
|
|
239
|
-
async runAndWatch(ts, options) {
|
|
240
|
-
const port = String(await getPort(this.#cwd));
|
|
241
|
-
const initialFilters = this.#convertFiltersToArgs(this.#options.filters);
|
|
242
|
-
this.#clearScreen();
|
|
243
|
-
this.#startAssetsServer();
|
|
244
|
-
this.#logger.info('booting application to run tests...');
|
|
245
|
-
this.#runTests(port, initialFilters, 'blocking');
|
|
246
|
-
/**
|
|
247
|
-
* Create watcher using tsconfig.json file
|
|
248
|
-
*/
|
|
249
|
-
const output = watch(this.#cwd, ts, options || {});
|
|
250
|
-
if (!output) {
|
|
251
|
-
this.#onClose?.(1);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Storing reference to watcher, so that we can close it
|
|
256
|
-
* when HTTP server exists with error
|
|
257
|
-
*/
|
|
258
|
-
this.#watcher = output.chokidar;
|
|
259
|
-
/**
|
|
260
|
-
* Notify the watcher is ready
|
|
261
|
-
*/
|
|
262
|
-
output.watcher.on('watcher:ready', () => {
|
|
263
|
-
this.#logger.info('watching file system for changes...');
|
|
264
|
-
});
|
|
265
|
-
/**
|
|
266
|
-
* Cleanup when watcher dies
|
|
267
|
-
*/
|
|
268
|
-
output.chokidar.on('error', (error) => {
|
|
269
|
-
this.#logger.warning('file system watcher failure');
|
|
270
|
-
this.#logger.fatal(error);
|
|
271
|
-
this.#onError?.(error);
|
|
272
|
-
output.chokidar.close();
|
|
273
|
-
});
|
|
274
|
-
/**
|
|
275
|
-
* Changes in TypeScript source file
|
|
276
|
-
*/
|
|
277
|
-
output.watcher.on('source:add', ({ relativePath }) => this.#handleSourceFileChange('add', port, initialFilters, relativePath));
|
|
278
|
-
output.watcher.on('source:change', ({ relativePath }) => this.#handleSourceFileChange('update', port, initialFilters, relativePath));
|
|
279
|
-
output.watcher.on('source:unlink', ({ relativePath }) => this.#handleSourceFileChange('delete', port, initialFilters, relativePath));
|
|
280
|
-
/**
|
|
281
|
-
* Changes in non-TypeScript source files
|
|
282
|
-
*/
|
|
283
|
-
output.watcher.on('add', ({ relativePath }) => this.#handleFileChange('add', port, initialFilters, relativePath));
|
|
284
|
-
output.watcher.on('change', ({ relativePath }) => this.#handleFileChange('update', port, initialFilters, relativePath));
|
|
285
|
-
output.watcher.on('unlink', ({ relativePath }) => this.#handleFileChange('delete', port, initialFilters, relativePath));
|
|
286
|
-
}
|
|
287
|
-
}
|