@nestia/e2e 11.3.1 → 11.3.3

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.
@@ -37,7 +37,9 @@ export declare namespace DynamicExecutor {
37
37
  * Every prefixed function will be executed.
38
38
  *
39
39
  * In other words, if a function name doesn't start with the prefix, then it
40
- * would never be executed.
40
+ * would never be executed. Also, when a file name (basename) does not start
41
+ * with the prefix, the file would never be imported either, so that every
42
+ * function defined in the file would never be executed.
41
43
  */
42
44
  prefix: string;
43
45
  /** Location of the test functions. */
@@ -60,10 +62,15 @@ export declare namespace DynamicExecutor {
60
62
  /**
61
63
  * Filter function whether to run or not.
62
64
  *
63
- * @param name Function name
65
+ * The filter function is called with the file name (basename) of each
66
+ * dynamic function module, not with the function name. When it returns
67
+ * `false`, the file would never be imported, so that every function defined
68
+ * in the file would never be executed either.
69
+ *
70
+ * @param file File name (basename) of the dynamic functions
64
71
  * @returns Whether to run or not
65
72
  */
66
- filter?: (name: string) => boolean;
73
+ filter?: (file: string) => boolean;
67
74
  /**
68
75
  * Wrapper of test function.
69
76
  *
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -71,6 +104,8 @@ var DynamicExecutor;
71
104
  const processes = yield iterate({
72
105
  extension: (_a = props.extension) !== null && _a !== void 0 ? _a : "js",
73
106
  location: props.location,
107
+ prefix: props.prefix,
108
+ filter: props.filter,
74
109
  executor,
75
110
  });
76
111
  yield Promise.all(new Array((_b = props.simultaneous) !== null && _b !== void 0 ? _b : 1).fill(0).map(() => __awaiter(this, void 0, void 0, function* () {
@@ -82,6 +117,12 @@ var DynamicExecutor;
82
117
  report.time = Date.now() - report.time;
83
118
  return report;
84
119
  });
120
+ const specifier = (location) => {
121
+ const relative = path_1.default.relative(__dirname, path_1.default.resolve(location))
122
+ .split(path_1.default.sep)
123
+ .join("/");
124
+ return `./${relative}`;
125
+ };
85
126
  const iterate = (props) => __awaiter(this, void 0, void 0, function* () {
86
127
  const container = [];
87
128
  const visitor = (path) => __awaiter(this, void 0, void 0, function* () {
@@ -95,7 +136,17 @@ var DynamicExecutor;
95
136
  }
96
137
  else if (file.substr(-3) !== `.${props.extension}`)
97
138
  continue;
98
- const modulo = yield import(location);
139
+ else if (file.startsWith(props.prefix) === false)
140
+ continue;
141
+ else if (props.filter && props.filter(file) === false)
142
+ continue;
143
+ // Convert the absolute path to a POSIX relative specifier. It works
144
+ // both as a native ESM dynamic import (module: nodenext, which keeps
145
+ // `import()` as is) and as a `require()` call (module: commonjs, which
146
+ // downlevels `import()` to `require()`). A raw absolute path would
147
+ // break the native import on Windows (file URL scheme), and a `file://`
148
+ // URL would break the downleveled `require()`.
149
+ const modulo = yield Promise.resolve(`${specifier(location)}`).then(s => __importStar(require(s)));
99
150
  container.push(() => props.executor(location, modulo));
100
151
  }
101
152
  });
@@ -105,8 +156,7 @@ var DynamicExecutor;
105
156
  const execute = (props) => (report) => (assert) => (location, modulo) => __awaiter(this, void 0, void 0, function* () {
106
157
  for (const [key, closure] of Object.entries(modulo)) {
107
158
  if (key.substring(0, props.prefix.length) !== props.prefix ||
108
- typeof closure !== "function" ||
109
- (props.filter && props.filter(key) === false))
159
+ typeof closure !== "function")
110
160
  continue;
111
161
  const func = () => {
112
162
  if (props.wrapper !== undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"DynamicExecutor.js","sourceRoot":"","sources":["../src/DynamicExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAA4B;AAE5B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,IAAiB,eAAe,CAyP/B;AAzPD,WAAiB,eAAe;IA0H9B;;;;;;;;;OASG;IACU,sBAAM,GAAG,CACpB,KAAwB,EACN,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;IAEzC;;;;;;;;;OASG;IACU,wBAAQ,GAAG,CACtB,KAAwB,EACN,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;IAE1C,MAAM,IAAI,GACR,CAAC,MAAe,EAAE,EAAE,CACpB,CACE,KAAwB,EACN,EAAE;;QACpB,MAAM,MAAM,GAAY;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,UAAU,EAAE,EAAE;SACf,CAAC;QAEF,MAAM,QAAQ,GAAG,O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AAE,CAAC,WAAW,EAAE;gBACpC,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACvC,CAAC;YACF,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAE/B,IAAI,CAAC;gBACH,MAAM,CAAC,KAAK,GAAG,MAAM,IAAI,EAAE,CAAC;gBAC5B,MAAM,CAAC,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YACjD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,KAAK,GAAG,GAAY,CAAC;gBAC5B,IAAI,MAAM,KAAK,IAAI;oBAAE,MAAM,GAAG,CAAC;YACjC,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;gBAC/C,IAAI,KAAK,CAAC,UAAU;oBAAE,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC,CAAA,CAAC;AAKN,CAAC,EArRgB,eAAe,+BAAf,eAAe,QAqR/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/e2e",
3
- "version": "11.3.1",
3
+ "version": "11.3.3",
4
4
  "description": "E2E test utilify functions",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -41,7 +41,9 @@ export namespace DynamicExecutor {
41
41
  * Every prefixed function will be executed.
42
42
  *
43
43
  * In other words, if a function name doesn't start with the prefix, then it
44
- * would never be executed.
44
+ * would never be executed. Also, when a file name (basename) does not start
45
+ * with the prefix, the file would never be imported either, so that every
46
+ * function defined in the file would never be executed.
45
47
  */
46
48
  prefix: string;
47
49
 
@@ -68,10 +70,15 @@ export namespace DynamicExecutor {
68
70
  /**
69
71
  * Filter function whether to run or not.
70
72
  *
71
- * @param name Function name
73
+ * The filter function is called with the file name (basename) of each
74
+ * dynamic function module, not with the function name. When it returns
75
+ * `false`, the file would never be imported, so that every function defined
76
+ * in the file would never be executed either.
77
+ *
78
+ * @param file File name (basename) of the dynamic functions
72
79
  * @returns Whether to run or not
73
80
  */
74
- filter?: (name: string) => boolean;
81
+ filter?: (file: string) => boolean;
75
82
 
76
83
  /**
77
84
  * Wrapper of test function.
@@ -187,6 +194,8 @@ export namespace DynamicExecutor {
187
194
  const processes: Array<() => Promise<void>> = await iterate({
188
195
  extension: props.extension ?? "js",
189
196
  location: props.location,
197
+ prefix: props.prefix,
198
+ filter: props.filter,
190
199
  executor,
191
200
  });
192
201
  await Promise.all(
@@ -201,9 +210,21 @@ export namespace DynamicExecutor {
201
210
  return report;
202
211
  };
203
212
 
213
+ const specifier = (location: string): string => {
214
+ const relative: string = NodePath.relative(
215
+ __dirname,
216
+ NodePath.resolve(location),
217
+ )
218
+ .split(NodePath.sep)
219
+ .join("/");
220
+ return `./${relative}`;
221
+ };
222
+
204
223
  const iterate = async <Arguments extends any[]>(props: {
205
224
  location: string;
206
225
  extension: string;
226
+ prefix: string;
227
+ filter?: (file: string) => boolean;
207
228
  executor: (path: string, modulo: Module<Arguments>) => Promise<void>;
208
229
  }): Promise<Array<() => Promise<void>>> => {
209
230
  const container: Array<() => Promise<void>> = [];
@@ -217,8 +238,16 @@ export namespace DynamicExecutor {
217
238
  await visitor(location);
218
239
  continue;
219
240
  } else if (file.substr(-3) !== `.${props.extension}`) continue;
241
+ else if (file.startsWith(props.prefix) === false) continue;
242
+ else if (props.filter && props.filter(file) === false) continue;
220
243
 
221
- const modulo: Module<Arguments> = await import(location);
244
+ // Convert the absolute path to a POSIX relative specifier. It works
245
+ // both as a native ESM dynamic import (module: nodenext, which keeps
246
+ // `import()` as is) and as a `require()` call (module: commonjs, which
247
+ // downlevels `import()` to `require()`). A raw absolute path would
248
+ // break the native import on Windows (file URL scheme), and a `file://`
249
+ // URL would break the downleveled `require()`.
250
+ const modulo: Module<Arguments> = await import(specifier(location));
222
251
  container.push(() => props.executor(location, modulo));
223
252
  }
224
253
  };
@@ -234,8 +263,7 @@ export namespace DynamicExecutor {
234
263
  for (const [key, closure] of Object.entries(modulo)) {
235
264
  if (
236
265
  key.substring(0, props.prefix.length) !== props.prefix ||
237
- typeof closure !== "function" ||
238
- (props.filter && props.filter(key) === false)
266
+ typeof closure !== "function"
239
267
  )
240
268
  continue;
241
269