velocious 1.0.666 → 1.0.668

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.
Files changed (174) hide show
  1. package/README.md +40 -11
  2. package/build/background-jobs/adapter-client.js +22 -0
  3. package/build/background-jobs/adapter.js +15 -0
  4. package/build/background-jobs/client.js +147 -1
  5. package/build/background-jobs/job-semantics.js +30 -0
  6. package/build/background-jobs/job.js +26 -1
  7. package/build/background-jobs/local-adapter.js +36 -8
  8. package/build/background-jobs/local-store.js +410 -39
  9. package/build/background-jobs/main.js +69 -2
  10. package/build/background-jobs/platform-job.js +26 -1
  11. package/build/background-jobs/runtime.js +58 -0
  12. package/build/background-jobs/store.js +374 -6
  13. package/build/background-jobs/types.js +27 -2
  14. package/build/background-jobs/web/controller.js +1 -0
  15. package/build/configuration.js +30 -6
  16. package/build/database/drivers/mssql/column.js +2 -2
  17. package/build/database/drivers/mssql/table.js +19 -5
  18. package/build/database/pool/async-tracked-multi-connection.js +2 -1
  19. package/build/database/query/alter-table-base.js +8 -1
  20. package/build/database/record/attachments/store.js +2 -2
  21. package/build/environment-handlers/node/cli/commands/test/timing-manifest/merge.js +2 -48
  22. package/build/environment-handlers/node/cli/commands/test.js +17 -69
  23. package/build/frontend-model-controller.js +22 -2
  24. package/build/frontend-models/websocket-channel.js +18 -0
  25. package/build/http-server/client/websocket-session.js +41 -4
  26. package/build/http-server/websocket-channel.js +14 -0
  27. package/build/http-server/websocket-event-log-store.js +85 -12
  28. package/build/http-server/websocket-events-host.js +17 -7
  29. package/build/src/background-jobs/adapter-client.d.ts +17 -0
  30. package/build/src/background-jobs/adapter-client.d.ts.map +1 -1
  31. package/build/src/background-jobs/adapter-client.js +19 -1
  32. package/build/src/background-jobs/adapter.d.ts +15 -0
  33. package/build/src/background-jobs/adapter.d.ts.map +1 -1
  34. package/build/src/background-jobs/adapter.js +14 -1
  35. package/build/src/background-jobs/client.d.ts +17 -0
  36. package/build/src/background-jobs/client.d.ts.map +1 -1
  37. package/build/src/background-jobs/client.js +129 -1
  38. package/build/src/background-jobs/job-semantics.d.ts +18 -0
  39. package/build/src/background-jobs/job-semantics.d.ts.map +1 -1
  40. package/build/src/background-jobs/job-semantics.js +28 -1
  41. package/build/src/background-jobs/job.d.ts +15 -0
  42. package/build/src/background-jobs/job.d.ts.map +1 -1
  43. package/build/src/background-jobs/job.js +21 -2
  44. package/build/src/background-jobs/local-adapter.d.ts +23 -8
  45. package/build/src/background-jobs/local-adapter.d.ts.map +1 -1
  46. package/build/src/background-jobs/local-adapter.js +35 -9
  47. package/build/src/background-jobs/local-store.d.ts +120 -5
  48. package/build/src/background-jobs/local-store.d.ts.map +1 -1
  49. package/build/src/background-jobs/local-store.js +366 -40
  50. package/build/src/background-jobs/main.d.ts +24 -2
  51. package/build/src/background-jobs/main.d.ts.map +1 -1
  52. package/build/src/background-jobs/main.js +68 -3
  53. package/build/src/background-jobs/platform-job.d.ts +15 -0
  54. package/build/src/background-jobs/platform-job.d.ts.map +1 -1
  55. package/build/src/background-jobs/platform-job.js +19 -2
  56. package/build/src/background-jobs/runtime.d.ts +39 -0
  57. package/build/src/background-jobs/runtime.d.ts.map +1 -1
  58. package/build/src/background-jobs/runtime.js +49 -1
  59. package/build/src/background-jobs/store.d.ts +100 -1
  60. package/build/src/background-jobs/store.d.ts.map +1 -1
  61. package/build/src/background-jobs/store.js +334 -8
  62. package/build/src/background-jobs/types.d.ts +97 -4
  63. package/build/src/background-jobs/types.d.ts.map +1 -1
  64. package/build/src/background-jobs/types.js +28 -3
  65. package/build/src/background-jobs/web/controller.d.ts.map +1 -1
  66. package/build/src/background-jobs/web/controller.js +2 -1
  67. package/build/src/configuration.d.ts +18 -1
  68. package/build/src/configuration.d.ts.map +1 -1
  69. package/build/src/configuration.js +28 -6
  70. package/build/src/database/drivers/mssql/column.d.ts.map +1 -1
  71. package/build/src/database/drivers/mssql/column.js +2 -2
  72. package/build/src/database/drivers/mssql/table.d.ts.map +1 -1
  73. package/build/src/database/drivers/mssql/table.js +19 -5
  74. package/build/src/database/pool/async-tracked-multi-connection.d.ts.map +1 -1
  75. package/build/src/database/pool/async-tracked-multi-connection.js +3 -2
  76. package/build/src/database/query/alter-table-base.d.ts.map +1 -1
  77. package/build/src/database/query/alter-table-base.js +9 -2
  78. package/build/src/database/record/attachments/store.js +3 -3
  79. package/build/src/environment-handlers/node/cli/commands/test/timing-manifest/merge.d.ts.map +1 -1
  80. package/build/src/environment-handlers/node/cli/commands/test/timing-manifest/merge.js +3 -47
  81. package/build/src/environment-handlers/node/cli/commands/test.d.ts +2 -28
  82. package/build/src/environment-handlers/node/cli/commands/test.d.ts.map +1 -1
  83. package/build/src/environment-handlers/node/cli/commands/test.js +10 -61
  84. package/build/src/frontend-model-controller.d.ts.map +1 -1
  85. package/build/src/frontend-model-controller.js +18 -3
  86. package/build/src/frontend-models/websocket-channel.d.ts +9 -0
  87. package/build/src/frontend-models/websocket-channel.d.ts.map +1 -1
  88. package/build/src/frontend-models/websocket-channel.js +16 -1
  89. package/build/src/http-server/client/websocket-session.d.ts +25 -2
  90. package/build/src/http-server/client/websocket-session.d.ts.map +1 -1
  91. package/build/src/http-server/client/websocket-session.js +40 -5
  92. package/build/src/http-server/websocket-channel.d.ts +11 -0
  93. package/build/src/http-server/websocket-channel.d.ts.map +1 -1
  94. package/build/src/http-server/websocket-channel.js +14 -1
  95. package/build/src/http-server/websocket-event-log-store.d.ts +60 -41
  96. package/build/src/http-server/websocket-event-log-store.d.ts.map +1 -1
  97. package/build/src/http-server/websocket-event-log-store.js +79 -12
  98. package/build/src/http-server/websocket-events-host.d.ts +10 -3
  99. package/build/src/http-server/websocket-events-host.d.ts.map +1 -1
  100. package/build/src/http-server/websocket-events-host.js +17 -8
  101. package/build/src/testing/test-files-finder.d.ts +17 -117
  102. package/build/src/testing/test-files-finder.d.ts.map +1 -1
  103. package/build/src/testing/test-files-finder.js +29 -294
  104. package/build/src/testing/test-filter-parser.d.ts +32 -22
  105. package/build/src/testing/test-filter-parser.d.ts.map +1 -1
  106. package/build/src/testing/test-filter-parser.js +25 -217
  107. package/build/src/testing/test-profile-activity.d.ts +1 -6
  108. package/build/src/testing/test-profile-activity.d.ts.map +1 -1
  109. package/build/src/testing/test-profile-activity.js +2 -12
  110. package/build/src/testing/test-profile-output.d.ts +1 -40
  111. package/build/src/testing/test-profile-output.d.ts.map +1 -1
  112. package/build/src/testing/test-profile-output.js +2 -217
  113. package/build/src/testing/test-profiler.d.ts +15 -659
  114. package/build/src/testing/test-profiler.d.ts.map +1 -1
  115. package/build/src/testing/test-profiler.js +35 -833
  116. package/build/src/testing/test-runner.d.ts +10 -1
  117. package/build/src/testing/test-runner.d.ts.map +1 -1
  118. package/build/src/testing/test-runner.js +26 -4
  119. package/build/src/testing/test-suite-splitter.d.ts +1 -128
  120. package/build/src/testing/test-suite-splitter.d.ts.map +1 -1
  121. package/build/src/testing/test-suite-splitter.js +2 -259
  122. package/build/src/testing/timing-manifest.d.ts +5 -93
  123. package/build/src/testing/timing-manifest.d.ts.map +1 -1
  124. package/build/src/testing/timing-manifest.js +4 -283
  125. package/build/src/testing/velocious-attempt-executor.d.ts.map +1 -1
  126. package/build/src/testing/velocious-attempt-executor.js +8 -2
  127. package/build/testing/test-files-finder.js +32 -343
  128. package/build/testing/test-filter-parser.js +29 -248
  129. package/build/testing/test-profile-activity.js +1 -12
  130. package/build/testing/test-profile-output.js +8 -253
  131. package/build/testing/test-profiler.js +38 -895
  132. package/build/testing/test-runner.js +33 -9
  133. package/build/testing/test-suite-splitter.js +1 -301
  134. package/build/testing/timing-manifest.js +10 -344
  135. package/build/testing/velocious-attempt-executor.js +7 -1
  136. package/package.json +3 -3
  137. package/scripts/test-browser.js +30 -6
  138. package/scripts/verify-docker-dev-environment.js +13 -1
  139. package/src/background-jobs/adapter-client.js +22 -0
  140. package/src/background-jobs/adapter.js +15 -0
  141. package/src/background-jobs/client.js +147 -1
  142. package/src/background-jobs/job-semantics.js +30 -0
  143. package/src/background-jobs/job.js +26 -1
  144. package/src/background-jobs/local-adapter.js +36 -8
  145. package/src/background-jobs/local-store.js +410 -39
  146. package/src/background-jobs/main.js +69 -2
  147. package/src/background-jobs/platform-job.js +26 -1
  148. package/src/background-jobs/runtime.js +58 -0
  149. package/src/background-jobs/store.js +374 -6
  150. package/src/background-jobs/types.js +27 -2
  151. package/src/background-jobs/web/controller.js +1 -0
  152. package/src/configuration.js +30 -6
  153. package/src/database/drivers/mssql/column.js +2 -2
  154. package/src/database/drivers/mssql/table.js +19 -5
  155. package/src/database/pool/async-tracked-multi-connection.js +2 -1
  156. package/src/database/query/alter-table-base.js +8 -1
  157. package/src/database/record/attachments/store.js +2 -2
  158. package/src/environment-handlers/node/cli/commands/test/timing-manifest/merge.js +2 -48
  159. package/src/environment-handlers/node/cli/commands/test.js +17 -69
  160. package/src/frontend-model-controller.js +22 -2
  161. package/src/frontend-models/websocket-channel.js +18 -0
  162. package/src/http-server/client/websocket-session.js +41 -4
  163. package/src/http-server/websocket-channel.js +14 -0
  164. package/src/http-server/websocket-event-log-store.js +85 -12
  165. package/src/http-server/websocket-events-host.js +17 -7
  166. package/src/testing/test-files-finder.js +32 -343
  167. package/src/testing/test-filter-parser.js +29 -248
  168. package/src/testing/test-profile-activity.js +1 -12
  169. package/src/testing/test-profile-output.js +8 -253
  170. package/src/testing/test-profiler.js +38 -895
  171. package/src/testing/test-runner.js +33 -9
  172. package/src/testing/test-suite-splitter.js +1 -301
  173. package/src/testing/timing-manifest.js +10 -344
  174. package/src/testing/velocious-attempt-executor.js +7 -1
