mootant 0.2.0 → 0.3.0

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 (313) hide show
  1. package/bin/mootant.js +3 -2
  2. package/dist/adapters/jest/collect-jest-dependencies.d.ts +8 -6
  3. package/dist/adapters/jest/collect-jest-dependencies.js +20 -14
  4. package/dist/adapters/jest/get-jest-cache-inputs.d.ts +14 -13
  5. package/dist/adapters/jest/index.d.ts +3 -1
  6. package/dist/adapters/jest/run-dry.js +20 -20
  7. package/dist/adapters/jest/start-jest-session.d.ts +6 -2
  8. package/dist/adapters/jest/start-jest-session.js +9 -2
  9. package/dist/adapters/jest/types/jest-handle.d.ts +2 -1
  10. package/dist/adapters/jest/types/jest-record.d.ts +4 -3
  11. package/dist/adapters/jest/types/worker-channel.d.ts +7 -0
  12. package/dist/adapters/jest/worker/boot-worker.d.ts +5 -4
  13. package/dist/adapters/jest/worker/create-test-runner.d.ts +4 -1
  14. package/dist/adapters/jest/worker/keep-reset-loads.d.ts +13 -0
  15. package/dist/adapters/jest/worker/list-runtime-files.d.ts +13 -0
  16. package/dist/adapters/jest/worker/run-unit.d.ts +25 -20
  17. package/dist/adapters/jest/worker/vm-setup.js +1 -1
  18. package/dist/adapters/jest/worker/worker.js +1 -1
  19. package/dist/adapters/node-test/check-typescript.js +2 -2
  20. package/dist/adapters/node-test/collect-node-dependencies.d.ts +7 -5
  21. package/dist/adapters/node-test/collect-node-dependencies.js +26 -20
  22. package/dist/adapters/node-test/create-spare-processes.d.ts +26 -0
  23. package/dist/adapters/node-test/create-spare-processes.js +53 -0
  24. package/dist/adapters/node-test/filter-exec-argv.d.ts +2 -1
  25. package/dist/adapters/node-test/filter-exec-argv.js +13 -12
  26. package/dist/adapters/node-test/get-node-cache-inputs.js +1 -1
  27. package/dist/adapters/node-test/get-unit-deadline.d.ts +6 -5
  28. package/dist/adapters/node-test/index.d.ts +2 -2
  29. package/dist/adapters/node-test/index.js +1 -0
  30. package/dist/adapters/node-test/is-group-alive.d.ts +8 -0
  31. package/dist/adapters/node-test/is-group-alive.js +8 -0
  32. package/dist/adapters/node-test/list-setup-files.js +2 -2
  33. package/dist/adapters/node-test/place-preload.d.ts +2 -1
  34. package/dist/adapters/node-test/place-preload.js +24 -18
  35. package/dist/adapters/node-test/preload/create-commonjs-route.js +1 -1
  36. package/dist/adapters/node-test/preload/preload.js +54 -52
  37. package/dist/adapters/node-test/preload/read-line-sync.d.ts +11 -0
  38. package/dist/adapters/node-test/preload/read-line-sync.js +25 -0
  39. package/dist/adapters/node-test/preload/read-unit.d.ts +11 -5
  40. package/dist/adapters/node-test/preload/read-unit.js +5 -4
  41. package/dist/adapters/node-test/run-isolated.d.ts +19 -10
  42. package/dist/adapters/node-test/run-isolated.js +68 -52
  43. package/dist/adapters/node-test/run-test-file.d.ts +12 -4
  44. package/dist/adapters/node-test/run-test-file.js +18 -14
  45. package/dist/adapters/node-test/run-test-process.d.ts +30 -13
  46. package/dist/adapters/node-test/run-test-process.js +38 -40
  47. package/dist/adapters/node-test/start-node-test-session.d.ts +10 -2
  48. package/dist/adapters/node-test/start-node-test-session.js +90 -84
  49. package/dist/adapters/node-test/start-test-process.d.ts +30 -0
  50. package/dist/adapters/node-test/start-test-process.js +27 -0
  51. package/dist/adapters/node-test/types/node-test-handle.d.ts +14 -1
  52. package/dist/adapters/node-test/types/process-watch.d.ts +4 -3
  53. package/dist/adapters/node-test/types/spare-processes.d.ts +20 -0
  54. package/dist/adapters/node-test/types/test-process-outcome.d.ts +8 -1
  55. package/dist/adapters/shared/allows-spares.d.ts +11 -0
  56. package/dist/adapters/shared/allows-spares.js +23 -0
  57. package/dist/adapters/shared/create-environment-proxy.d.ts +4 -3
  58. package/dist/adapters/shared/create-input-filter.d.ts +17 -14
  59. package/dist/adapters/shared/create-input-filter.js +2 -2
  60. package/dist/adapters/shared/enable-compile-cache.d.ts +32 -0
  61. package/dist/adapters/shared/enable-compile-cache.js +7 -0
  62. package/dist/adapters/shared/find-tsconfig-property.d.ts +13 -0
  63. package/dist/adapters/shared/find-tsconfig-property.js +6 -0
  64. package/dist/adapters/shared/get-spare-limit.d.ts +10 -0
  65. package/dist/adapters/shared/get-spare-limit.js +5 -0
  66. package/dist/adapters/shared/index-environment-hashes.d.ts +2 -2
  67. package/dist/adapters/shared/index-environment-hashes.js +5 -13
  68. package/dist/adapters/{node-test → shared}/list-flag-values.d.ts +2 -1
  69. package/dist/adapters/shared/list-flag-values.js +10 -0
  70. package/dist/adapters/shared/list-tsconfig-files.d.ts +14 -5
  71. package/dist/adapters/shared/list-tsconfig-files.js +15 -13
  72. package/dist/adapters/shared/parse-tsconfig.d.ts +10 -0
  73. package/dist/adapters/shared/parse-tsconfig.js +19 -0
  74. package/dist/adapters/shared/read-flag-name.d.ts +9 -0
  75. package/dist/adapters/shared/read-flag-name.js +5 -0
  76. package/dist/adapters/shared/read-node-options.d.ts +11 -0
  77. package/dist/adapters/shared/read-node-options.js +6 -0
  78. package/dist/adapters/shared/read-prefork-switch.d.ts +10 -0
  79. package/dist/adapters/shared/read-prefork-switch.js +5 -0
  80. package/dist/adapters/shared/read-tsconfig-extends.d.ts +2 -5
  81. package/dist/adapters/shared/read-tsconfig-extends.js +16 -31
  82. package/dist/adapters/shared/read-tsconfig-references.d.ts +12 -0
  83. package/dist/adapters/shared/read-tsconfig-references.js +13 -0
  84. package/dist/adapters/shared/track-file-reads.d.ts +13 -12
  85. package/dist/adapters/shared/track-file-reads.js +71 -71
  86. package/dist/adapters/shared/track-process-group.d.ts +2 -1
  87. package/dist/adapters/shared/track-process-group.js +7 -2
  88. package/dist/adapters/vitest/build-isolated-facts.d.ts +4 -3
  89. package/dist/adapters/vitest/collect-dependencies.d.ts +11 -5
  90. package/dist/adapters/vitest/collect-dependencies.js +36 -27
  91. package/dist/adapters/vitest/configure-project.d.ts +3 -2
  92. package/dist/adapters/vitest/configure-project.js +1 -1
  93. package/dist/adapters/vitest/create-forks-pool.d.ts +34 -7
  94. package/dist/adapters/vitest/create-forks-pool.js +102 -24
  95. package/dist/adapters/vitest/create-interleaved-sequencer.d.ts +3 -2
  96. package/dist/adapters/vitest/drop-signal-listeners.d.ts +14 -0
  97. package/dist/adapters/vitest/drop-signal-listeners.js +15 -0
  98. package/dist/adapters/vitest/get-cache-inputs.d.ts +3 -1
  99. package/dist/adapters/vitest/get-cache-inputs.js +43 -28
  100. package/dist/adapters/vitest/get-module-file.d.ts +3 -5
  101. package/dist/adapters/vitest/get-module-file.js +1 -1
  102. package/dist/adapters/vitest/get-spare-key.d.ts +15 -0
  103. package/dist/adapters/vitest/get-spare-key.js +15 -0
  104. package/dist/adapters/vitest/index.d.ts +2 -1
  105. package/dist/adapters/vitest/index.js +1 -0
  106. package/dist/adapters/vitest/is-virtual-module.d.ts +1 -2
  107. package/dist/adapters/vitest/is-virtual-module.js +1 -1
  108. package/dist/adapters/vitest/list-script-defines.d.ts +13 -0
  109. package/dist/adapters/vitest/list-script-defines.js +22 -0
  110. package/dist/adapters/vitest/read-unit-inputs.d.ts +2 -1
  111. package/dist/adapters/vitest/run-dry.js +1 -1
  112. package/dist/adapters/vitest/run-plan.d.ts +10 -8
  113. package/dist/adapters/vitest/run-plan.js +1 -1
  114. package/dist/adapters/vitest/run-specifications.d.ts +9 -2
  115. package/dist/adapters/vitest/run-specifications.js +22 -12
  116. package/dist/adapters/vitest/runner.d.ts +60 -29
  117. package/dist/adapters/vitest/runner.js +109 -86
  118. package/dist/adapters/vitest/start-vitest-session.d.ts +5 -1
  119. package/dist/adapters/vitest/start-vitest-session.js +64 -59
  120. package/dist/adapters/vitest/stop-hung-worker.d.ts +11 -4
  121. package/dist/adapters/vitest/stop-hung-worker.js +20 -7
  122. package/dist/adapters/vitest/types/mootant-forks-pool.d.ts +47 -0
  123. package/dist/adapters/vitest/types/vitest-session-state.d.ts +9 -8
  124. package/dist/adapters/vitest/types/vitest-worker.d.ts +48 -33
  125. package/dist/adapters/vitest/wait-for-workers.d.ts +5 -2
  126. package/dist/adapters/vitest/wait-for-workers.js +15 -15
  127. package/dist/adapters/vitest/worker/track-meta-defines.d.ts +39 -0
  128. package/dist/adapters/vitest/worker/track-meta-defines.js +23 -0
  129. package/dist/adapters/vitest/worker/track-values.d.ts +38 -0
  130. package/dist/adapters/vitest/worker/track-values.js +45 -0
  131. package/dist/adapters/vitest/worker/value-prefixes.d.ts +12 -0
  132. package/dist/adapters/vitest/worker/value-prefixes.js +6 -0
  133. package/dist/adapters/vitest/worker/wait-for-turn.d.ts +8 -6
  134. package/dist/adapters/vitest/worker/watch-property.d.ts +17 -0
  135. package/dist/adapters/vitest/worker/watch-property.js +27 -0
  136. package/dist/cli/create-run-progress.d.ts +8 -1
  137. package/dist/cli/create-run-progress.js +4 -1
  138. package/dist/cli/ensure-exit.d.ts +11 -0
  139. package/dist/cli/ensure-exit.js +15 -0
  140. package/dist/cli/html/build-html-report.js +1 -0
  141. package/dist/cli/html/client/main.js +1 -1
  142. package/dist/cli/html/client/render-overview.d.ts +3 -3
  143. package/dist/cli/index.d.ts +1 -0
  144. package/dist/cli/index.js +3 -2
  145. package/dist/cli/parse-arguments.d.ts +4 -0
  146. package/dist/cli/parse-arguments.js +4 -1
  147. package/dist/cli/report/build-run-report.js +1 -0
  148. package/dist/cli/report/format-command.d.ts +5 -0
  149. package/dist/cli/report/format-command.js +1 -1
  150. package/dist/cli/report/format-run-text-report.d.ts +5 -4
  151. package/dist/cli/report/format-run-text-report.js +10 -10
  152. package/dist/cli/report/slim-run-report.d.ts +10 -10
  153. package/dist/cli/report/slim-run-report.js +1 -0
  154. package/dist/cli/run-mutation.d.ts +5 -1
  155. package/dist/cli/run-mutation.js +32 -24
  156. package/dist/cli/terminal/create-spinner.d.ts +1 -2
  157. package/dist/cli/terminal/create-spinner.js +23 -32
  158. package/dist/cli/watch-interrupts.d.ts +41 -0
  159. package/dist/cli/watch-interrupts.js +32 -0
  160. package/dist/core/cache/apply-cached-units.d.ts +8 -7
  161. package/dist/core/cache/build-hash.d.ts +9 -0
  162. package/dist/core/cache/build-hash.js +2 -0
  163. package/dist/core/cache/cache-version.d.ts +4 -4
  164. package/dist/core/cache/check-dry-snapshot.d.ts +25 -0
  165. package/dist/core/cache/check-dry-snapshot.js +13 -0
  166. package/dist/core/cache/create-dry-reuse-miss.d.ts +12 -0
  167. package/dist/core/cache/create-dry-reuse-miss.js +7 -0
  168. package/dist/core/cache/create-dry-snapshot.d.ts +71 -0
  169. package/dist/core/cache/create-dry-snapshot.js +27 -0
  170. package/dist/core/cache/create-run-cache.d.ts +20 -2
  171. package/dist/core/cache/create-run-cache.js +31 -22
  172. package/dist/core/cache/create-snapshot-session.d.ts +12 -0
  173. package/dist/core/cache/create-snapshot-session.js +19 -0
  174. package/dist/core/cache/get-build-id.d.ts +11 -0
  175. package/dist/core/cache/get-build-id.js +7 -0
  176. package/dist/core/cache/get-cache-path.d.ts +1 -1
  177. package/dist/core/cache/get-cache-path.js +1 -1
  178. package/dist/core/cache/get-dry-snapshot-key.d.ts +47 -0
  179. package/dist/core/cache/get-dry-snapshot-key.js +43 -0
  180. package/dist/core/cache/get-dry-snapshot-path.d.ts +9 -0
  181. package/dist/core/cache/get-dry-snapshot-path.js +5 -0
  182. package/dist/core/cache/get-environment-key.d.ts +9 -4
  183. package/dist/core/cache/get-environment-key.js +3 -2
  184. package/dist/core/cache/get-test-file-keys.d.ts +2 -1
  185. package/dist/core/cache/get-test-file-keys.js +11 -10
  186. package/dist/core/cache/hash-files.d.ts +8 -7
  187. package/dist/core/cache/hash-files.js +17 -11
  188. package/dist/core/cache/hash-project-tree.d.ts +22 -0
  189. package/dist/core/cache/hash-project-tree.js +69 -0
  190. package/dist/core/cache/is-dry-reuse-miss.d.ts +8 -0
  191. package/dist/core/cache/is-dry-reuse-miss.js +4 -0
  192. package/dist/core/cache/list-file-hashes.d.ts +4 -0
  193. package/dist/core/cache/list-file-hashes.js +5 -2
  194. package/dist/core/cache/list-install-states.d.ts +12 -0
  195. package/dist/core/cache/list-install-states.js +19 -0
  196. package/dist/core/cache/list-variable-hashes.d.ts +15 -0
  197. package/dist/core/cache/list-variable-hashes.js +14 -0
  198. package/dist/core/cache/prepare-run-cache.d.ts +48 -22
  199. package/dist/core/cache/prepare-run-cache.js +86 -73
  200. package/dist/core/cache/read-dry-snapshot.d.ts +10 -0
  201. package/dist/core/cache/read-dry-snapshot.js +15 -0
  202. package/dist/core/cache/read-run-cache.js +6 -2
  203. package/dist/core/cache/save-dry-snapshot.d.ts +34 -0
  204. package/dist/core/cache/save-dry-snapshot.js +32 -0
  205. package/dist/core/cache/volatile-variables.d.ts +7 -0
  206. package/dist/core/cache/volatile-variables.js +11 -0
  207. package/dist/core/cache/write-run-cache.js +1 -1
  208. package/dist/core/config/load-typescript-config.d.ts +6 -1
  209. package/dist/core/config/load-typescript-config.js +26 -10
  210. package/dist/core/config/prepare-run.d.ts +7 -3
  211. package/dist/core/config/prepare-run.js +1 -0
  212. package/dist/core/config/resolve-run-settings.d.ts +3 -2
  213. package/dist/core/config/resolve-run-settings.js +1 -0
  214. package/dist/core/config/validate-config.js +3 -2
  215. package/dist/core/files/get-package-manifest.d.ts +12 -0
  216. package/dist/core/files/get-package-manifest.js +7 -0
  217. package/dist/core/generate/collect-candidates.d.ts +5 -1
  218. package/dist/core/generate/collect-candidates.js +125 -97
  219. package/dist/core/generate/generate-file-mutants.js +6 -5
  220. package/dist/core/index.d.ts +18 -0
  221. package/dist/core/mutators/shared/get-branch-copy-skip.d.ts +2 -2
  222. package/dist/core/mutators/shared/get-comparison-plan.d.ts +2 -2
  223. package/dist/core/mutators/shared/get-default-option-skip.d.ts +2 -2
  224. package/dist/core/mutators/shared/get-group-constant.d.ts +2 -2
  225. package/dist/core/mutators/shared/get-literal-skip.d.ts +3 -3
  226. package/dist/core/mutators/shared/get-loop-running-skip.d.ts +2 -2
  227. package/dist/core/mutators/shared/get-nullish-swap-skip.d.ts +2 -2
  228. package/dist/core/mutators/shared/get-or-default-skip.d.ts +2 -2
  229. package/dist/core/mutators/shared/get-owned-constants.d.ts +2 -2
  230. package/dist/core/mutators/shared/leave-now-skip.d.ts +2 -2
  231. package/dist/core/mutators/shared/no-op-callback-skip.d.ts +2 -2
  232. package/dist/core/plugins/create-mutator-registry.d.ts +4 -2
  233. package/dist/core/plugins/create-mutator-registry.js +15 -5
  234. package/dist/core/plugins/validate-plugin.d.ts +3 -3
  235. package/dist/core/plugins/validate-plugin.js +32 -10
  236. package/dist/core/regex/collect-pattern-changes.d.ts +2 -2
  237. package/dist/core/regex/create-regex-replacement.d.ts +2 -2
  238. package/dist/core/run/apply-isolated-result.d.ts +22 -14
  239. package/dist/core/run/apply-isolated-result.js +45 -26
  240. package/dist/core/run/count-run.d.ts +2 -1
  241. package/dist/core/run/create-run-state.d.ts +5 -0
  242. package/dist/core/run/create-run-state.js +1 -0
  243. package/dist/core/run/create-work-directory.d.ts +4 -1
  244. package/dist/core/run/create-work-directory.js +15 -12
  245. package/dist/core/run/decide-evidence.d.ts +4 -3
  246. package/dist/core/run/get-unit-evidence.d.ts +13 -7
  247. package/dist/core/run/get-unit-evidence.js +1 -1
  248. package/dist/core/run/guard-session.d.ts +18 -0
  249. package/dist/core/run/guard-session.js +30 -0
  250. package/dist/core/run/live-work-directories.d.ts +5 -0
  251. package/dist/core/run/live-work-directories.js +2 -0
  252. package/dist/core/run/read-isolated-unit.d.ts +6 -3
  253. package/dist/core/run/read-isolated-unit.js +77 -38
  254. package/dist/core/run/remove-live-work-directories.d.ts +7 -0
  255. package/dist/core/run/remove-live-work-directories.js +12 -0
  256. package/dist/core/run/run-isolated-rounds.d.ts +16 -12
  257. package/dist/core/run/run-isolated-rounds.js +3 -2
  258. package/dist/core/run/validate-adapter.d.ts +1 -1
  259. package/dist/core/run/validate-adapter.js +1 -1
  260. package/dist/core/run-mutants.d.ts +34 -2
  261. package/dist/core/run-mutants.js +356 -216
  262. package/dist/core/skips/skip-rules.d.ts +3 -1
  263. package/dist/package.js +1 -1
  264. package/dist/types/adapter/adapter-context.d.ts +20 -0
  265. package/dist/types/adapter/adapter-session.d.ts +2 -1
  266. package/dist/types/adapter/cache-inputs.d.ts +3 -2
  267. package/dist/types/adapter/dry-file.d.ts +4 -2
  268. package/dist/types/adapter/isolated-plan.d.ts +2 -1
  269. package/dist/types/adapter/isolated-result.d.ts +3 -1
  270. package/dist/types/adapter/run-inputs.d.ts +5 -4
  271. package/dist/types/adapter/test-adapter.d.ts +7 -0
  272. package/dist/types/cache/cache-entry.d.ts +9 -7
  273. package/dist/types/cache/cached-inputs.d.ts +2 -2
  274. package/dist/types/cache/dry-snapshot.d.ts +76 -0
  275. package/dist/types/cache/project-tree.d.ts +16 -0
  276. package/dist/types/cache/run-cache-file.d.ts +1 -1
  277. package/dist/types/cache/run-cache.d.ts +6 -5
  278. package/dist/types/config/plugin.d.ts +11 -2
  279. package/dist/types/config/run-config.d.ts +10 -0
  280. package/dist/types/config/run-settings.d.ts +6 -0
  281. package/dist/types/mutant/core-note.d.ts +12 -0
  282. package/dist/types/mutant/diagnostic.d.ts +1 -0
  283. package/dist/types/mutant/registered-skip-rule.d.ts +11 -0
  284. package/dist/types/mutant/skip-note.d.ts +7 -6
  285. package/dist/types/mutant/skip-rule-id.d.ts +3 -2
  286. package/dist/types/mutant/skip-rule.d.ts +2 -1
  287. package/dist/types/mutant/skipped-candidate.d.ts +14 -7
  288. package/dist/types/mutant/skipped-mutant.d.ts +6 -6
  289. package/dist/types/mutator/mutator.d.ts +3 -2
  290. package/dist/types/mutator/registered-mutator.d.ts +8 -0
  291. package/dist/types/regex/regex-change.d.ts +2 -2
  292. package/dist/types/report/html-report.d.ts +3 -2
  293. package/dist/types/report/list-report-skipped.d.ts +3 -2
  294. package/dist/types/report/run-report.d.ts +11 -2
  295. package/dist/types/report/slim-run-report.d.ts +1 -1
  296. package/dist/types/run/isolated-evidence.d.ts +3 -2
  297. package/dist/types/run/isolated-reason.d.ts +2 -1
  298. package/dist/types/run/run-durations.d.ts +8 -3
  299. package/dist/types/run/run-event.d.ts +10 -7
  300. package/dist/types/run/run-result.d.ts +11 -2
  301. package/dist/types/run/run-state.d.ts +21 -0
  302. package/dist/types/run/try-cause.d.ts +2 -1
  303. package/package.json +1 -1
  304. package/readme.md +85 -68
  305. package/skills/mootant/SKILL.md +36 -19
  306. package/skills/mootant/references/mutators.md +29 -23
  307. package/dist/adapters/node-test/list-flag-values.js +0 -9
  308. /package/dist/adapters/{node-test → shared}/loader-flags.d.ts +0 -0
  309. /package/dist/adapters/{node-test → shared}/loader-flags.js +0 -0
  310. /package/dist/{adapters/shared → core/files}/list-package-files.d.ts +0 -0
  311. /package/dist/{adapters/shared → core/files}/list-package-files.js +0 -0
  312. /package/dist/{adapters/shared → core/files}/read-package-type.d.ts +0 -0
  313. /package/dist/{adapters/shared → core/files}/read-package-type.js +0 -0
