@adonisjs/assembler 6.1.3-8 → 6.1.3-9

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.
@@ -30,6 +30,10 @@ export declare class DevServer {
30
30
  * with an error
31
31
  */
32
32
  onError(callback: (error: any) => any): this;
33
+ /**
34
+ * Close watchers and running child processes
35
+ */
36
+ close(): Promise<void>;
33
37
  /**
34
38
  * Start the development server
35
39
  */
@@ -94,7 +94,6 @@ export class DevServer {
94
94
  });
95
95
  this.#httpServer
96
96
  .then((result) => {
97
- this.#logger.warning(`underlying HTTP server closed with status code "${result.exitCode}"`);
98
97
  if (mode === 'nonblocking') {
99
98
  this.#onClose?.(result.exitCode);
100
99
  this.#watcher?.close();
@@ -102,9 +101,11 @@ export class DevServer {
102
101
  }
103
102
  })
104
103
  .catch((error) => {
105
- this.#onError?.(error);
106
- this.#watcher?.close();
107
- this.#assetsServer?.stop();
104
+ if (mode === 'nonblocking') {
105
+ this.#onError?.(error);
106
+ this.#watcher?.close();
107
+ this.#assetsServer?.stop();
108
+ }
108
109
  });
109
110
  }
110
111
  /**
@@ -178,6 +179,17 @@ export class DevServer {
178
179
  this.#onError = callback;
179
180
  return this;
180
181
  }
182
+ /**
183
+ * Close watchers and running child processes
184
+ */
185
+ async close() {
186
+ await this.#watcher?.close();
187
+ this.#assetsServer?.stop();
188
+ if (this.#httpServer) {
189
+ this.#httpServer.removeAllListeners();
190
+ this.#httpServer.kill('SIGKILL');
191
+ }
192
+ }
181
193
  /**
182
194
  * Start the development server
183
195
  */
@@ -30,6 +30,10 @@ export declare class TestRunner {
30
30
  * with an error
31
31
  */
32
32
  onError(callback: (error: any) => any): this;
33
+ /**
34
+ * Close watchers and running child processes
35
+ */
36
+ close(): Promise<void>;
33
37
  /**
34
38
  * Runs tests
35
39
  */
@@ -121,26 +121,29 @@ export class TestRunner {
121
121
  .then((result) => {
122
122
  if (mode === 'nonblocking') {
123
123
  this.#onClose?.(result.exitCode);
124
- this.#watcher?.close();
125
- this.#assetsServer?.stop();
124
+ this.close();
126
125
  }
127
126
  })
128
127
  .catch((error) => {
129
- /**
130
- * Since the tests runner set the `process.exitCode = 1`, execa will
131
- * throw an exception. However, we should ignore it and keep the
132
- * watcher on.
133
- */
134
128
  if (mode === 'nonblocking') {
135
129
  this.#onError?.(error);
136
- this.#watcher?.close();
137
- this.#assetsServer?.stop();
130
+ this.close();
138
131
  }
139
132
  })
140
133
  .finally(() => {
141
134
  this.#isBusy = false;
142
135
  });
143
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
+ }
144
147
  /**
145
148
  * Starts the assets server
146
149
  */
@@ -159,7 +162,7 @@ export class TestRunner {
159
162
  if (isDotEnvFile(relativePath) || this.#isMetaFile(relativePath)) {
160
163
  this.#clearScreen();
161
164
  this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
162
- this.#runTests(port, filters, 'blocking');
165
+ this.#rerunTests(port, filters);
163
166
  }
164
167
  }
165
168
  /**
@@ -176,13 +179,13 @@ export class TestRunner {
176
179
  * then only run that file
177
180
  */
178
181
  if (this.#isTestFile(relativePath)) {
179
- this.#runTests(port, this.#convertFiltersToArgs({
182
+ this.#rerunTests(port, this.#convertFiltersToArgs({
180
183
  ...this.#options.filters,
181
184
  files: [relativePath],
182
- }), 'blocking');
185
+ }));
183
186
  return;
184
187
  }
185
- this.#runTests(port, filters, 'blocking');
188
+ this.#rerunTests(port, filters);
186
189
  }
187
190
  /**
188
191
  * Set a custom CLI UI logger
@@ -208,6 +211,17 @@ export class TestRunner {
208
211
  this.#onError = callback;
209
212
  return this;
210
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
+ }
211
225
  /**
212
226
  * Runs tests
213
227
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
- "version": "6.1.3-8",
3
+ "version": "6.1.3-9",
4
4
  "description": "Provides utilities to run AdonisJS development server and build project for production",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -106,7 +106,10 @@
106
106
  "exclude": [
107
107
  "tests/**",
108
108
  "build/**",
109
- "examples/**"
109
+ "examples/**",
110
+ "src/dev_server.ts",
111
+ "src/test_runner.ts",
112
+ "src/assets_dev_server.ts"
110
113
  ]
111
114
  },
112
115
  "eslintConfig": {