@@ -1,364 +1,53 @@
1
1
  // @ts-check
2
2
 
3
- import fs from "fs/promises"
4
- import path from "path"
3
+ import {
4
+ discoverTestFiles,
5
+ lineFiltersFromCandidates
6
+ } from "@velocious/testing/node"
5
7
 
6
- import fileExists from "../utils/file-exists.js"
7
- import Logger from "../logger.js"
8
8
  import restArgsError from "../utils/rest-args-error.js"
9
9
 
10
- // Incredibly complex class to find files in multiple simultanious running promises to do it as fast as possible.
11
- export default class TestFilesFinder {
12
- static IGNORED_NAMES = [".git", "node_modules"]
10
+ const VELOCIOUS_NODE_TEST_PATTERN = /(?<!\.browser)-(?:spec|test)\.(?:m)?js$/u
13
11
 
12
+ /** Compatibility facade for Velocious's published test-file finder path. */
13
+ export default class TestFilesFinder {
14
14
  /**
15
- * Runs constructor.
16
- * @param {object} args - Options object.
17
- * @param {string} args.directory - Directory path.
18
- * @param {string[]} [args.directories] - Directories.
19
- * @param {string[]} args.processArgs - Process args.
15
+ * Creates a Velocious-compatible package discovery adapter.
16
+ * @param {object} args - Discovery options.
17
+ * @param {string} args.directory - Discovery base directory.
18
+ * @param {string[]} [args.directories] - Default directories.
19
+ * @param {RegExp} [args.filePattern] - Test-file pattern override.
20
+ * @param {string[]} args.processArgs - Process arguments including the command name.
20
21
  */
21
- constructor({directory, directories, processArgs, ...restArgs}) {
22
+ constructor({directory, directories, filePattern, processArgs, ...restArgs}) {
22
23
  restArgsError(restArgs)
23
-
24
- this.directory = path.resolve(directory)
25
- this.logger = new Logger(this)
26
-
27
- if (directories) {
28
- this.directories = directories.map((entry) => path.resolve(entry))
29
- } else {
30
- this.directories = [
31
- `${this.directory}/__tests__`,
32
- `${this.directory}/tests`,
33
- `${this.directory}/spec`
34
- ]
35
- }
36
-
37
- this.findingCount = 0
38
- this.processArgs = processArgs
39
-
40
- /**
41
- * Narrows the runtime value to the documented type.
42
- * @type {string[]} */
43
- this.foundFiles = []
44
-
45
- /**
46
- * Narrows the runtime value to the documented type.
47
- * @type {Record<number, Promise<void>>} */
48
- this.findingPromises = {}
49
-
50
- /**
51
- * Narrows the runtime value to the documented type.
52
- * @type {string[]} */
53
- this.testArgs = this.processArgs.filter((processArg, index) => index != 0)
54
-
55
- /**
56
- * Narrows the runtime value to the documented type.
57
- * @type {string[]} */
58
- this.directoryArgs = []
59
-
60
- /**
61
- * Narrows the runtime value to the documented type.
62
- * @type {string[]} */
63
- this.directoryFullPaths = []
64
-
65
- /**
66
- * Narrows the runtime value to the documented type.
67
- * @type {string[]} */
68
- this.fileArgs = []
69
-
70
- /**
71
- * Narrows the runtime value to the documented type.
72
- * @type {string[]} */
73
- this.explicitFiles = []
74
-
75
- /**
76
- * Narrows the runtime value to the documented type.
77
- * @type {Record<string, number[]>} */
78
- this.lineFiltersByFile = {}
79
-
80
- this._argsPrepared = false
24
+ this.directory = directory
25
+ this.directories = directories
26
+ this.filePattern = filePattern
27
+ this.candidates = processArgs.slice(1).filter((argument) => argument !== "--")
28
+ /** @type {Record<string, number[]>} */
29
+ this.lineFiltersByFile = lineFiltersFromCandidates({
30
+ cwd: directory,
31
+ candidates: this.candidates
32
+ })
81
33
  }
82
34
 
83
35
  /**
84
- * Runs find test files.
85
- * @returns {Promise<string[]>} - Resolves with the test files.
36
+ * Discovers test files through the package implementation.
37
+ * @returns {Promise<string[]>} - Discovered absolute file paths.
86
38
  */
87
39
  async findTestFiles() {
88
- await this.prepareArgs()
89
-
90
- if (this.explicitFiles.length > 0 && this.directoryArgs.length === 0) {
91
- return Array.from(new Set(this.explicitFiles))
92
- }
93
-
94
- await this.withFindingCount(async () => {
95
- const hasExplicitArgs = this.directoryFullPaths.length > 0 || this.fileArgs.length > 0
96
- const directoriesToScan = hasExplicitArgs ? this.directoryFullPaths : this.directories
97
-
98
- for (const directory of directoriesToScan) {
99
- if (await fileExists(directory)) {
100
- await this.findTestFilesInDir(directory)
101
- }
102
- }
40
+ return await discoverTestFiles({
41
+ cwd: this.directory,
42
+ candidates: this.candidates,
43
+ directories: this.directories,
44
+ filePattern: this.filePattern || VELOCIOUS_NODE_TEST_PATTERN
103
45
  })
104
-
105
- await this.waitForFindingPromises()
106
-
107
- if (this.explicitFiles.length > 0) {
108
- this.foundFiles.push(...this.explicitFiles)
109
- }
110
-
111
- return Array.from(new Set(this.foundFiles))
112
46
  }
113
47
 
114
48
  /**
115
- * Runs get line filters by file.
116
- * @returns {Record<string, number[]>} - Line filters by file.
49
+ * Gets candidate-derived line filters.
50
+ * @returns {Record<string, number[]>} - Line filters keyed by absolute file path.
117
51
  */
118
52
  getLineFiltersByFile() { return this.lineFiltersByFile }
119
-
120
- /**
121
- * Runs finding promises length.
122
- * @returns {number} - The ing promises length.
123
- */
124
- findingPromisesLength() { return Object.keys(this.findingPromises).length }
125
-
126
- async waitForFindingPromises() {
127
- while (this.findingPromisesLength() > 0) {
128
- await this.waitForFindingPromisesIteration()
129
- }
130
- }
131
-
132
- /**
133
- * Runs wait for finding promises iteration.
134
- * @returns {Promise<void>} - Resolves when complete.
135
- */
136
- async waitForFindingPromisesIteration() {
137
- const unfinishedPromises = []
138
-
139
- for (const findingPromiseId in this.findingPromises) {
140
- const findingPromise = this.findingPromises[findingPromiseId]
141
-
142
- unfinishedPromises.push(findingPromise)
143
- }
144
-
145
- await Promise.all(unfinishedPromises)
146
- }
147
-
148
- /**
149
- * Runs with finding count.
150
- * @param {() => Promise<void>} callback - Callback function.
151
- * @returns {Promise<void>} - Resolves when complete.
152
- */
153
- withFindingCount(callback) {
154
- return new Promise((resolve) => {
155
- const findingPromise = callback()
156
- const findingCount = this.findingCount
157
-
158
- this.findingCount += 1
159
- this.findingPromises[findingCount] = findingPromise
160
-
161
- findingPromise.finally(() => {
162
- delete this.findingPromises[findingCount]
163
-
164
- resolve(undefined)
165
- })
166
- })
167
- }
168
-
169
- /**
170
- * Runs find test files in dir.
171
- * @param {string} dir - Dir.
172
- * @returns {Promise<void>} - Resolves when complete.
173
- */
174
- async findTestFilesInDir(dir) {
175
- await this.withFindingCount(async () => {
176
- const files = await fs.readdir(dir)
177
-
178
- for (const file of files) {
179
- if (TestFilesFinder.IGNORED_NAMES.includes(file)) {
180
- continue
181
- }
182
-
183
- const fullPath = `${dir}/${file}`
184
- const localPath = fullPath.replace(`${this.directory}/`, "")
185
- const isDir = (await fs.stat(fullPath)).isDirectory()
186
-
187
- if (isDir) {
188
- this.findTestFilesInDir(fullPath)
189
- } else {
190
- if (this.isFileMatchingRequirements(file, localPath)) {
191
- this.foundFiles.push(fullPath)
192
- }
193
- }
194
- }
195
- })
196
- }
197
-
198
- /**
199
- * Runs is file matching requirements.
200
- * @param {string} file - File.
201
- * @param {string} localPath - Local path.
202
- * @returns {boolean} - Whether file matching requirements.
203
- */
204
- isFileMatchingRequirements(file, localPath) {
205
- if (this.directoryArgs.length > 0) {
206
- for (const directoryArg of this.directoryArgs) {
207
- if (localPath.startsWith(directoryArg) && this.looksLikeTestFile(file)) {
208
- this.logger.debug("Found test file because matching dir and looks like this file:", file)
209
- return true
210
- }
211
- }
212
- }
213
-
214
- if (this.fileArgs.length > 0) {
215
- for (const fileArg of this.fileArgs) {
216
- if (fileArg == localPath) {
217
- this.logger.debug("Found test file because matching file arg:", file)
218
- return true
219
- }
220
- }
221
- }
222
-
223
- if (this.fileArgs.length == 0 && this.directoryArgs.length == 0 && this.looksLikeTestFile(file)) {
224
- this.logger.debug("Found test file because looks like this file:", file)
225
- return true
226
- }
227
-
228
- return false
229
- }
230
-
231
- /**
232
- * Runs looks like test file.
233
- * @param {string} file - File.
234
- * @returns {boolean} - Whether looks like test file.
235
- */
236
- looksLikeTestFile(file) {
237
- return Boolean(file.match(/-(spec|test)\.(m|)js$/))
238
- }
239
-
240
- /**
241
- * Runs prepare args.
242
- * @returns {Promise<void>} - Resolves when test args are prepared.
243
- */
244
- async prepareArgs() {
245
- if (this._argsPrepared) return
246
-
247
- for (const testArg of this.testArgs) {
248
- if (testArg === "--") continue
249
-
250
- const {cleanArg, line} = this.splitLineArg(testArg)
251
- const forceDirectory = testArg.endsWith("/") || testArg.endsWith(path.sep)
252
- const fullPath = path.isAbsolute(cleanArg) ? cleanArg : path.resolve(this.directory, cleanArg)
253
- const baseName = path.basename(this.directory)
254
- const hasBasePrefix = cleanArg === baseName || cleanArg.startsWith(`${baseName}/`) || cleanArg.startsWith(`${baseName}${path.sep}`)
255
- const basePrefixedFullPath = (!path.isAbsolute(cleanArg) && hasBasePrefix) ? path.resolve(path.dirname(this.directory), cleanArg) : null
256
- const fullPathCandidates = basePrefixedFullPath ? [basePrefixedFullPath] : [fullPath]
257
-
258
- if (forceDirectory) {
259
- const preferredLocalPath = this.toLocalPath(basePrefixedFullPath || fullPath)
260
- this.directoryArgs.push(this.ensureTrailingSlash(preferredLocalPath))
261
- this.directoryFullPaths.push(path.resolve(basePrefixedFullPath || fullPath))
262
- continue
263
- }
264
-
265
- try {
266
- let stats
267
- let resolvedFullPath
268
-
269
- for (const candidatePath of fullPathCandidates) {
270
- try {
271
- stats = await fs.stat(candidatePath)
272
- resolvedFullPath = candidatePath
273
- break
274
- } catch {
275
- // Keep searching
276
- }
277
- }
278
-
279
- if (!stats || !resolvedFullPath) throw new Error("Path not found")
280
- const localPath = this.toLocalPath(resolvedFullPath)
281
-
282
- if (stats.isDirectory()) {
283
- this.directoryArgs.push(this.ensureTrailingSlash(localPath))
284
- this.directoryFullPaths.push(resolvedFullPath)
285
- } else if (stats.isFile()) {
286
- this.fileArgs.push(localPath)
287
- this.explicitFiles.push(resolvedFullPath)
288
-
289
- if (line) {
290
- this.addLineFilter(resolvedFullPath, line)
291
- }
292
- }
293
- } catch {
294
- const fallbackLocalPath = this.toLocalPath(basePrefixedFullPath || fullPath)
295
- this.fileArgs.push(fallbackLocalPath)
296
-
297
- if (line) {
298
- this.addLineFilter(basePrefixedFullPath || fullPath, line)
299
- }
300
- }
301
- }
302
-
303
- this._argsPrepared = true
304
- }
305
-
306
- /**
307
- * Runs add line filter.
308
- * @param {string} filePath - File path.
309
- * @param {number} line - Line number.
310
- * @returns {void} - No return value.
311
- */
312
- addLineFilter(filePath, line) {
313
- const fullPath = path.resolve(filePath)
314
-
315
- if (!this.lineFiltersByFile[fullPath]) {
316
- this.lineFiltersByFile[fullPath] = []
317
- }
318
-
319
- if (!this.lineFiltersByFile[fullPath].includes(line)) {
320
- this.lineFiltersByFile[fullPath].push(line)
321
- }
322
- }
323
-
324
- /**
325
- * Runs split line arg.
326
- * @param {string} testArg - Test arg.
327
- * @returns {{cleanArg: string, line?: number}} - Cleaned arg and line.
328
- */
329
- splitLineArg(testArg) {
330
- const match = testArg.match(/^(.*):(\d+)$/)
331
-
332
- if (!match) {
333
- return {cleanArg: testArg}
334
- }
335
-
336
- const line = Number(match[2])
337
-
338
- if (!Number.isFinite(line)) {
339
- return {cleanArg: testArg}
340
- }
341
-
342
- return {cleanArg: match[1], line}
343
- }
344
-
345
- /**
346
- * Runs ensure trailing slash.
347
- * @param {string} localPath - Local path.
348
- * @returns {string} - Normalized local path with trailing slash.
349
- */
350
- ensureTrailingSlash(localPath) {
351
- if (localPath === "") return localPath
352
- return localPath.endsWith("/") ? localPath : `${localPath}/`
353
- }
354
-
355
- /**
356
- * Runs to local path.
357
- * @param {string} fullPath - Full path.
358
- * @returns {string} - Local path relative to the base directory.
359
- */
360
- toLocalPath(fullPath) {
361
- const relativePath = path.relative(this.directory, fullPath)
362
- return relativePath.split(path.sep).join("/")
363
- }
364
53
  }
@@ -1,269 +1,50 @@
1
+ // @ts-check
2
+
3
+ import {
4
+ extractTestCliArguments,
5
+ normalizeExamplePatterns
6
+ } from "@velocious/testing/node"
7
+
1
8
  /**
2
- * ParseFiltersResult type.
3
9
  * @typedef {object} ParseFiltersResult
4
10
  * @property {string[]} includeTags - Tags to include.
5
11
  * @property {string[]} excludeTags - Tags to exclude.
6
12
  * @property {string[]} examplePatterns - Example name patterns.
7
- * @property {string[]} filteredProcessArgs - Remaining process args with filter flags removed.
13
+ * @property {string[]} filteredProcessArgs - Remaining process args with package-owned flags removed.
8
14
  * @property {number | undefined} groups - Total number of groups for test splitting.
9
15
  * @property {number | undefined} groupNumber - Which group to run (1-indexed).
10
16
  * @property {boolean} profile - Whether test profiling is enabled.
11
17
  * @property {string | undefined} profileJsonPath - Rich profile output path.
12
18
  * @property {string | undefined} timingManifestPath - JSON timing manifest path.
13
19
  * @property {string | undefined} timingManifestOutputPath - Timing manifest output path.
20
+ * @property {number | undefined} retries - Default retry count.
21
+ * @property {string[]} setupFiles - Setup files imported before test files.
22
+ * @property {number | undefined} timeoutMs - Default lifecycle timeout.
14
23
  */
15
- // @ts-check
16
-
17
- const INCLUDE_TAG_FLAGS = new Set(["--tag", "--include-tag", "-t"])
18
- const EXCLUDE_TAG_FLAGS = new Set(["--exclude-tag", "--skip-tag", "-x"])
19
- const EXAMPLE_FLAGS = new Set(["--example", "--name", "-e"])
20
- const GROUPS_FLAGS = new Set(["--groups"])
21
- const GROUP_NUMBER_FLAGS = new Set(["--group-number"])
22
- const TIMING_MANIFEST_FLAGS = new Set(["--timing-manifest"])
23
- const PROFILE_JSON_FLAGS = new Set(["--profile-json"])
24
- const TIMING_MANIFEST_OUTPUT_FLAGS = new Set(["--timing-manifest-output"])
25
-
26
- /**
27
- * Runs split tags.
28
- * @param {string | undefined} value - Tag argument value.
29
- * @returns {string[]} - Tags list.
30
- */
31
- function splitTags(value) {
32
- if (!value) return []
33
-
34
- return value
35
- .split(",")
36
- .map((tag) => tag.trim())
37
- .filter(Boolean)
38
- }
39
-
40
- /**
41
- * Runs escape reg exp.
42
- * @param {string} value - Value.
43
- * @returns {string} - Escaped value for regex.
44
- */
45
- function escapeRegExp(value) {
46
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
47
- }
48
-
49
- /**
50
- * Runs the normalizeExamplePatterns helper.
51
- * @param {string[]} patterns - Patterns.
52
- * @returns {RegExp[]} - Normalized patterns.
53
- */
54
- export function normalizeExamplePatterns(patterns) {
55
- const normalized = []
56
-
57
- for (const pattern of patterns) {
58
- const regexMatch = pattern.match(/^\/(.+)\/([gimsuy]*)$/)
59
24
 
60
- if (regexMatch) {
61
- normalized.push(new RegExp(regexMatch[1], regexMatch[2]))
62
- } else {
63
- normalized.push(new RegExp(escapeRegExp(pattern)))
64
- }
65
- }
66
-
67
- return normalized
68
- }
25
+ export { normalizeExamplePatterns }
69
26
 
70
27
  /**
71
- * Runs the parseFilters helper.
72
- * @param {string[]} processArgs - Process args.
73
- * @returns {ParseFiltersResult} - Parsed tags, group options, and process args.
28
+ * Preserves the Velocious parser result while delegating package-owned option parsing.
29
+ * @param {string[]} processArgs - Raw process arguments including the command name.
30
+ * @returns {ParseFiltersResult} - Package options and downstream process arguments.
74
31
  */
75
32
  export function parseFilters(processArgs) {
76
- const includeTags = []
77
- const excludeTags = []
78
- const filteredProcessArgs = processArgs.length > 0 ? [processArgs[0]] : []
79
- const examplePatterns = []
80
-
81
- /**
82
- * Defines groups.
83
- * @type {number | undefined} */
84
- let groups
85
- /**
86
- * Defines groupNumber.
87
- * @type {number | undefined} */
88
- let groupNumber
89
- let profile = false
90
- /** @type {string | undefined} */
91
- let profileJsonPath
92
- /** @type {string | undefined} */
93
- let timingManifestPath
94
- /** @type {string | undefined} */
95
- let timingManifestOutputPath
96
-
97
- let inRestArgs = false
98
-
99
- for (let i = 1; i < processArgs.length; i++) {
100
- const arg = processArgs[i]
101
-
102
- if (arg === "--") {
103
- inRestArgs = true
104
- filteredProcessArgs.push(arg)
105
- continue
106
- }
107
-
108
- if (!inRestArgs) {
109
- if (INCLUDE_TAG_FLAGS.has(arg)) {
110
- const nextValue = processArgs[i + 1]
111
-
112
- if (nextValue && !nextValue.startsWith("-")) {
113
- includeTags.push(...splitTags(nextValue))
114
- i++
115
- }
116
- continue
117
- }
118
-
119
- if (EXCLUDE_TAG_FLAGS.has(arg)) {
120
- const nextValue = processArgs[i + 1]
121
-
122
- if (nextValue && !nextValue.startsWith("-")) {
123
- excludeTags.push(...splitTags(nextValue))
124
- i++
125
- }
126
- continue
127
- }
128
-
129
- if (arg.startsWith("--tag=")) {
130
- includeTags.push(...splitTags(arg.slice("--tag=".length)))
131
- continue
132
- }
133
-
134
- if (arg.startsWith("--include-tag=")) {
135
- includeTags.push(...splitTags(arg.slice("--include-tag=".length)))
136
- continue
137
- }
138
-
139
- if (arg.startsWith("--exclude-tag=")) {
140
- excludeTags.push(...splitTags(arg.slice("--exclude-tag=".length)))
141
- continue
142
- }
143
-
144
- if (arg.startsWith("--skip-tag=")) {
145
- excludeTags.push(...splitTags(arg.slice("--skip-tag=".length)))
146
- continue
147
- }
148
-
149
- if (EXAMPLE_FLAGS.has(arg)) {
150
- const nextValue = processArgs[i + 1]
151
-
152
- if (nextValue && !nextValue.startsWith("-")) {
153
- examplePatterns.push(nextValue)
154
- i++
155
- }
156
- continue
157
- }
158
-
159
- if (arg.startsWith("--example=")) {
160
- examplePatterns.push(arg.slice("--example=".length))
161
- continue
162
- }
163
-
164
- if (arg.startsWith("--name=")) {
165
- examplePatterns.push(arg.slice("--name=".length))
166
- continue
167
- }
168
-
169
- if (GROUPS_FLAGS.has(arg)) {
170
- const nextValue = processArgs[i + 1]
171
-
172
- if (nextValue && !nextValue.startsWith("-")) {
173
- groups = parseInt(nextValue, 10)
174
- i++
175
- }
176
- continue
177
- }
178
-
179
- if (arg.startsWith("--groups=")) {
180
- groups = parseInt(arg.slice("--groups=".length), 10)
181
- continue
182
- }
183
-
184
- if (GROUP_NUMBER_FLAGS.has(arg)) {
185
- const nextValue = processArgs[i + 1]
186
-
187
- if (nextValue && !nextValue.startsWith("-")) {
188
- groupNumber = parseInt(nextValue, 10)
189
- i++
190
- }
191
- continue
192
- }
193
-
194
- if (arg.startsWith("--group-number=")) {
195
- groupNumber = parseInt(arg.slice("--group-number=".length), 10)
196
- continue
197
- }
198
-
199
- if (TIMING_MANIFEST_FLAGS.has(arg)) {
200
- const nextValue = processArgs[i + 1]
201
-
202
- if (!nextValue || nextValue.startsWith("-")) throw new Error("--timing-manifest requires a path")
203
- timingManifestPath = nextValue
204
- i++
205
- continue
206
- }
207
-
208
- if (arg.startsWith("--timing-manifest=")) {
209
- timingManifestPath = arg.slice("--timing-manifest=".length)
210
- if (!timingManifestPath) throw new Error("--timing-manifest requires a path")
211
- continue
212
- }
213
-
214
- if (arg === "--profile") {
215
- profile = true
216
- continue
217
- }
218
-
219
- if (PROFILE_JSON_FLAGS.has(arg)) {
220
- const nextValue = processArgs[i + 1]
221
-
222
- if (!nextValue || nextValue.startsWith("-")) throw new Error("--profile-json requires a path")
223
- profileJsonPath = nextValue
224
- profile = true
225
- i++
226
- continue
227
- }
228
-
229
- if (arg.startsWith("--profile-json=")) {
230
- profileJsonPath = arg.slice("--profile-json=".length)
231
- if (!profileJsonPath) throw new Error("--profile-json requires a path")
232
- profile = true
233
- continue
234
- }
235
-
236
- if (TIMING_MANIFEST_OUTPUT_FLAGS.has(arg)) {
237
- const nextValue = processArgs[i + 1]
238
-
239
- if (!nextValue || nextValue.startsWith("-")) throw new Error("--timing-manifest-output requires a path")
240
- timingManifestOutputPath = nextValue
241
- profile = true
242
- i++
243
- continue
244
- }
245
-
246
- if (arg.startsWith("--timing-manifest-output=")) {
247
- timingManifestOutputPath = arg.slice("--timing-manifest-output=".length)
248
- if (!timingManifestOutputPath) throw new Error("--timing-manifest-output requires a path")
249
- profile = true
250
- continue
251
- }
252
- }
253
-
254
- filteredProcessArgs.push(arg)
255
- }
33
+ const {options, remainingArguments} = extractTestCliArguments(processArgs)
256
34
 
257
35
  return {
258
- includeTags: Array.from(new Set(includeTags)),
259
- excludeTags: Array.from(new Set(excludeTags)),
260
- examplePatterns,
261
- filteredProcessArgs,
262
- groups,
263
- groupNumber,
264
- profile,
265
- profileJsonPath,
266
- timingManifestPath,
267
- timingManifestOutputPath
36
+ includeTags: options.includeTags,
37
+ excludeTags: options.excludeTags,
38
+ examplePatterns: options.examples,
39
+ filteredProcessArgs: remainingArguments,
40
+ groups: options.groups,
41
+ groupNumber: options.groupNumber,
42
+ profile: options.profile === true,
43
+ profileJsonPath: options.profileJsonPath,
44
+ timingManifestPath: options.timingManifestPath,
45
+ timingManifestOutputPath: options.timingManifestOutputPath,
46
+ retries: options.retries,
47
+ setupFiles: options.setupFiles,
48
+ timeoutMs: options.timeoutMs
268
49
  }
269
50
  }