@@ -1,25 +1,27 @@
1
1
  import { installMutantRuntime as e } from "../../core/runtime/install-mutant-runtime.js";
2
2
  import { createInterleavedSequencer as t } from "./create-interleaved-sequencer.js";
3
- import { createOutputReporter as n } from "./create-output-reporter.js";
4
- import { createMootantPlugin as r } from "./create-mootant-plugin.js";
5
- import { createOutputStream as i } from "./create-output-stream.js";
6
- import { createForksPool as a } from "./create-forks-pool.js";
7
- import { checkVitestCopy as o } from "./check-vitest-copy.js";
8
- import { getCacheInputs as s } from "./get-cache-inputs.js";
9
- import { getRunnerPath as c } from "./get-runner-path.js";
10
- import { detectVitest as l } from "./detect-vitest.js";
11
- import { runIsolated as u } from "./run-isolated.js";
12
- import { runBatch as d } from "./run-batch.js";
13
- import { runDry as f } from "./run-dry.js";
14
- import p from "node:path";
15
- import { pathToFileURL as m } from "node:url";
16
- async function h(h, g) {
17
- let { root: _ } = h, v = await l(_);
18
- if (!v.available) throw Error(v.version === null ? `Vitest is not installed in ${_}.` : `mootant runs Vitest 5, but ${_} has Vitest ${v.version}.`);
19
- let y = c(), b = o(_, y);
20
- if (b !== null) throw Error(b);
21
- let x = await import(m(v.node).href), S = /* @__PURE__ */ new Map(), C = {
22
- pool: a(x.ForksPoolWorker, S),
3
+ import { readPreforkSwitch as n } from "../shared/read-prefork-switch.js";
4
+ import { createOutputReporter as r } from "./create-output-reporter.js";
5
+ import { dropSignalListeners as i } from "./drop-signal-listeners.js";
6
+ import { createMootantPlugin as a } from "./create-mootant-plugin.js";
7
+ import { createOutputStream as o } from "./create-output-stream.js";
8
+ import { createForksPool as s } from "./create-forks-pool.js";
9
+ import { checkVitestCopy as c } from "./check-vitest-copy.js";
10
+ import { getCacheInputs as l } from "./get-cache-inputs.js";
11
+ import { getRunnerPath as u } from "./get-runner-path.js";
12
+ import { detectVitest as d } from "./detect-vitest.js";
13
+ import { runIsolated as f } from "./run-isolated.js";
14
+ import { runBatch as p } from "./run-batch.js";
15
+ import { runDry as m } from "./run-dry.js";
16
+ import h from "node:path";
17
+ import { pathToFileURL as g } from "node:url";
18
+ async function _(_, v) {
19
+ let { root: y } = _, b = n(), x = await d(y);
20
+ if (!x.available) throw Error(x.version === null ? `Vitest is not installed in ${y}.` : `mootant runs Vitest 5, but ${y} has Vitest ${x.version}.`);
21
+ let S = u(), C = c(y, S);
22
+ if (C !== null) throw Error(C);
23
+ let w = await import(g(x.node).href), T = /* @__PURE__ */ new Map(), E = {
24
+ pool: s(w.ForksPoolWorker, T, b),
23
25
  mismatched: /* @__PURE__ */ new Set(),
24
26
  instrumented: !0,
25
27
  outside: /* @__PURE__ */ new Set(),
@@ -29,60 +31,63 @@ async function h(h, g) {
29
31
  diagnostics: [],
30
32
  error: null,
31
33
  files: null,
32
- runnerPath: y,
33
- spawns: S
34
- }, { onOutput: w } = h, T = null, E = await x.createVitest({
35
- ...g.config !== void 0 && { config: p.resolve(_, g.config) },
36
- ...h.concurrency !== null && { maxWorkers: h.concurrency },
37
- reporters: w === void 0 ? [] : [n(w, () => T)],
34
+ runnerPath: S,
35
+ spawns: T
36
+ };
37
+ _.signal?.addEventListener("abort", () => {
38
+ E.pool.interrupt();
39
+ }, { once: !0 });
40
+ let { onOutput: D } = _, O = null, k = await i(() => w.createVitest({
41
+ ...v.config !== void 0 && { config: h.resolve(y, v.config) },
42
+ ..._.concurrency !== null && { maxWorkers: _.concurrency },
43
+ reporters: D === void 0 ? [] : [r(D, () => O)],
38
44
  coverage: { enabled: !1 },
39
- includeTaskLocation: !0,
40
45
  passWithNoTests: !0,
41
46
  fsModuleCache: !1,
42
47
  watch: !1,
43
48
  cache: !1,
44
49
  bail: 0,
45
- root: _
46
- }, { plugins: [r(h, C)] }, w === void 0 ? {} : {
47
- stderr: i((e) => w(e, null)),
48
- stdout: i((e) => w(e, null))
49
- });
50
- if (T = E, C.error !== null) throw await E.close(), Error(C.error);
51
- if ((await E.globTestSpecifications()).length === 0) {
52
- await E.close();
53
- let e = new Set(E.projects.flatMap((e) => e.config.include));
50
+ root: y
51
+ }, { plugins: [a(_, E)] }, D === void 0 ? {} : {
52
+ stderr: o((e) => D(e, null)),
53
+ stdout: o((e) => D(e, null))
54
+ }));
55
+ if (O = k, E.error !== null) throw await k.close(), Error(E.error);
56
+ if ((await k.globTestSpecifications()).length === 0) {
57
+ await k.close();
58
+ let e = new Set(k.projects.flatMap((e) => e.config.include));
54
59
  throw Error(`No test files match the include patterns of Vitest (${[...e].map((e) => `"${e}"`).join(", ")}); set vitestAdapter({ config }) or fix the patterns.`);
55
60
  }
56
- let { sequence: D } = E.config;
57
- D.sequencer = t(D.sequencer);
58
- let O = e(), { coverage: k } = O;
59
- O.coverage = C.outside;
60
- let A = {
61
- context: h,
62
- vitest: E,
63
- state: C
64
- }, j = null;
65
- async function M() {
61
+ let { sequence: A } = k.config;
62
+ A.sequencer = t(A.sequencer);
63
+ let j = e(), { coverage: M } = j;
64
+ j.coverage = E.outside;
65
+ let N = {
66
+ context: _,
67
+ vitest: k,
68
+ state: E
69
+ }, P = null;
70
+ async function F() {
66
71
  try {
67
- await E.close();
72
+ await E.pool.drain(), await k.close();
68
73
  } finally {
69
- O.coverage === C.outside && (O.coverage = k);
74
+ j.coverage === E.outside && (j.coverage = M);
70
75
  }
71
76
  }
72
77
  return {
73
78
  listTestFiles: async () => {
74
- let e = new Set((await E.globTestSpecifications()).map(({ moduleId: e }) => e));
75
- for (let t of E.projects) for (let n of [...t.config.setupFiles, ...t.config.globalSetup]) e.add(n);
79
+ let e = new Set((await k.globTestSpecifications()).map(({ moduleId: e }) => e));
80
+ for (let t of k.projects) for (let n of [...t.config.setupFiles, ...t.config.globalSetup]) e.add(n);
76
81
  return [...e];
77
82
  },
78
- cacheInputs: () => Promise.resolve(s(E, C.environment)),
79
- close: () => (j ??= M(), j),
80
- runIsolated: (e) => u(A, e),
81
- dryRun: (e) => f(A, e),
82
- runBatch: (e) => d(A, e),
83
- workers: E.config.maxWorkers,
84
- diagnostics: C.diagnostics,
85
- version: E.version
83
+ cacheInputs: () => Promise.resolve(l(k, E.environment)),
84
+ close: () => (P ??= F(), P),
85
+ runIsolated: (e) => f(N, e),
86
+ dryRun: (e) => m(N, e),
87
+ runBatch: (e) => p(N, e),
88
+ workers: k.config.maxWorkers,
89
+ diagnostics: E.diagnostics,
90
+ version: k.version
86
91
  };
87
92
  }
88
- export { h as startVitestSession };
93
+ export { _ as startVitestSession };
@@ -1,11 +1,18 @@
1
+ import { MootantForksPool } from './types/mootant-forks-pool.js';
1
2
  /**
2
- * Stops a hung worker process with `SIGKILL`, but only when the process is
3
- * still alive and, outside Windows, is a child of this process: a process id
4
- * may have been reused by an unrelated process.
3
+ * Stops a hung worker process with `SIGKILL`. The pool stops it through the
4
+ * process of its worker, which cannot stand for another process, and leaves a
5
+ * process id that is none of its workers (`MootantForksPool.stopWorker`).
6
+ * Should Vitest stop exposing the processes of its workers, the process is
7
+ * stopped by its id, but only when it is still alive and, outside Windows, a
8
+ * child of this process, as a process id may have been reused by an unrelated
9
+ * process: the parent comes from `/proc/<pid>/stat` where Linux provides it,
10
+ * else from `ps`. A process whose parent neither tells is left.
5
11
  *
6
12
  * @param pid - Process id of the worker.
13
+ * @param pool - Pool of the session.
7
14
  * @returns Whether the worker was stopped.
8
15
  * @throws {Error} When the signal fails for another reason than a process that
9
16
  * is gone.
10
17
  */
11
- export declare function stopHungWorker(pid: number): Promise<boolean>;
18
+ export declare function stopHungWorker(pid: number, pool: Pick<MootantForksPool, 'stopWorker'>): Promise<boolean>;
@@ -1,11 +1,14 @@
1
- import { execFile as e } from "node:child_process";
2
- async function t(e) {
1
+ import { readFileSync as e } from "node:fs";
2
+ import { execFile as t } from "node:child_process";
3
+ async function n(e, t) {
4
+ let n = t.stopWorker(e);
5
+ if (n !== null) return n;
3
6
  try {
4
7
  process.kill(e, 0);
5
8
  } catch {
6
9
  return !1;
7
10
  }
8
- if (process.platform !== "win32" && await n(e) !== process.pid) return !1;
11
+ if (process.platform !== "win32" && (r(e) ?? await i(e)) !== process.pid) return !1;
9
12
  try {
10
13
  process.kill(e, "SIGKILL");
11
14
  } catch (e) {
@@ -14,16 +17,26 @@ async function t(e) {
14
17
  }
15
18
  return !0;
16
19
  }
17
- function n(t) {
20
+ function r(t) {
21
+ let n;
22
+ try {
23
+ n = e(`/proc/${t}/stat`, "utf8");
24
+ } catch {
25
+ return null;
26
+ }
27
+ let [, r] = n.slice(n.lastIndexOf(")") + 2).split(" ", 2);
28
+ return Number(r);
29
+ }
30
+ function i(e) {
18
31
  return new Promise((n) => {
19
- e("ps", [
32
+ t("ps", [
20
33
  "-o",
21
34
  "ppid=",
22
35
  "-p",
23
- String(t)
36
+ String(e)
24
37
  ], (e, t) => {
25
38
  n(e === null ? Number(t.trim()) : null);
26
39
  });
27
40
  });
28
41
  }
29
- export { t as stopHungWorker };
42
+ export { n as stopHungWorker };
@@ -0,0 +1,47 @@
1
+ import { PoolRunnerInitializer, TestSpecification } from 'vitest/node';
2
+ /**
3
+ * Mootant's pool of Vitest forks workers (`createForksPool`), which keeps spare
4
+ * workers for the tasks of a run.
5
+ */
6
+ export interface MootantForksPool extends PoolRunnerInitializer {
7
+ /**
8
+ * Tells the pool the test files of the run to come, whose tasks spare workers
9
+ * may serve.
10
+ *
11
+ * @param specifications - Test files of the run.
12
+ */
13
+ prepare(specifications: readonly TestSpecification[]): void
14
+
15
+ /**
16
+ * Stops the process of a worker or spare the pool started that still runs,
17
+ * with `SIGKILL` through the process itself, which cannot stand for another
18
+ * process before it ended.
19
+ *
20
+ * @param pid - Process id of the worker.
21
+ * @returns Whether the process was stopped: false when no process of the pool
22
+ * with this id runs, null when Vitest does not expose the processes of its
23
+ * workers, so the pool cannot tell.
24
+ */
25
+ stopWorker(pid: number): boolean | null
26
+
27
+ /**
28
+ * Stops the spare workers no task took, and the run's spares to come.
29
+ *
30
+ * @returns Resolves when every spare is gone.
31
+ */
32
+ drain(): Promise<void>
33
+
34
+ /**
35
+ * Stops the process of every worker and spare the pool started that still
36
+ * runs, as the run is interrupted, and starts none from then on: the start of
37
+ * a task fails at once.
38
+ */
39
+ interrupt(): void
40
+ }
41
+
42
+ /**
43
+ * Options of a worker of a pool, as Vitest gives them for each task.
44
+ */
45
+ export type PoolWorkerOptions = Parameters<
46
+ PoolRunnerInitializer['createPoolWorker']
47
+ >[0]
@@ -1,7 +1,8 @@
1
- import { PoolRunnerInitializer, Vitest } from 'vitest/node';
1
+ import { Vitest } from 'vitest/node';
2
2
  import { AdapterContext } from '../../../types/adapter/adapter-context.js';
3
3
  import { SwitchedFile } from '../../../types/adapter/switched-file.js';
4
4
  import { Diagnostic } from '../../../types/mutant/diagnostic.js';
5
+ import { MootantForksPool } from './mootant-forks-pool.js';
5
6
  /**
6
7
  * State shared by the Vitest session, its Vite plugin and the project
7
8
  * configuration hook.
@@ -20,16 +21,11 @@ export interface VitestSessionState {
20
21
  files: Map<string, SwitchedFile> | null
21
22
 
22
23
  /**
23
- * Epoch milliseconds at which the pool started each worker process of the
24
- * current run, by process id (`createForksPool`).
24
+ * Epoch milliseconds at which each task of the current run got its worker
25
+ * process, by process id (`createForksPool`).
25
26
  */
26
27
  spawns: Map<number, number>
27
28
 
28
- /**
29
- * Pool the projects run with (`createForksPool`).
30
- */
31
- pool: PoolRunnerInitializer
32
-
33
29
  /**
34
30
  * Real paths of the module ids the plugin has seen, by id.
35
31
  */
@@ -45,6 +41,11 @@ export interface VitestSessionState {
45
41
  */
46
42
  mismatched: Set<string>
47
43
 
44
+ /**
45
+ * Pool the projects run with (`createForksPool`).
46
+ */
47
+ pool: MootantForksPool
48
+
48
49
  /**
49
50
  * Whether the plugin serves switched texts; false while a dry run checks the
50
51
  * tests without them.
@@ -32,7 +32,8 @@ export type VitestOutRecord =
32
32
 
33
33
  /**
34
34
  * Names of the environment variables the test code read, or `*` when it
35
- * listed them all, sorted.
35
+ * listed them all, and of the values of `provide` and `define` it read
36
+ * (`trackValues`), sorted.
36
37
  */
37
38
  environment: string[]
38
39
 
@@ -149,6 +150,52 @@ export type VitestOutRecord =
149
150
  kind: 'test'
150
151
  }
151
152
 
153
+ /**
154
+ * Options the main process provides to workers under the key `mootant`.
155
+ */
156
+ export interface VitestWorkerOptions {
157
+ /**
158
+ * Defines Vitest runs as a script in the workers of each project, by key,
159
+ * with whether each value is code (`listScriptDefines`), by project name;
160
+ * none when omitted.
161
+ */
162
+ defines?: Record<string, Record<string, boolean>>
163
+
164
+ /**
165
+ * Watchdog budgets of a dry run (`DryRunRequest.timeouts`), or null in batch
166
+ * and isolated runs, whose plans carry their own.
167
+ */
168
+ timeouts: { test: number; file: number } | null
169
+
170
+ /**
171
+ * Kind of the run.
172
+ */
173
+ mode: 'isolated' | 'batch' | 'dry'
174
+
175
+ /**
176
+ * Whether a unit of an isolated run starts without waiting for the unit
177
+ * before it of the same test file (`AdapterContext.parallelUnits`); false or
178
+ * omitted waits.
179
+ */
180
+ parallel?: boolean
181
+
182
+ /**
183
+ * Work directory of this run.
184
+ */
185
+ directory: string
186
+
187
+ /**
188
+ * Whether a dry run tries every test twice in a row (`DryRunRequest.repeat`);
189
+ * false in batch and isolated runs.
190
+ */
191
+ repeat: boolean
192
+
193
+ /**
194
+ * Project root; reads outside it count too (`createInputFilter`).
195
+ */
196
+ root: string
197
+ }
198
+
152
199
  /**
153
200
  * Content of `beat/<pid>.json`; the main process timestamps it when it first
154
201
  * sees `sequence`.
@@ -195,38 +242,6 @@ export interface VitestHeartbeat {
195
242
  pid: number
196
243
  }
197
244
 
198
- /**
199
- * Options the main process provides to workers under the key `mootant`.
200
- */
201
- export interface VitestWorkerOptions {
202
- /**
203
- * Watchdog budgets of a dry run (`DryRunRequest.timeouts`), or null in batch
204
- * and isolated runs, whose plans carry their own.
205
- */
206
- timeouts: { test: number; file: number } | null
207
-
208
- /**
209
- * Kind of the run.
210
- */
211
- mode: 'isolated' | 'batch' | 'dry'
212
-
213
- /**
214
- * Work directory of this run.
215
- */
216
- directory: string
217
-
218
- /**
219
- * Whether a dry run tries every test twice in a row (`DryRunRequest.repeat`);
220
- * false in batch and isolated runs.
221
- */
222
- repeat: boolean
223
-
224
- /**
225
- * Project root; reads outside it count too (`createInputFilter`).
226
- */
227
- root: string
228
- }
229
-
230
245
  /**
231
246
  * Unhandled error as a worker recorded it: what Vitest's listener passed to the
232
247
  * worker's RPC (`interceptStrays`), encoded (`encodeStray`), before the main
@@ -1,3 +1,4 @@
1
+ import { MootantForksPool } from './types/mootant-forks-pool.js';
1
2
  /**
2
3
  * Waits until every worker of the run is gone. Vitest ends a run as soon as its
3
4
  * workers reported their files, and stops them afterwards: worker-scoped
@@ -12,9 +13,11 @@
12
13
  * that is, and the watchdog must run until the wait is over. A beat file that
13
14
  * cannot be read, such as one being written, is read again on the next look and
14
15
  * counts as a beat without budget until then. Workers still alive past the
15
- * limit and without such a beat are stopped, so no worker outlives the run.
16
+ * limit and without such a beat are stopped (`stopHungWorker`), so no worker
17
+ * outlives the run.
16
18
  *
17
19
  * @param directory - Work directory of the session.
20
+ * @param pool - Pool of the session.
18
21
  * @param limits - Milliseconds to wait at most without a pending heartbeat and
19
22
  * past the budget of one.
20
23
  * @param limits.wait - Milliseconds to wait at most without a pending beat.
@@ -24,7 +27,7 @@
24
27
  * @throws {Error} When the folders of the run cannot be read or a worker cannot
25
28
  * be stopped.
26
29
  */
27
- export declare function waitForWorkers(directory: string, limits?: {
30
+ export declare function waitForWorkers(directory: string, pool: Pick<MootantForksPool, 'stopWorker'>, limits?: {
28
31
  grace: number;
29
32
  wait: number;
30
33
  }): Promise<void>;
@@ -3,37 +3,37 @@ import { stopHungWorker as t } from "./stop-hung-worker.js";
3
3
  import { readFileSync as n, readdirSync as r } from "node:fs";
4
4
  import i from "node:path";
5
5
  import { setInterval as a } from "node:timers/promises";
6
- async function o(o, s = {
6
+ async function o(o, s, c = {
7
7
  grace: 5e3,
8
8
  wait: 7e4
9
9
  }) {
10
- let c = i.join(o, "worker"), l = i.join(o, "beat"), u = performance.now() + s.wait, d = /* @__PURE__ */ new Map();
11
- function f() {
12
- let t = performance.now(), a = r(c).filter((t) => e(t));
10
+ let l = i.join(o, "worker"), u = i.join(o, "beat"), d = performance.now() + c.wait, f = /* @__PURE__ */ new Map();
11
+ function p() {
12
+ let t = performance.now(), a = r(l).filter((t) => e(t));
13
13
  if (a.length === 0) return a;
14
14
  let o = !1;
15
- for (let e of r(l)) {
15
+ for (let e of r(u)) {
16
16
  let r;
17
17
  try {
18
- r = JSON.parse(n(i.join(l, e), "utf8"));
18
+ r = JSON.parse(n(i.join(u, e), "utf8"));
19
19
  } catch {
20
20
  r = {
21
21
  sequence: -1,
22
22
  budget: 0
23
23
  };
24
24
  }
25
- let c = d.get(e);
26
- c?.sequence !== r.sequence && (c = {
27
- deadline: t + r.budget + s.grace,
25
+ let s = f.get(e);
26
+ s?.sequence !== r.sequence && (s = {
27
+ deadline: t + r.budget + c.grace,
28
28
  sequence: r.sequence
29
- }, d.set(e, c)), a.includes(i.basename(e, ".json")) && t < c.deadline && (o = !0);
29
+ }, f.set(e, s)), a.includes(i.basename(e, ".json")) && t < s.deadline && (o = !0);
30
30
  }
31
- return o || t < u ? null : a;
31
+ return o || t < d ? null : a;
32
32
  }
33
- let p = f();
34
- if (p === null) {
35
- for await (let e of a(10)) if (p = f(), p !== null) break;
33
+ let m = p();
34
+ if (m === null) {
35
+ for await (let e of a(10)) if (m = p(), m !== null) break;
36
36
  }
37
- await Promise.all(p.map((e) => t(Number(e))));
37
+ await Promise.all(m.map((e) => t(Number(e), s)));
38
38
  }
39
39
  export { o as waitForWorkers };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Module evaluator of Vite's module runner, as far as it is used here.
3
+ */
4
+ interface Evaluator {
5
+ /**
6
+ * Runs the code of a module that Vite transformed, with the context it gets,
7
+ * its `import.meta` among it.
8
+ */
9
+ runInlinedModule(context: Record<string, unknown>, code: string, module: unknown): Promise<unknown>;
10
+ }
11
+ /**
12
+ * Makes the defines of `import.meta` report their first read in the modules
13
+ * Vitest evaluates from now on. Vitest's script keeps them in `metaDefines` of
14
+ * the worker state, which its module evaluator copies into the `import.meta` of
15
+ * each module before the module runs: they are taken out of it, and the wrapped
16
+ * evaluator puts them on the `import.meta` of each module itself, as Vitest
17
+ * would, watched until the first read of the unit reports one
18
+ * (`watchProperty`), and plain once it did. Nothing changes when the module
19
+ * runner has no evaluator to wrap or a define is not in `metaDefines`. The
20
+ * tracking is installed once per worker state; a later receiver on the same
21
+ * state takes it over.
22
+ *
23
+ * @param state - Vitest's worker state.
24
+ * @param runner - Module runner Vitest gave the test runner (`moduleRunner`).
25
+ * @param input - Defines to track and the receiver of the names read.
26
+ * @param input.keys - Keys of the defines, such as `import.meta.version`.
27
+ * @param input.record - Receives the names read, such as
28
+ * `define=import.meta.version`.
29
+ * @returns Whether the defines are tracked.
30
+ */
31
+ export declare function trackMetaDefines(state: {
32
+ metaDefines?: Record<string, unknown>;
33
+ }, runner: {
34
+ evaluator?: Partial<Evaluator>;
35
+ } | undefined, input: {
36
+ record(name: string): void;
37
+ keys: readonly string[];
38
+ }): boolean;
39
+ export {};
@@ -0,0 +1,23 @@
1
+ import { VALUE_PREFIXES as e } from "./value-prefixes.js";
2
+ import { watchProperty as t } from "./watch-property.js";
3
+ const n = Symbol.for("mootant.vitest.meta");
4
+ function r(r, i, a) {
5
+ let o = Reflect.get(r, n);
6
+ if (o !== void 0) return o.record = a.record, !0;
7
+ let s = i?.evaluator, c = r.metaDefines ?? {}, l = a.keys.map((e) => e.slice(12));
8
+ if (typeof s?.runInlinedModule != "function" || l.some((e) => !Object.hasOwn(c, e))) return !1;
9
+ let u = s.runInlinedModule, d = { record: a.record }, f = l.map((e) => [e, c[e]]), p = new Set(l);
10
+ for (let e of l) Reflect.deleteProperty(c, e);
11
+ return s.runInlinedModule = (n, r, i) => {
12
+ let a = n.__vite_ssr_import_meta__;
13
+ for (let [n, r] of f) {
14
+ let i = n.split("."), o = i.pop(), s = a;
15
+ for (let e of i) s[e] ||= {}, s = s[e];
16
+ s[o] = r, p.has(n) && t(s, o, () => {
17
+ p.delete(n), d.record(`${e.define}import.meta.${n}`);
18
+ });
19
+ }
20
+ return u.call(s, n, r, i);
21
+ }, Reflect.set(r, n, d), !0;
22
+ }
23
+ export { r as trackMetaDefines };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Makes the values of `provide` and `define` report what code reads, under the
3
+ * names of `VALUE_PREFIXES`. The provided context of the worker state, which
4
+ * `inject` reads on every call, and its alias in the state's context are
5
+ * replaced with a proxy that reports a key read, tested or asked for its
6
+ * descriptor, a missing one too, and `provide=*` when code lists them, but
7
+ * never mootant's own options. Each define Vitest set as a plain property, on
8
+ * `globalThis` or, for a key with dots, on the object that holds its last part,
9
+ * is a getter that reports its first read (`wrapDefine`); `in`, `Object.keys`
10
+ * and descriptors call none, as the names count under `defines=`. Defines of
11
+ * `import.meta` are left to `trackMetaDefines`. Vitest evaluates a define given
12
+ * as code before the runner exists, and that code may read and change anything,
13
+ * or hold `process.env` itself, so such a define is reported at once with
14
+ * `provide=*` and `*`. So is a define that is not such a property, without
15
+ * them, and every value when the project has a custom snapshot environment,
16
+ * which Vitest may load before the runner. The tracking is installed once per
17
+ * worker state; a later receiver on the same state takes it over and gets those
18
+ * names too.
19
+ *
20
+ * @param state - Vitest's worker state.
21
+ * @param project - Defines and snapshot environment of the project.
22
+ * @param project.defines - Defines Vitest set as globals (`defines` of the
23
+ * serialized configuration).
24
+ * @param project.scripted - Defines Vitest ran as a script
25
+ * (`listScriptDefines`), by key, with whether each value is code.
26
+ * @param project.snapshotEnvironment - Custom snapshot environment, if any.
27
+ * @param record - Receives the names read.
28
+ */
29
+ export declare function trackValues(state: {
30
+ ctx: {
31
+ providedContext: object;
32
+ };
33
+ providedContext: object;
34
+ }, project: {
35
+ scripted: Readonly<Record<string, boolean>>;
36
+ defines: Record<string, unknown>;
37
+ snapshotEnvironment?: string;
38
+ }, record: (name: string) => void): void;
@@ -0,0 +1,45 @@
1
+ import { createEnvironmentProxy as e } from "../../shared/create-environment-proxy.js";
2
+ import { VALUE_PREFIXES as t } from "./value-prefixes.js";
3
+ import { watchProperty as n } from "./watch-property.js";
4
+ const r = `${t.provide}*`, i = Symbol.for("mootant.vitest.values");
5
+ function a(n, a, s) {
6
+ let c = Reflect.get(n, i);
7
+ if (c === void 0) {
8
+ let l = {
9
+ names: /* @__PURE__ */ new Set([t.defines]),
10
+ record: s
11
+ }, u = a.snapshotEnvironment !== void 0;
12
+ u && l.names.add(r), n.providedContext = e(n.providedContext, {
13
+ record: (e) => {
14
+ l.record(`${t.provide}${e}`);
15
+ },
16
+ ignored: /* @__PURE__ */ new Set(["mootant"]),
17
+ listing: !1
18
+ }), n.ctx.providedContext = n.providedContext;
19
+ let d = [...Object.keys(a.defines).map((e) => [e, !1]), ...Object.entries(a.scripted)];
20
+ for (let [e, n] of d) {
21
+ let i = `${t.define}${e}`;
22
+ if (n) {
23
+ l.names.add(i).add(r).add("*");
24
+ continue;
25
+ }
26
+ let a = e.startsWith("import.meta.") || o(e, () => {
27
+ l.record(i);
28
+ });
29
+ (u || !a) && l.names.add(i);
30
+ }
31
+ Reflect.set(n, i, l), c = l;
32
+ }
33
+ c.record = s;
34
+ for (let e of c.names) s(e);
35
+ }
36
+ function o(e, t) {
37
+ let r = e.split("."), i = r.pop(), a = globalThis;
38
+ for (let e of r) {
39
+ let t = Reflect.getOwnPropertyDescriptor(a, e)?.value;
40
+ if (typeof t != "object" || !t) return !1;
41
+ a = t;
42
+ }
43
+ return n(a, i, t);
44
+ }
45
+ export { a as trackValues };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Prefixes of the names under which the cache keys the values of `provide` and
3
+ * `define` that test code reads, beside the names of environment variables:
4
+ * `provide=<key>` for a provided value, `provide=*` for all of them,
5
+ * `define=<key>` for a define, and `defines=` for the names of the defines of a
6
+ * project. Each holds `=`, which no environment variable name has.
7
+ */
8
+ export declare const VALUE_PREFIXES: {
9
+ defines: string;
10
+ provide: string;
11
+ define: string;
12
+ };