@adonisjs/assembler 5.9.0 → 5.9.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/build/commands/Build.d.ts +37 -37
- package/build/commands/Build.js +138 -138
- package/build/commands/Invoke.d.ts +34 -34
- package/build/commands/Invoke.js +221 -221
- package/build/commands/Make/Base.d.ts +30 -30
- package/build/commands/Make/Base.js +75 -75
- package/build/commands/Make/Command.d.ts +35 -35
- package/build/commands/Make/Command.js +82 -82
- package/build/commands/Make/Controller.d.ts +37 -37
- package/build/commands/Make/Controller.js +89 -89
- package/build/commands/Make/Exception.d.ts +32 -32
- package/build/commands/Make/Exception.js +75 -75
- package/build/commands/Make/Listener.d.ts +30 -30
- package/build/commands/Make/Listener.js +70 -70
- package/build/commands/Make/Middleware.d.ts +31 -31
- package/build/commands/Make/Middleware.js +87 -87
- package/build/commands/Make/PreloadFile.d.ts +38 -38
- package/build/commands/Make/PreloadFile.js +157 -157
- package/build/commands/Make/Provider.d.ts +31 -31
- package/build/commands/Make/Provider.js +114 -114
- package/build/commands/Make/Suite.d.ts +41 -41
- package/build/commands/Make/Suite.js +120 -120
- package/build/commands/Make/Test.d.ts +35 -35
- package/build/commands/Make/Test.js +96 -96
- package/build/commands/Make/Validator.d.ts +31 -31
- package/build/commands/Make/Validator.js +71 -71
- package/build/commands/Make/View.d.ts +30 -30
- package/build/commands/Make/View.js +70 -70
- package/build/commands/Serve.d.ts +33 -33
- package/build/commands/Serve.js +112 -112
- package/build/commands/Test.d.ts +57 -57
- package/build/commands/Test.js +159 -159
- package/build/commands/TypeCheck.d.ts +16 -16
- package/build/commands/TypeCheck.js +85 -85
- package/build/config/paths.d.ts +7 -7
- package/build/config/paths.js +18 -18
- package/build/register.d.ts +1 -1
- package/build/register.js +15 -15
- package/build/src/AssetsBundler/index.d.ts +76 -76
- package/build/src/AssetsBundler/index.js +216 -216
- package/build/src/Compiler/index.d.ts +62 -62
- package/build/src/Compiler/index.js +287 -287
- package/build/src/Contracts/index.d.ts +8 -8
- package/build/src/Contracts/index.js +10 -10
- package/build/src/DevServer/index.d.ts +70 -70
- package/build/src/DevServer/index.js +306 -306
- package/build/src/EnvParser/index.d.ts +23 -23
- package/build/src/EnvParser/index.js +52 -52
- package/build/src/HttpServer/index.d.ts +34 -34
- package/build/src/HttpServer/index.js +87 -87
- package/build/src/Manifest/index.d.ts +32 -32
- package/build/src/Manifest/index.js +88 -88
- package/build/src/RcFile/index.d.ts +72 -72
- package/build/src/RcFile/index.js +174 -174
- package/build/src/Test/index.d.ts +75 -75
- package/build/src/Test/index.js +346 -346
- package/build/src/Test/process.d.ts +22 -22
- package/build/src/Test/process.js +68 -68
- package/build/src/Ts/index.d.ts +24 -24
- package/build/src/Ts/index.js +55 -55
- package/build/src/requireHook/index.d.ts +5 -5
- package/build/src/requireHook/index.js +28 -28
- package/build/src/requireHook/ioc-transformer.d.ts +6 -6
- package/build/src/requireHook/ioc-transformer.js +21 -21
- package/package.json +1 -1
package/build/src/Test/index.js
CHANGED
|
@@ -1,346 +1,346 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/assembler
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.TestsServer = void 0;
|
|
15
|
-
const path_1 = require("path");
|
|
16
|
-
const picomatch_1 = __importDefault(require("picomatch"));
|
|
17
|
-
const cliui_1 = require("@poppinss/cliui");
|
|
18
|
-
const require_ts_1 = require("@adonisjs/require-ts");
|
|
19
|
-
const Ts_1 = require("../Ts");
|
|
20
|
-
const RcFile_1 = require("../RcFile");
|
|
21
|
-
const Manifest_1 = require("../Manifest");
|
|
22
|
-
const process_1 = require("./process");
|
|
23
|
-
const paths_1 = require("../../config/paths");
|
|
24
|
-
const EnvParser_1 = require("../EnvParser");
|
|
25
|
-
const get_port_1 = __importDefault(require("get-port"));
|
|
26
|
-
/**
|
|
27
|
-
* Exposes the API to watch project for compilition changes and
|
|
28
|
-
* run/re-run tests
|
|
29
|
-
*/
|
|
30
|
-
class TestsServer {
|
|
31
|
-
constructor(appRoot, filters, nodeArgs = [], logger = cliui_1.logger) {
|
|
32
|
-
this.appRoot = appRoot;
|
|
33
|
-
this.filters = filters;
|
|
34
|
-
this.nodeArgs = nodeArgs;
|
|
35
|
-
this.logger = logger;
|
|
36
|
-
/**
|
|
37
|
-
* A boolean to know if we are watching for filesystem
|
|
38
|
-
*/
|
|
39
|
-
this.watchingFileSystem = false;
|
|
40
|
-
/**
|
|
41
|
-
* Boolean to hold the current state of tests. This is avoid
|
|
42
|
-
* re-running the tests when one run is in progress
|
|
43
|
-
*/
|
|
44
|
-
this.busy = false;
|
|
45
|
-
/**
|
|
46
|
-
* Reference to the typescript compiler
|
|
47
|
-
*/
|
|
48
|
-
this.ts = new Ts_1.Ts(this.appRoot, this.logger);
|
|
49
|
-
/**
|
|
50
|
-
* Reference to the RCFile
|
|
51
|
-
*/
|
|
52
|
-
this.rcFile = new RcFile_1.RcFile(this.appRoot);
|
|
53
|
-
/**
|
|
54
|
-
* Manifest instance to generate ace manifest file
|
|
55
|
-
*/
|
|
56
|
-
this.manifest = new Manifest_1.Manifest(this.appRoot, this.logger);
|
|
57
|
-
/**
|
|
58
|
-
* Require-ts watch helpers
|
|
59
|
-
*/
|
|
60
|
-
this.watchHelpers = (0, require_ts_1.getWatcherHelpers)(this.appRoot);
|
|
61
|
-
/**
|
|
62
|
-
* A method to know if the file is part of the selected suites
|
|
63
|
-
* or not
|
|
64
|
-
*/
|
|
65
|
-
this.isTestSuiteFile = (0, picomatch_1.default)(this.getFilesForSelectedSuites());
|
|
66
|
-
/**
|
|
67
|
-
* Find if the test file part of the applied file filters
|
|
68
|
-
*/
|
|
69
|
-
this.isTestFile = (filePath) => {
|
|
70
|
-
if (!this.filters['--files']) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
const fileName = filePath.replace((0, path_1.extname)(filePath), '');
|
|
74
|
-
return !!this.filters['--files'].find((filter) => {
|
|
75
|
-
if (filePath.endsWith(filter)) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
return fileName.endsWith(filter) || fileName.endsWith(`${filter}.spec`);
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Clear terminal screen
|
|
84
|
-
*/
|
|
85
|
-
clearScreen() {
|
|
86
|
-
process.stdout.write('\u001Bc');
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Returns the glob paths for test suites. Returns all if no
|
|
90
|
-
* filter is applied. Otherwise only the filtered suites
|
|
91
|
-
* are picked.
|
|
92
|
-
*/
|
|
93
|
-
getFilesForSelectedSuites() {
|
|
94
|
-
return this.rcFile.application.rcFile.tests.suites.reduce((result, suite) => {
|
|
95
|
-
if (!suite.files) {
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
if (!this.filters['--suites'] || this.filters['--suites'].includes(suite.name)) {
|
|
99
|
-
result = result.concat(suite.files);
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}, []);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Kill current process
|
|
106
|
-
*/
|
|
107
|
-
kill() {
|
|
108
|
-
process.exit();
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Returns the HOST and the PORT environment variables
|
|
112
|
-
* for the HTTP server
|
|
113
|
-
*/
|
|
114
|
-
async getEnvironmentVariables() {
|
|
115
|
-
const envParser = new EnvParser_1.EnvParser('.env.test');
|
|
116
|
-
await envParser.parse(this.appRoot);
|
|
117
|
-
const envOptions = envParser.asEnvObject(['PORT', 'TZ', 'HOST']);
|
|
118
|
-
const HOST = process.env.HOST || envOptions.HOST || '0.0.0.0';
|
|
119
|
-
let PORT = Number(process.env.PORT || envOptions.PORT);
|
|
120
|
-
/**
|
|
121
|
-
* Use the port defined inside ".env.test" file or use
|
|
122
|
-
* a random port
|
|
123
|
-
*/
|
|
124
|
-
PORT = await (0, get_port_1.default)({
|
|
125
|
-
port: !isNaN(PORT) ? [PORT] : [],
|
|
126
|
-
host: HOST,
|
|
127
|
-
});
|
|
128
|
-
return { HOST, PORT: String(PORT) };
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Run tests. Use [[watch]] to also watch for file
|
|
132
|
-
* changes
|
|
133
|
-
*/
|
|
134
|
-
async run(filePath) {
|
|
135
|
-
if (this.busy) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
this.clearScreen();
|
|
139
|
-
const filters = { ...this.filters };
|
|
140
|
-
/**
|
|
141
|
-
* Overwrite files filter when a specific file path
|
|
142
|
-
* is mentioned
|
|
143
|
-
*/
|
|
144
|
-
if (filePath) {
|
|
145
|
-
filters['--files'] = [filePath];
|
|
146
|
-
}
|
|
147
|
-
this.busy = true;
|
|
148
|
-
const { hasErrors } = await new process_1.TestProcess(paths_1.TESTS_ENTRY_FILE, this.appRoot, filters, this.nodeArgs, this.logger, await this.getEnvironmentVariables()).run();
|
|
149
|
-
this.busy = false;
|
|
150
|
-
if (!this.watchingFileSystem) {
|
|
151
|
-
if (hasErrors) {
|
|
152
|
-
process.exitCode = 1;
|
|
153
|
-
}
|
|
154
|
-
this.kill();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Build and watch for file changes
|
|
159
|
-
*/
|
|
160
|
-
async watch(poll = false) {
|
|
161
|
-
this.watchingFileSystem = true;
|
|
162
|
-
/**
|
|
163
|
-
* Clear require-ts cache
|
|
164
|
-
*/
|
|
165
|
-
this.watchHelpers.clear();
|
|
166
|
-
/**
|
|
167
|
-
* Run tests
|
|
168
|
-
*/
|
|
169
|
-
await this.run();
|
|
170
|
-
/**
|
|
171
|
-
* Parse config to find the files excluded inside
|
|
172
|
-
* tsconfig file
|
|
173
|
-
*/
|
|
174
|
-
const config = this.ts.parseConfig();
|
|
175
|
-
if (!config) {
|
|
176
|
-
this.logger.warning('Cannot start watcher because of errors in the tsconfig file');
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Stick file watcher
|
|
181
|
-
*/
|
|
182
|
-
const watcher = this.ts.tsCompiler.watcher(config, 'raw');
|
|
183
|
-
/**
|
|
184
|
-
* Watcher is ready after first compile
|
|
185
|
-
*/
|
|
186
|
-
watcher.on('watcher:ready', () => {
|
|
187
|
-
this.logger.info('watching file system for changes');
|
|
188
|
-
});
|
|
189
|
-
/**
|
|
190
|
-
* Source file removed
|
|
191
|
-
*/
|
|
192
|
-
watcher.on('source:unlink', async ({ absPath, relativePath }) => {
|
|
193
|
-
this.watchHelpers.clear(absPath);
|
|
194
|
-
if (this.busy) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
this.logger.action('delete').succeeded(relativePath);
|
|
198
|
-
/**
|
|
199
|
-
* Generate manifest when filePath is a commands path
|
|
200
|
-
*/
|
|
201
|
-
if (this.rcFile.isCommandsPath(relativePath)) {
|
|
202
|
-
this.manifest.generate();
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Run all tests when any of the source, except the
|
|
206
|
-
* test file changes
|
|
207
|
-
*/
|
|
208
|
-
if (!this.rcFile.isTestsFile(relativePath)) {
|
|
209
|
-
await this.run();
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
/**
|
|
213
|
-
* Source file added
|
|
214
|
-
*/
|
|
215
|
-
watcher.on('source:add', async ({ absPath, relativePath }) => {
|
|
216
|
-
this.watchHelpers.clear(absPath);
|
|
217
|
-
if (this.busy) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
this.logger.action('add').succeeded(relativePath);
|
|
221
|
-
/**
|
|
222
|
-
* Run all tests when any of the source, except the
|
|
223
|
-
* test file changes
|
|
224
|
-
*/
|
|
225
|
-
if (!this.rcFile.isTestsFile(relativePath)) {
|
|
226
|
-
await this.run();
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Run only the changed file if it part of the test
|
|
231
|
-
* suites (respecting filters)
|
|
232
|
-
*/
|
|
233
|
-
if (this.isTestSuiteFile(relativePath) && this.isTestFile(relativePath)) {
|
|
234
|
-
await this.run(relativePath);
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
/**
|
|
238
|
-
* Source file changed
|
|
239
|
-
*/
|
|
240
|
-
watcher.on('source:change', async ({ absPath, relativePath }) => {
|
|
241
|
-
this.watchHelpers.clear(absPath);
|
|
242
|
-
if (this.busy) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
this.logger.action('update').succeeded(relativePath);
|
|
246
|
-
/**
|
|
247
|
-
* Generate manifest when filePath is a commands path
|
|
248
|
-
*/
|
|
249
|
-
if (this.rcFile.isCommandsPath(relativePath)) {
|
|
250
|
-
this.manifest.generate();
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Run all tests when any of the source, except the
|
|
254
|
-
* test file changes
|
|
255
|
-
*/
|
|
256
|
-
if (!this.rcFile.isTestsFile(relativePath)) {
|
|
257
|
-
await this.run();
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Run only the changed file if it part of the test
|
|
262
|
-
* suites (respecting filters)
|
|
263
|
-
*/
|
|
264
|
-
if (this.isTestSuiteFile(relativePath) && this.isTestFile(relativePath)) {
|
|
265
|
-
await this.run(relativePath);
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
/**
|
|
269
|
-
* New file added
|
|
270
|
-
*/
|
|
271
|
-
watcher.on('add', async ({ relativePath }) => {
|
|
272
|
-
if (this.busy) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
276
|
-
this.logger.action('create').succeeded(relativePath);
|
|
277
|
-
await this.run();
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
const metaData = this.rcFile.getMetaData(relativePath);
|
|
281
|
-
if (!metaData.metaFile) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
this.logger.action('create').succeeded(relativePath);
|
|
285
|
-
await this.run();
|
|
286
|
-
});
|
|
287
|
-
/**
|
|
288
|
-
* File changed
|
|
289
|
-
*/
|
|
290
|
-
watcher.on('change', async ({ relativePath }) => {
|
|
291
|
-
if (this.busy) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
295
|
-
this.logger.action('update').succeeded(relativePath);
|
|
296
|
-
await this.run();
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
const metaData = this.rcFile.getMetaData(relativePath);
|
|
300
|
-
if (!metaData.metaFile) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
this.logger.action('update').succeeded(relativePath);
|
|
304
|
-
await this.run();
|
|
305
|
-
});
|
|
306
|
-
/**
|
|
307
|
-
* File removed
|
|
308
|
-
*/
|
|
309
|
-
watcher.on('unlink', async ({ relativePath }) => {
|
|
310
|
-
if (this.busy) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
314
|
-
this.logger.action('delete').succeeded(relativePath);
|
|
315
|
-
await this.run();
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
const metaData = this.rcFile.getMetaData(relativePath);
|
|
319
|
-
if (!metaData.metaFile) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
if (metaData.rcFile) {
|
|
323
|
-
this.logger.info('cannot continue after deletion of .adonisrc.json file');
|
|
324
|
-
watcher.chokidar.close();
|
|
325
|
-
this.kill();
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
this.logger.action('delete').succeeded(relativePath);
|
|
329
|
-
await this.run();
|
|
330
|
-
});
|
|
331
|
-
/**
|
|
332
|
-
* Start the watcher
|
|
333
|
-
*/
|
|
334
|
-
watcher.watch(['.'], {
|
|
335
|
-
usePolling: poll,
|
|
336
|
-
});
|
|
337
|
-
/**
|
|
338
|
-
* Kill when watcher recieves an error
|
|
339
|
-
*/
|
|
340
|
-
watcher.chokidar.on('error', (error) => {
|
|
341
|
-
this.logger.fatal(error);
|
|
342
|
-
this.kill();
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
exports.TestsServer = TestsServer;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* @adonisjs/assembler
|
|
4
|
+
*
|
|
5
|
+
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.TestsServer = void 0;
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const picomatch_1 = __importDefault(require("picomatch"));
|
|
17
|
+
const cliui_1 = require("@poppinss/cliui");
|
|
18
|
+
const require_ts_1 = require("@adonisjs/require-ts");
|
|
19
|
+
const Ts_1 = require("../Ts");
|
|
20
|
+
const RcFile_1 = require("../RcFile");
|
|
21
|
+
const Manifest_1 = require("../Manifest");
|
|
22
|
+
const process_1 = require("./process");
|
|
23
|
+
const paths_1 = require("../../config/paths");
|
|
24
|
+
const EnvParser_1 = require("../EnvParser");
|
|
25
|
+
const get_port_1 = __importDefault(require("get-port"));
|
|
26
|
+
/**
|
|
27
|
+
* Exposes the API to watch project for compilition changes and
|
|
28
|
+
* run/re-run tests
|
|
29
|
+
*/
|
|
30
|
+
class TestsServer {
|
|
31
|
+
constructor(appRoot, filters, nodeArgs = [], logger = cliui_1.logger) {
|
|
32
|
+
this.appRoot = appRoot;
|
|
33
|
+
this.filters = filters;
|
|
34
|
+
this.nodeArgs = nodeArgs;
|
|
35
|
+
this.logger = logger;
|
|
36
|
+
/**
|
|
37
|
+
* A boolean to know if we are watching for filesystem
|
|
38
|
+
*/
|
|
39
|
+
this.watchingFileSystem = false;
|
|
40
|
+
/**
|
|
41
|
+
* Boolean to hold the current state of tests. This is avoid
|
|
42
|
+
* re-running the tests when one run is in progress
|
|
43
|
+
*/
|
|
44
|
+
this.busy = false;
|
|
45
|
+
/**
|
|
46
|
+
* Reference to the typescript compiler
|
|
47
|
+
*/
|
|
48
|
+
this.ts = new Ts_1.Ts(this.appRoot, this.logger);
|
|
49
|
+
/**
|
|
50
|
+
* Reference to the RCFile
|
|
51
|
+
*/
|
|
52
|
+
this.rcFile = new RcFile_1.RcFile(this.appRoot);
|
|
53
|
+
/**
|
|
54
|
+
* Manifest instance to generate ace manifest file
|
|
55
|
+
*/
|
|
56
|
+
this.manifest = new Manifest_1.Manifest(this.appRoot, this.logger);
|
|
57
|
+
/**
|
|
58
|
+
* Require-ts watch helpers
|
|
59
|
+
*/
|
|
60
|
+
this.watchHelpers = (0, require_ts_1.getWatcherHelpers)(this.appRoot);
|
|
61
|
+
/**
|
|
62
|
+
* A method to know if the file is part of the selected suites
|
|
63
|
+
* or not
|
|
64
|
+
*/
|
|
65
|
+
this.isTestSuiteFile = (0, picomatch_1.default)(this.getFilesForSelectedSuites());
|
|
66
|
+
/**
|
|
67
|
+
* Find if the test file part of the applied file filters
|
|
68
|
+
*/
|
|
69
|
+
this.isTestFile = (filePath) => {
|
|
70
|
+
if (!this.filters['--files']) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const fileName = filePath.replace((0, path_1.extname)(filePath), '');
|
|
74
|
+
return !!this.filters['--files'].find((filter) => {
|
|
75
|
+
if (filePath.endsWith(filter)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return fileName.endsWith(filter) || fileName.endsWith(`${filter}.spec`);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Clear terminal screen
|
|
84
|
+
*/
|
|
85
|
+
clearScreen() {
|
|
86
|
+
process.stdout.write('\u001Bc');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the glob paths for test suites. Returns all if no
|
|
90
|
+
* filter is applied. Otherwise only the filtered suites
|
|
91
|
+
* are picked.
|
|
92
|
+
*/
|
|
93
|
+
getFilesForSelectedSuites() {
|
|
94
|
+
return this.rcFile.application.rcFile.tests.suites.reduce((result, suite) => {
|
|
95
|
+
if (!suite.files) {
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
if (!this.filters['--suites'] || this.filters['--suites'].includes(suite.name)) {
|
|
99
|
+
result = result.concat(suite.files);
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}, []);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Kill current process
|
|
106
|
+
*/
|
|
107
|
+
kill() {
|
|
108
|
+
process.exit();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns the HOST and the PORT environment variables
|
|
112
|
+
* for the HTTP server
|
|
113
|
+
*/
|
|
114
|
+
async getEnvironmentVariables() {
|
|
115
|
+
const envParser = new EnvParser_1.EnvParser('.env.test');
|
|
116
|
+
await envParser.parse(this.appRoot);
|
|
117
|
+
const envOptions = envParser.asEnvObject(['PORT', 'TZ', 'HOST']);
|
|
118
|
+
const HOST = process.env.HOST || envOptions.HOST || '0.0.0.0';
|
|
119
|
+
let PORT = Number(process.env.PORT || envOptions.PORT);
|
|
120
|
+
/**
|
|
121
|
+
* Use the port defined inside ".env.test" file or use
|
|
122
|
+
* a random port
|
|
123
|
+
*/
|
|
124
|
+
PORT = await (0, get_port_1.default)({
|
|
125
|
+
port: !isNaN(PORT) ? [PORT] : [],
|
|
126
|
+
host: HOST,
|
|
127
|
+
});
|
|
128
|
+
return { HOST, PORT: String(PORT) };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Run tests. Use [[watch]] to also watch for file
|
|
132
|
+
* changes
|
|
133
|
+
*/
|
|
134
|
+
async run(filePath) {
|
|
135
|
+
if (this.busy) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.clearScreen();
|
|
139
|
+
const filters = { ...this.filters };
|
|
140
|
+
/**
|
|
141
|
+
* Overwrite files filter when a specific file path
|
|
142
|
+
* is mentioned
|
|
143
|
+
*/
|
|
144
|
+
if (filePath) {
|
|
145
|
+
filters['--files'] = [filePath.replace(/\\/g, '/')];
|
|
146
|
+
}
|
|
147
|
+
this.busy = true;
|
|
148
|
+
const { hasErrors } = await new process_1.TestProcess(paths_1.TESTS_ENTRY_FILE, this.appRoot, filters, this.nodeArgs, this.logger, await this.getEnvironmentVariables()).run();
|
|
149
|
+
this.busy = false;
|
|
150
|
+
if (!this.watchingFileSystem) {
|
|
151
|
+
if (hasErrors) {
|
|
152
|
+
process.exitCode = 1;
|
|
153
|
+
}
|
|
154
|
+
this.kill();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build and watch for file changes
|
|
159
|
+
*/
|
|
160
|
+
async watch(poll = false) {
|
|
161
|
+
this.watchingFileSystem = true;
|
|
162
|
+
/**
|
|
163
|
+
* Clear require-ts cache
|
|
164
|
+
*/
|
|
165
|
+
this.watchHelpers.clear();
|
|
166
|
+
/**
|
|
167
|
+
* Run tests
|
|
168
|
+
*/
|
|
169
|
+
await this.run();
|
|
170
|
+
/**
|
|
171
|
+
* Parse config to find the files excluded inside
|
|
172
|
+
* tsconfig file
|
|
173
|
+
*/
|
|
174
|
+
const config = this.ts.parseConfig();
|
|
175
|
+
if (!config) {
|
|
176
|
+
this.logger.warning('Cannot start watcher because of errors in the tsconfig file');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Stick file watcher
|
|
181
|
+
*/
|
|
182
|
+
const watcher = this.ts.tsCompiler.watcher(config, 'raw');
|
|
183
|
+
/**
|
|
184
|
+
* Watcher is ready after first compile
|
|
185
|
+
*/
|
|
186
|
+
watcher.on('watcher:ready', () => {
|
|
187
|
+
this.logger.info('watching file system for changes');
|
|
188
|
+
});
|
|
189
|
+
/**
|
|
190
|
+
* Source file removed
|
|
191
|
+
*/
|
|
192
|
+
watcher.on('source:unlink', async ({ absPath, relativePath }) => {
|
|
193
|
+
this.watchHelpers.clear(absPath);
|
|
194
|
+
if (this.busy) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.logger.action('delete').succeeded(relativePath);
|
|
198
|
+
/**
|
|
199
|
+
* Generate manifest when filePath is a commands path
|
|
200
|
+
*/
|
|
201
|
+
if (this.rcFile.isCommandsPath(relativePath)) {
|
|
202
|
+
this.manifest.generate();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Run all tests when any of the source, except the
|
|
206
|
+
* test file changes
|
|
207
|
+
*/
|
|
208
|
+
if (!this.rcFile.isTestsFile(relativePath)) {
|
|
209
|
+
await this.run();
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
/**
|
|
213
|
+
* Source file added
|
|
214
|
+
*/
|
|
215
|
+
watcher.on('source:add', async ({ absPath, relativePath }) => {
|
|
216
|
+
this.watchHelpers.clear(absPath);
|
|
217
|
+
if (this.busy) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.logger.action('add').succeeded(relativePath);
|
|
221
|
+
/**
|
|
222
|
+
* Run all tests when any of the source, except the
|
|
223
|
+
* test file changes
|
|
224
|
+
*/
|
|
225
|
+
if (!this.rcFile.isTestsFile(relativePath)) {
|
|
226
|
+
await this.run();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Run only the changed file if it part of the test
|
|
231
|
+
* suites (respecting filters)
|
|
232
|
+
*/
|
|
233
|
+
if (this.isTestSuiteFile(relativePath) && this.isTestFile(relativePath)) {
|
|
234
|
+
await this.run(relativePath);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
/**
|
|
238
|
+
* Source file changed
|
|
239
|
+
*/
|
|
240
|
+
watcher.on('source:change', async ({ absPath, relativePath }) => {
|
|
241
|
+
this.watchHelpers.clear(absPath);
|
|
242
|
+
if (this.busy) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.logger.action('update').succeeded(relativePath);
|
|
246
|
+
/**
|
|
247
|
+
* Generate manifest when filePath is a commands path
|
|
248
|
+
*/
|
|
249
|
+
if (this.rcFile.isCommandsPath(relativePath)) {
|
|
250
|
+
this.manifest.generate();
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Run all tests when any of the source, except the
|
|
254
|
+
* test file changes
|
|
255
|
+
*/
|
|
256
|
+
if (!this.rcFile.isTestsFile(relativePath)) {
|
|
257
|
+
await this.run();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Run only the changed file if it part of the test
|
|
262
|
+
* suites (respecting filters)
|
|
263
|
+
*/
|
|
264
|
+
if (this.isTestSuiteFile(relativePath) && this.isTestFile(relativePath)) {
|
|
265
|
+
await this.run(relativePath);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
/**
|
|
269
|
+
* New file added
|
|
270
|
+
*/
|
|
271
|
+
watcher.on('add', async ({ relativePath }) => {
|
|
272
|
+
if (this.busy) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
276
|
+
this.logger.action('create').succeeded(relativePath);
|
|
277
|
+
await this.run();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const metaData = this.rcFile.getMetaData(relativePath);
|
|
281
|
+
if (!metaData.metaFile) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.logger.action('create').succeeded(relativePath);
|
|
285
|
+
await this.run();
|
|
286
|
+
});
|
|
287
|
+
/**
|
|
288
|
+
* File changed
|
|
289
|
+
*/
|
|
290
|
+
watcher.on('change', async ({ relativePath }) => {
|
|
291
|
+
if (this.busy) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
295
|
+
this.logger.action('update').succeeded(relativePath);
|
|
296
|
+
await this.run();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const metaData = this.rcFile.getMetaData(relativePath);
|
|
300
|
+
if (!metaData.metaFile) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
this.logger.action('update').succeeded(relativePath);
|
|
304
|
+
await this.run();
|
|
305
|
+
});
|
|
306
|
+
/**
|
|
307
|
+
* File removed
|
|
308
|
+
*/
|
|
309
|
+
watcher.on('unlink', async ({ relativePath }) => {
|
|
310
|
+
if (this.busy) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
314
|
+
this.logger.action('delete').succeeded(relativePath);
|
|
315
|
+
await this.run();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const metaData = this.rcFile.getMetaData(relativePath);
|
|
319
|
+
if (!metaData.metaFile) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (metaData.rcFile) {
|
|
323
|
+
this.logger.info('cannot continue after deletion of .adonisrc.json file');
|
|
324
|
+
watcher.chokidar.close();
|
|
325
|
+
this.kill();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
this.logger.action('delete').succeeded(relativePath);
|
|
329
|
+
await this.run();
|
|
330
|
+
});
|
|
331
|
+
/**
|
|
332
|
+
* Start the watcher
|
|
333
|
+
*/
|
|
334
|
+
watcher.watch(['.'], {
|
|
335
|
+
usePolling: poll,
|
|
336
|
+
});
|
|
337
|
+
/**
|
|
338
|
+
* Kill when watcher recieves an error
|
|
339
|
+
*/
|
|
340
|
+
watcher.chokidar.on('error', (error) => {
|
|
341
|
+
this.logger.fatal(error);
|
|
342
|
+
this.kill();
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
exports.TestsServer = TestsServer;
|