@contrast/agent-bundle 5.41.0 → 5.45.1

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 (489) hide show
  1. package/README.md +1 -10
  2. package/node_modules/@contrast/agent/README.md +1 -10
  3. package/node_modules/@contrast/agent/package.json +13 -12
  4. package/node_modules/@contrast/agent-swc-plugin/package.json +3 -3
  5. package/node_modules/@contrast/agentify/lib/rewrite-hooks.js +3 -3
  6. package/node_modules/@contrast/agentify/lib/utils.js +13 -7
  7. package/node_modules/@contrast/agentify/package.json +17 -17
  8. package/node_modules/@contrast/architecture-components/package.json +6 -6
  9. package/node_modules/@contrast/assess/lib/dataflow/propagation/install/ejs/template.js +1 -1
  10. package/node_modules/@contrast/assess/lib/dataflow/propagation/install/pug/index.js +1 -1
  11. package/node_modules/@contrast/assess/lib/dataflow/sinks/install/http/server-response.js +1 -12
  12. package/node_modules/@contrast/assess/lib/dataflow/sinks/install/restify.js +1 -1
  13. package/node_modules/@contrast/assess/lib/dataflow/sources/install/http.js +1 -1
  14. package/node_modules/@contrast/assess/lib/dataflow/tracker.js +1 -1
  15. package/node_modules/@contrast/assess/lib/get-source-context.js +1 -1
  16. package/node_modules/@contrast/assess/lib/response-scanning/install/http.js +0 -12
  17. package/node_modules/@contrast/assess/package.json +14 -14
  18. package/node_modules/@contrast/code-events/binding.gyp +1 -1
  19. package/node_modules/@contrast/code-events/package.json +11 -9
  20. package/node_modules/@contrast/code-events/prebuilds/darwin-x64+arm64/@contrast+code-events.abi108.node +0 -0
  21. package/node_modules/@contrast/code-events/prebuilds/darwin-x64+arm64/@contrast+code-events.abi115.node +0 -0
  22. package/node_modules/@contrast/code-events/prebuilds/darwin-x64+arm64/@contrast+code-events.abi127.node +0 -0
  23. package/node_modules/@contrast/code-events/prebuilds/darwin-x64+arm64/{@contrast+code-events.abi93.node → @contrast+code-events.abi137.node} +0 -0
  24. package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi108.armv8.node +0 -0
  25. package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi115.armv8.node +0 -0
  26. package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi127.armv8.node +0 -0
  27. package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi137.armv8.node +0 -0
  28. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi108.glibc.node +0 -0
  29. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi108.musl.node +0 -0
  30. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi115.glibc.node +0 -0
  31. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi115.musl.node +0 -0
  32. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi127.glibc.node +0 -0
  33. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi127.musl.node +0 -0
  34. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi137.glibc.node +0 -0
  35. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi137.musl.node +0 -0
  36. package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi108.node +0 -0
  37. package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi115.node +0 -0
  38. package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi127.node +0 -0
  39. package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi137.node +0 -0
  40. package/node_modules/@contrast/common/lib/constants.d.ts +1 -1
  41. package/node_modules/@contrast/common/lib/constants.js +1 -1
  42. package/node_modules/@contrast/common/lib/index.js +15 -15
  43. package/node_modules/@contrast/common/lib/primordials.d.ts +22 -20
  44. package/node_modules/@contrast/common/lib/types.d.ts +18 -6
  45. package/node_modules/@contrast/common/package.json +2 -2
  46. package/node_modules/@contrast/config/lib/options.js +29 -4
  47. package/node_modules/@contrast/config/package.json +4 -4
  48. package/node_modules/@contrast/core/lib/app-info.js +53 -74
  49. package/node_modules/@contrast/core/lib/index.d.ts +17 -1
  50. package/node_modules/@contrast/core/lib/sensitive-data-masking/index.js +33 -5
  51. package/node_modules/@contrast/core/package.json +10 -9
  52. package/node_modules/@contrast/deadzones/package.json +6 -6
  53. package/node_modules/@contrast/dep-hooks/lib/export-handler-registry.d.ts +17 -13
  54. package/node_modules/@contrast/dep-hooks/lib/export-handler-registry.js +16 -4
  55. package/node_modules/@contrast/dep-hooks/lib/export-hook-descriptor.d.ts +2 -2
  56. package/node_modules/@contrast/dep-hooks/lib/export-hook-descriptor.js +2 -3
  57. package/node_modules/@contrast/dep-hooks/lib/handler-invoker.d.ts +6 -6
  58. package/node_modules/@contrast/dep-hooks/lib/handler-invoker.js +0 -1
  59. package/node_modules/@contrast/dep-hooks/lib/helpers.d.ts +0 -7
  60. package/node_modules/@contrast/dep-hooks/lib/helpers.js +2 -18
  61. package/node_modules/@contrast/dep-hooks/lib/index.d.ts +17 -12
  62. package/node_modules/@contrast/dep-hooks/lib/index.js +5 -3
  63. package/node_modules/@contrast/dep-hooks/lib/package-finder.d.ts +2 -1
  64. package/node_modules/@contrast/dep-hooks/lib/package-finder.js +6 -6
  65. package/node_modules/@contrast/dep-hooks/package.json +4 -3
  66. package/node_modules/@contrast/distringuish/package.json +7 -6
  67. package/node_modules/@contrast/distringuish/prebuilds/darwin-x64+arm64/@contrast+distringuish.abi108.node +0 -0
  68. package/node_modules/@contrast/distringuish/prebuilds/darwin-x64+arm64/@contrast+distringuish.abi115.node +0 -0
  69. package/node_modules/@contrast/distringuish/prebuilds/darwin-x64+arm64/@contrast+distringuish.abi127.node +0 -0
  70. package/node_modules/@contrast/distringuish/prebuilds/darwin-x64+arm64/{@contrast+distringuish.abi93.node → @contrast+distringuish.abi137.node} +0 -0
  71. package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi108.armv8.node +0 -0
  72. package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi115.armv8.node +0 -0
  73. package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi127.armv8.node +0 -0
  74. package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi137.armv8.node +0 -0
  75. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi108.glibc.node +0 -0
  76. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi108.musl.node +0 -0
  77. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi115.glibc.node +0 -0
  78. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi115.musl.node +0 -0
  79. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi127.glibc.node +0 -0
  80. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi127.musl.node +0 -0
  81. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi137.glibc.node +0 -0
  82. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi137.musl.node +0 -0
  83. package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi108.node +0 -0
  84. package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi115.node +0 -0
  85. package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi127.node +0 -0
  86. package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi137.node +0 -0
  87. package/node_modules/@contrast/esm-hooks/lib/debug-methods.mjs +4 -4
  88. package/node_modules/@contrast/esm-hooks/lib/get-file-type.mjs +2 -9
  89. package/node_modules/@contrast/esm-hooks/lib/hooks.mjs +0 -2
  90. package/node_modules/@contrast/esm-hooks/lib/redirects/builtin/fs/promises.mjs +2 -0
  91. package/node_modules/@contrast/esm-hooks/lib/redirects/builtin/fs.mjs +3 -0
  92. package/node_modules/@contrast/esm-hooks/lib/redirects/builtin/util.mjs +1 -0
  93. package/node_modules/@contrast/esm-hooks/package.json +7 -7
  94. package/node_modules/@contrast/fn-inspect/package.json +9 -5
  95. package/node_modules/@contrast/fn-inspect/prebuilds/darwin-x64+arm64/@contrast+fn-inspect.abi108.node +0 -0
  96. package/node_modules/@contrast/fn-inspect/prebuilds/darwin-x64+arm64/@contrast+fn-inspect.abi115.node +0 -0
  97. package/node_modules/@contrast/fn-inspect/prebuilds/darwin-x64+arm64/@contrast+fn-inspect.abi127.node +0 -0
  98. package/node_modules/@contrast/fn-inspect/prebuilds/darwin-x64+arm64/{@contrast+fn-inspect.abi93.node → @contrast+fn-inspect.abi137.node} +0 -0
  99. package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi108.armv8.node +0 -0
  100. package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi115.armv8.node +0 -0
  101. package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi127.armv8.node +0 -0
  102. package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi137.armv8.node +0 -0
  103. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi108.glibc.node +0 -0
  104. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi108.musl.node +0 -0
  105. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi115.glibc.node +0 -0
  106. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi115.musl.node +0 -0
  107. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi127.glibc.node +0 -0
  108. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi127.musl.node +0 -0
  109. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi137.glibc.node +0 -0
  110. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/{@contrast+fn-inspect.abi93.musl.node → @contrast+fn-inspect.abi137.musl.node} +0 -0
  111. package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi108.node +0 -0
  112. package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi115.node +0 -0
  113. package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi127.node +0 -0
  114. package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi137.node +0 -0
  115. package/node_modules/@contrast/instrumentation/lib/http2.js +0 -11
  116. package/node_modules/@contrast/instrumentation/package.json +6 -6
  117. package/node_modules/@contrast/library-analysis/lib/install/library-reporting/dep.json +312 -224
  118. package/node_modules/@contrast/library-analysis/package.json +6 -6
  119. package/node_modules/@contrast/logger/lib/index.js +18 -8
  120. package/node_modules/@contrast/logger/lib/serializers.js +5 -5
  121. package/node_modules/@contrast/logger/lib/utils.d.ts +0 -6
  122. package/node_modules/@contrast/logger/package.json +4 -4
  123. package/node_modules/@contrast/metrics/lib/index.d.ts +6 -6
  124. package/node_modules/@contrast/metrics/lib/index.js +0 -1
  125. package/node_modules/@contrast/metrics/package.json +7 -7
  126. package/node_modules/@contrast/patcher/package.json +3 -3
  127. package/node_modules/@contrast/perf/package.json +7 -4
  128. package/node_modules/@contrast/protect/lib/hardening/handlers.js +37 -21
  129. package/node_modules/@contrast/protect/lib/index.d.ts +3 -2
  130. package/node_modules/@contrast/protect/lib/index.js +9 -2
  131. package/node_modules/@contrast/protect/lib/input-analysis/handlers.js +275 -233
  132. package/node_modules/@contrast/protect/lib/input-analysis/install/http.js +3 -4
  133. package/node_modules/@contrast/protect/lib/input-tracing/{handlers/index.js → handlers.js} +15 -15
  134. package/node_modules/@contrast/protect/lib/input-tracing/index.js +0 -1
  135. package/node_modules/@contrast/protect/lib/make-source-context.js +5 -7
  136. package/node_modules/@contrast/protect/lib/policy.js +130 -95
  137. package/node_modules/@contrast/protect/lib/semantic-analysis/handlers.js +19 -18
  138. package/node_modules/@contrast/protect/package.json +12 -12
  139. package/node_modules/@contrast/reporter/lib/index.js +1 -1
  140. package/node_modules/@contrast/reporter/lib/reporters/base.d.ts +0 -1
  141. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/index.d.ts +4 -2
  142. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/index.js +14 -14
  143. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/translations.d.ts +43 -6
  144. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/translations.js +262 -429
  145. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/server-inventory.d.ts +3 -3
  146. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/index.d.ts +11 -11
  147. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/index.js +93 -93
  148. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/translations.js +12 -13
  149. package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/utils.js +6 -7
  150. package/node_modules/@contrast/reporter/lib/reporters/file.js +1 -1
  151. package/node_modules/@contrast/reporter/lib/reporters/security-logger/index.d.ts +2 -3
  152. package/node_modules/@contrast/reporter/lib/reporters/security-logger/index.js +72 -86
  153. package/node_modules/@contrast/reporter/lib/reporters/security-logger/messages.js +6 -7
  154. package/node_modules/@contrast/reporter/lib/validators.js +0 -1
  155. package/node_modules/@contrast/reporter/node_modules/sonic-boom/.husky/pre-commit +2 -2
  156. package/node_modules/@contrast/reporter/node_modules/sonic-boom/.taprc +5 -0
  157. package/node_modules/@contrast/reporter/node_modules/sonic-boom/README.md +2 -4
  158. package/node_modules/@contrast/reporter/node_modules/sonic-boom/bench.js +5 -36
  159. package/node_modules/@contrast/reporter/node_modules/sonic-boom/index.js +56 -300
  160. package/node_modules/@contrast/reporter/node_modules/sonic-boom/package.json +12 -7
  161. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test.js +1684 -0
  162. package/node_modules/@contrast/reporter/node_modules/sonic-boom/types/index.d.ts +1 -2
  163. package/node_modules/@contrast/reporter/package.json +10 -10
  164. package/node_modules/@contrast/rewriter/lib/index.js +5 -43
  165. package/node_modules/@contrast/rewriter/package.json +8 -8
  166. package/node_modules/@contrast/route-coverage/lib/install/express/express5.js +0 -5
  167. package/node_modules/@contrast/route-coverage/lib/install/hapi.js +9 -2
  168. package/node_modules/@contrast/route-coverage/lib/install/restify.js +1 -1
  169. package/node_modules/@contrast/route-coverage/package.json +10 -10
  170. package/node_modules/@contrast/scopes/package.json +6 -6
  171. package/node_modules/@contrast/sec-obs/lib/traces/http.js +1 -1
  172. package/node_modules/@contrast/sec-obs/lib/traces/http.test.js +1 -1
  173. package/node_modules/@contrast/sec-obs/package.json +10 -10
  174. package/node_modules/@contrast/sources/lib/index.js +1 -1
  175. package/node_modules/@contrast/sources/lib/index.test.js +0 -26
  176. package/node_modules/@contrast/sources/package.json +3 -3
  177. package/node_modules/@contrast/telemetry/package.json +6 -6
  178. package/node_modules/@opentelemetry/semantic-conventions/README.md +3 -2
  179. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.d.ts +4350 -2882
  180. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js +4350 -2882
  181. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js.map +1 -1
  182. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_events.d.ts +136 -0
  183. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_events.js +154 -0
  184. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_events.js.map +1 -0
  185. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.d.ts +713 -141
  186. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.js +713 -141
  187. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.js.map +1 -1
  188. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index-incubating.d.ts +2 -0
  189. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index-incubating.js +2 -0
  190. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index-incubating.js.map +1 -1
  191. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index.d.ts +1 -0
  192. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index.js +1 -0
  193. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index.js.map +1 -1
  194. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.d.ts +7 -1
  195. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js +7 -1
  196. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js.map +1 -1
  197. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_events.d.ts +5 -0
  198. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_events.js +23 -0
  199. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_events.js.map +1 -0
  200. package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.d.ts +1 -1
  201. package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js +1 -1
  202. package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js.map +1 -1
  203. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.d.ts +4350 -2882
  204. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.js +4350 -2882
  205. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.js.map +1 -1
  206. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_events.d.ts +136 -0
  207. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_events.js +154 -0
  208. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_events.js.map +1 -0
  209. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.d.ts +713 -141
  210. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.js +713 -141
  211. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.js.map +1 -1
  212. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index-incubating.d.ts +2 -0
  213. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index-incubating.js +2 -0
  214. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index-incubating.js.map +1 -1
  215. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index.d.ts +1 -0
  216. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index.js +1 -0
  217. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index.js.map +1 -1
  218. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.d.ts +7 -1
  219. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.js +7 -1
  220. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.js.map +1 -1
  221. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_events.d.ts +5 -0
  222. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_events.js +23 -0
  223. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_events.js.map +1 -0
  224. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.d.ts +1 -1
  225. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js +1 -1
  226. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js.map +1 -1
  227. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.d.ts +4350 -2882
  228. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.js +4354 -2883
  229. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.js.map +1 -1
  230. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_events.d.ts +136 -0
  231. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_events.js +157 -0
  232. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_events.js.map +1 -0
  233. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.d.ts +713 -141
  234. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js +720 -147
  235. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js.map +1 -1
  236. package/node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.d.ts +2 -0
  237. package/node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.js +2 -0
  238. package/node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.js.map +1 -1
  239. package/node_modules/@opentelemetry/semantic-conventions/build/src/index.d.ts +1 -0
  240. package/node_modules/@opentelemetry/semantic-conventions/build/src/index.js +1 -0
  241. package/node_modules/@opentelemetry/semantic-conventions/build/src/index.js.map +1 -1
  242. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.d.ts +7 -1
  243. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js +10 -4
  244. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js.map +1 -1
  245. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_events.d.ts +5 -0
  246. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_events.js +26 -0
  247. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_events.js.map +1 -0
  248. package/node_modules/@opentelemetry/semantic-conventions/build/src/version.d.ts +1 -1
  249. package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js +1 -1
  250. package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js.map +1 -1
  251. package/node_modules/@opentelemetry/semantic-conventions/package.json +6 -7
  252. package/node_modules/@swc/core/README.md +5 -0
  253. package/node_modules/@swc/core/binding.d.ts +2 -2
  254. package/node_modules/@swc/core/index.d.ts +5 -4
  255. package/node_modules/@swc/core/index.js +2 -2
  256. package/node_modules/@swc/core/package.json +12 -12
  257. package/node_modules/@swc/core-darwin-arm64/package.json +1 -1
  258. package/node_modules/@swc/core-darwin-arm64/swc.darwin-arm64.node +0 -0
  259. package/node_modules/@swc/core-darwin-x64/package.json +1 -1
  260. package/node_modules/@swc/core-darwin-x64/swc.darwin-x64.node +0 -0
  261. package/node_modules/@swc/core-linux-arm64-gnu/package.json +1 -1
  262. package/node_modules/@swc/core-linux-arm64-gnu/swc.linux-arm64-gnu.node +0 -0
  263. package/node_modules/@swc/core-linux-arm64-musl/package.json +1 -1
  264. package/node_modules/@swc/core-linux-arm64-musl/swc.linux-arm64-musl.node +0 -0
  265. package/node_modules/@swc/core-linux-x64-gnu/package.json +1 -1
  266. package/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node +0 -0
  267. package/node_modules/@swc/core-linux-x64-musl/package.json +1 -1
  268. package/node_modules/@swc/core-linux-x64-musl/swc.linux-x64-musl.node +0 -0
  269. package/node_modules/@swc/core-win32-arm64-msvc/package.json +1 -1
  270. package/node_modules/@swc/core-win32-arm64-msvc/swc.win32-arm64-msvc.node +0 -0
  271. package/node_modules/@swc/core-win32-x64-msvc/package.json +1 -1
  272. package/node_modules/@swc/core-win32-x64-msvc/swc.win32-x64-msvc.node +0 -0
  273. package/node_modules/@swc/types/index.d.ts +15 -5
  274. package/node_modules/@swc/types/package.json +2 -2
  275. package/node_modules/@types/node/README.md +1 -1
  276. package/node_modules/@types/node/buffer.d.ts +1 -1
  277. package/node_modules/@types/node/child_process.d.ts +26 -122
  278. package/node_modules/@types/node/crypto.d.ts +61 -11
  279. package/node_modules/@types/node/dns.d.ts +5 -0
  280. package/node_modules/@types/node/fs/promises.d.ts +48 -29
  281. package/node_modules/@types/node/fs.d.ts +52 -37
  282. package/node_modules/@types/node/globals.d.ts +148 -347
  283. package/node_modules/@types/node/http.d.ts +29 -5
  284. package/node_modules/@types/node/http2.d.ts +13 -11
  285. package/node_modules/@types/node/https.d.ts +5 -0
  286. package/node_modules/@types/node/index.d.ts +7 -2
  287. package/node_modules/@types/node/inspector.d.ts +187 -3985
  288. package/node_modules/@types/node/inspector.generated.d.ts +4052 -0
  289. package/node_modules/@types/node/module.d.ts +25 -0
  290. package/node_modules/@types/node/net.d.ts +21 -0
  291. package/node_modules/@types/node/package.json +4 -9
  292. package/node_modules/@types/node/perf_hooks.d.ts +14 -0
  293. package/node_modules/@types/node/repl.d.ts +11 -1
  294. package/node_modules/@types/node/sqlite.d.ts +34 -1
  295. package/node_modules/@types/node/stream/web.d.ts +4 -0
  296. package/node_modules/@types/node/stream.d.ts +17 -6
  297. package/node_modules/@types/node/test.d.ts +120 -1
  298. package/node_modules/@types/node/timers.d.ts +0 -2
  299. package/node_modules/@types/node/tls.d.ts +32 -0
  300. package/node_modules/@types/node/ts5.6/index.d.ts +7 -2
  301. package/node_modules/@types/node/ts5.7/index.d.ts +7 -2
  302. package/node_modules/@types/node/url.d.ts +20 -6
  303. package/node_modules/@types/node/util.d.ts +12 -6
  304. package/node_modules/@types/node/vm.d.ts +73 -10
  305. package/node_modules/@types/node/wasi.d.ts +21 -0
  306. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  307. package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  308. package/node_modules/@types/node/{dom-events.d.ts → web-globals/events.d.ts} +47 -52
  309. package/node_modules/@types/node/web-globals/fetch.d.ts +50 -0
  310. package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
  311. package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
  312. package/node_modules/@types/node/worker_threads.d.ts +63 -3
  313. package/node_modules/@types/node/zlib.d.ts +8 -2
  314. package/node_modules/axios/CHANGELOG.md +58 -0
  315. package/node_modules/axios/README.md +87 -10
  316. package/node_modules/axios/dist/axios.js +355 -289
  317. package/node_modules/axios/dist/axios.js.map +1 -1
  318. package/node_modules/axios/dist/axios.min.js +2 -2
  319. package/node_modules/axios/dist/axios.min.js.map +1 -1
  320. package/node_modules/axios/dist/browser/axios.cjs +286 -213
  321. package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
  322. package/node_modules/axios/dist/esm/axios.js +286 -213
  323. package/node_modules/axios/dist/esm/axios.js.map +1 -1
  324. package/node_modules/axios/dist/esm/axios.min.js +2 -2
  325. package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  326. package/node_modules/axios/dist/node/axios.cjs +377 -213
  327. package/node_modules/axios/dist/node/axios.cjs.map +1 -1
  328. package/node_modules/axios/index.d.cts +12 -5
  329. package/node_modules/axios/index.d.ts +13 -4
  330. package/node_modules/axios/lib/adapters/adapters.js +6 -4
  331. package/node_modules/axios/lib/adapters/fetch.js +221 -162
  332. package/node_modules/axios/lib/adapters/http.js +18 -0
  333. package/node_modules/axios/lib/adapters/xhr.js +11 -8
  334. package/node_modules/axios/lib/core/Axios.js +0 -2
  335. package/node_modules/axios/lib/core/AxiosError.js +10 -3
  336. package/node_modules/axios/lib/core/dispatchRequest.js +1 -1
  337. package/node_modules/axios/lib/defaults/index.js +1 -1
  338. package/node_modules/axios/lib/env/data.js +1 -1
  339. package/node_modules/axios/lib/helpers/buildURL.js +1 -3
  340. package/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +73 -0
  341. package/node_modules/axios/lib/helpers/resolveConfig.js +13 -9
  342. package/node_modules/axios/lib/utils.js +5 -3
  343. package/node_modules/axios/package.json +18 -12
  344. package/node_modules/balanced-match/.github/FUNDING.yml +2 -0
  345. package/node_modules/balanced-match/LICENSE.md +21 -0
  346. package/node_modules/balanced-match/README.md +97 -0
  347. package/node_modules/balanced-match/index.js +62 -0
  348. package/node_modules/balanced-match/package.json +48 -0
  349. package/node_modules/brace-expansion/.github/FUNDING.yml +2 -0
  350. package/node_modules/brace-expansion/LICENSE +21 -0
  351. package/node_modules/brace-expansion/README.md +135 -0
  352. package/node_modules/brace-expansion/index.js +203 -0
  353. package/node_modules/brace-expansion/package.json +49 -0
  354. package/node_modules/detect-libc/lib/detect-libc.js +59 -13
  355. package/node_modules/detect-libc/lib/elf.js +39 -0
  356. package/node_modules/detect-libc/lib/filesystem.js +18 -8
  357. package/node_modules/detect-libc/package.json +3 -2
  358. package/node_modules/minimatch/LICENSE +15 -0
  359. package/node_modules/minimatch/README.md +454 -0
  360. package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts +2 -0
  361. package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts.map +1 -0
  362. package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
  363. package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js.map +1 -0
  364. package/node_modules/minimatch/dist/commonjs/ast.d.ts +20 -0
  365. package/node_modules/minimatch/dist/commonjs/ast.d.ts.map +1 -0
  366. package/node_modules/minimatch/dist/commonjs/ast.js +592 -0
  367. package/node_modules/minimatch/dist/commonjs/ast.js.map +1 -0
  368. package/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts +8 -0
  369. package/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts.map +1 -0
  370. package/node_modules/minimatch/dist/commonjs/brace-expressions.js +152 -0
  371. package/node_modules/minimatch/dist/commonjs/brace-expressions.js.map +1 -0
  372. package/node_modules/minimatch/dist/commonjs/escape.d.ts +12 -0
  373. package/node_modules/minimatch/dist/commonjs/escape.d.ts.map +1 -0
  374. package/node_modules/minimatch/dist/commonjs/escape.js +22 -0
  375. package/node_modules/minimatch/dist/commonjs/escape.js.map +1 -0
  376. package/node_modules/minimatch/dist/commonjs/index.d.ts +94 -0
  377. package/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -0
  378. package/node_modules/minimatch/dist/commonjs/index.js +1017 -0
  379. package/node_modules/minimatch/dist/commonjs/index.js.map +1 -0
  380. package/node_modules/minimatch/dist/commonjs/package.json +3 -0
  381. package/node_modules/minimatch/dist/commonjs/unescape.d.ts +17 -0
  382. package/node_modules/minimatch/dist/commonjs/unescape.d.ts.map +1 -0
  383. package/node_modules/minimatch/dist/commonjs/unescape.js +24 -0
  384. package/node_modules/minimatch/dist/commonjs/unescape.js.map +1 -0
  385. package/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts +2 -0
  386. package/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts.map +1 -0
  387. package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
  388. package/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -0
  389. package/node_modules/minimatch/dist/esm/ast.d.ts +20 -0
  390. package/node_modules/minimatch/dist/esm/ast.d.ts.map +1 -0
  391. package/node_modules/minimatch/dist/esm/ast.js +588 -0
  392. package/node_modules/minimatch/dist/esm/ast.js.map +1 -0
  393. package/node_modules/minimatch/dist/esm/brace-expressions.d.ts +8 -0
  394. package/node_modules/minimatch/dist/esm/brace-expressions.d.ts.map +1 -0
  395. package/node_modules/minimatch/dist/esm/brace-expressions.js +148 -0
  396. package/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -0
  397. package/node_modules/minimatch/dist/esm/escape.d.ts +12 -0
  398. package/node_modules/minimatch/dist/esm/escape.d.ts.map +1 -0
  399. package/node_modules/minimatch/dist/esm/escape.js +18 -0
  400. package/node_modules/minimatch/dist/esm/escape.js.map +1 -0
  401. package/node_modules/minimatch/dist/esm/index.d.ts +94 -0
  402. package/node_modules/minimatch/dist/esm/index.d.ts.map +1 -0
  403. package/node_modules/minimatch/dist/esm/index.js +1001 -0
  404. package/node_modules/minimatch/dist/esm/index.js.map +1 -0
  405. package/node_modules/minimatch/dist/esm/package.json +3 -0
  406. package/node_modules/minimatch/dist/esm/unescape.d.ts +17 -0
  407. package/node_modules/minimatch/dist/esm/unescape.d.ts.map +1 -0
  408. package/node_modules/minimatch/dist/esm/unescape.js +20 -0
  409. package/node_modules/minimatch/dist/esm/unescape.js.map +1 -0
  410. package/node_modules/minimatch/package.json +82 -0
  411. package/node_modules/node-abi/LICENSE +21 -0
  412. package/node_modules/node-abi/README.md +54 -0
  413. package/node_modules/node-abi/abi_registry.json +408 -0
  414. package/node_modules/node-abi/getNextTarget.js +13 -0
  415. package/node_modules/node-abi/index.js +161 -0
  416. package/node_modules/node-abi/package.json +46 -0
  417. package/node_modules/node-addon-api/README.md +25 -249
  418. package/node_modules/node-addon-api/common.gypi +1 -0
  419. package/node_modules/node-addon-api/index.js +2 -0
  420. package/node_modules/node-addon-api/napi-inl.h +592 -166
  421. package/node_modules/node-addon-api/napi.h +167 -59
  422. package/node_modules/node-addon-api/node_addon_api.gyp +10 -0
  423. package/node_modules/node-addon-api/noexcept.gypi +1 -1
  424. package/node_modules/node-addon-api/package.json +13 -13
  425. package/node_modules/node-addon-api/tools/conversion.js +1 -1
  426. package/node_modules/protobufjs/dist/light/protobuf.js +2 -2
  427. package/node_modules/protobufjs/dist/light/protobuf.min.js +2 -2
  428. package/node_modules/protobufjs/dist/minimal/protobuf.js +2 -2
  429. package/node_modules/protobufjs/dist/minimal/protobuf.min.js +2 -2
  430. package/node_modules/protobufjs/dist/protobuf.js +2 -2
  431. package/node_modules/protobufjs/dist/protobuf.min.js +2 -2
  432. package/node_modules/protobufjs/google/protobuf/descriptor.json +2 -2
  433. package/node_modules/protobufjs/google/protobuf/descriptor.proto +2 -1
  434. package/node_modules/protobufjs/package.json +1 -1
  435. package/node_modules/undici-types/agent.d.ts +4 -0
  436. package/node_modules/undici-types/client-stats.d.ts +15 -0
  437. package/node_modules/undici-types/client.d.ts +6 -3
  438. package/node_modules/undici-types/diagnostics-channel.d.ts +9 -0
  439. package/node_modules/undici-types/dispatcher.d.ts +3 -2
  440. package/node_modules/undici-types/env-http-proxy-agent.d.ts +2 -1
  441. package/node_modules/undici-types/eventsource.d.ts +3 -3
  442. package/node_modules/undici-types/fetch.d.ts +1 -0
  443. package/node_modules/undici-types/handlers.d.ts +1 -1
  444. package/node_modules/undici-types/mock-agent.d.ts +3 -0
  445. package/node_modules/undici-types/mock-client.d.ts +2 -0
  446. package/node_modules/undici-types/mock-interceptor.d.ts +2 -0
  447. package/node_modules/undici-types/mock-pool.d.ts +2 -0
  448. package/node_modules/undici-types/package.json +1 -1
  449. package/node_modules/undici-types/pool.d.ts +2 -0
  450. package/node_modules/undici-types/proxy-agent.d.ts +1 -0
  451. package/node_modules/undici-types/retry-handler.d.ts +9 -0
  452. package/node_modules/undici-types/webidl.d.ts +29 -15
  453. package/node_modules/undici-types/websocket.d.ts +3 -1
  454. package/node_modules/yaml/README.md +2 -20
  455. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +1 -1
  456. package/node_modules/yaml/dist/stringify/stringifyString.js +1 -1
  457. package/node_modules/yaml/package.json +2 -1
  458. package/package.json +4 -3
  459. package/node_modules/@contrast/code-events/prebuilds/linux-arm64/@contrast+code-events.abi93.armv8.node +0 -0
  460. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi93.glibc.node +0 -0
  461. package/node_modules/@contrast/code-events/prebuilds/linux-x64/@contrast+code-events.abi93.musl.node +0 -0
  462. package/node_modules/@contrast/code-events/prebuilds/win32-x64/@contrast+code-events.abi93.node +0 -0
  463. package/node_modules/@contrast/core/lib/sensitive-data-masking/protect-listener.js +0 -111
  464. package/node_modules/@contrast/distringuish/prebuilds/linux-arm64/@contrast+distringuish.abi93.armv8.node +0 -0
  465. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi93.glibc.node +0 -0
  466. package/node_modules/@contrast/distringuish/prebuilds/linux-x64/@contrast+distringuish.abi93.musl.node +0 -0
  467. package/node_modules/@contrast/distringuish/prebuilds/win32-x64/@contrast+distringuish.abi93.node +0 -0
  468. package/node_modules/@contrast/fn-inspect/prebuilds/linux-arm64/@contrast+fn-inspect.abi93.armv8.node +0 -0
  469. package/node_modules/@contrast/fn-inspect/prebuilds/linux-x64/@contrast+fn-inspect.abi93.glibc.node +0 -0
  470. package/node_modules/@contrast/fn-inspect/prebuilds/win32-x64/@contrast+fn-inspect.abi93.node +0 -0
  471. package/node_modules/@contrast/perf/lib/index.test.js +0 -547
  472. package/node_modules/@contrast/perf/lib/tsconfig.json +0 -31
  473. package/node_modules/@contrast/protect/lib/input-tracing/install/spdy.js +0 -63
  474. package/node_modules/@contrast/reporter/node_modules/sonic-boom/.taprc.yaml +0 -11
  475. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/destroy.test.js +0 -49
  476. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/end.test.js +0 -98
  477. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/flush-sync.test.js +0 -140
  478. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/flush.test.js +0 -419
  479. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/fsync.test.js +0 -63
  480. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/helper.js +0 -42
  481. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/minlength.test.js +0 -35
  482. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/mode.test.js +0 -116
  483. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/reopen.test.js +0 -239
  484. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/retry.test.js +0 -414
  485. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/sync.test.js +0 -261
  486. package/node_modules/@contrast/reporter/node_modules/sonic-boom/test/write.test.js +0 -465
  487. package/node_modules/@types/node/ts5.1/compatibility/disposable.d.ts +0 -12
  488. package/node_modules/@types/node/ts5.1/index.d.ts +0 -98
  489. package/node_modules/node-addon-api/tools/eslint-format.js +0 -79
@@ -0,0 +1,1684 @@
1
+ 'use strict'
2
+
3
+ const { test, teardown } = require('tap')
4
+ const { join } = require('path')
5
+ const { fork } = require('child_process')
6
+ const fs = require('fs')
7
+ const os = require('os')
8
+ const path = require('path')
9
+ const proxyquire = require('proxyquire')
10
+ const SonicBoom = require('.')
11
+
12
+ const isWindows = process.platform === 'win32'
13
+
14
+ const MAX_WRITE = 16 * 1024
15
+ const files = []
16
+ let count = 0
17
+
18
+ function file () {
19
+ const file = path.join(os.tmpdir(), `sonic-boom-${process.pid}-${process.hrtime().toString()}-${count++}`)
20
+ files.push(file)
21
+ return file
22
+ }
23
+
24
+ teardown(() => {
25
+ const rmSync = fs.rmSync || fs.rmdirSync
26
+ files.forEach((file) => {
27
+ try {
28
+ if (fs.existsSync(file)) {
29
+ fs.statSync(file).isDirectory() ? rmSync(file, { recursive: true, maxRetries: 10 }) : fs.unlinkSync(file)
30
+ }
31
+ } catch (e) {
32
+ console.log(e)
33
+ }
34
+ })
35
+ })
36
+
37
+ test('sync false', (t) => {
38
+ buildTests(t.test, false)
39
+ t.end()
40
+ })
41
+
42
+ test('sync true', (t) => {
43
+ buildTests(t.test, true)
44
+ t.end()
45
+ })
46
+
47
+ function buildTests (test, sync) {
48
+ // Reset the umask for testing
49
+ process.umask(0o000)
50
+
51
+ test('write things to a file descriptor', (t) => {
52
+ t.plan(6)
53
+
54
+ const dest = file()
55
+ const fd = fs.openSync(dest, 'w')
56
+ const stream = new SonicBoom({ fd, sync })
57
+
58
+ stream.on('ready', () => {
59
+ t.pass('ready emitted')
60
+ })
61
+
62
+ t.ok(stream.write('hello world\n'))
63
+ t.ok(stream.write('something else\n'))
64
+
65
+ stream.end()
66
+
67
+ stream.on('finish', () => {
68
+ fs.readFile(dest, 'utf8', (err, data) => {
69
+ t.error(err)
70
+ t.equal(data, 'hello world\nsomething else\n')
71
+ })
72
+ })
73
+ stream.on('close', () => {
74
+ t.pass('close emitted')
75
+ })
76
+ })
77
+
78
+ test('write things in a streaming fashion', (t) => {
79
+ t.plan(8)
80
+
81
+ const dest = file()
82
+ const fd = fs.openSync(dest, 'w')
83
+ const stream = new SonicBoom({ fd, sync })
84
+
85
+ stream.once('drain', () => {
86
+ fs.readFile(dest, 'utf8', (err, data) => {
87
+ t.error(err)
88
+ t.equal(data, 'hello world\n')
89
+ t.ok(stream.write('something else\n'))
90
+ })
91
+
92
+ stream.once('drain', () => {
93
+ fs.readFile(dest, 'utf8', (err, data) => {
94
+ t.error(err)
95
+ t.equal(data, 'hello world\nsomething else\n')
96
+ stream.end()
97
+ })
98
+ })
99
+ })
100
+
101
+ t.ok(stream.write('hello world\n'))
102
+
103
+ stream.on('finish', () => {
104
+ t.pass('finish emitted')
105
+ })
106
+ stream.on('close', () => {
107
+ t.pass('close emitted')
108
+ })
109
+ })
110
+
111
+ test('can be piped into', (t) => {
112
+ t.plan(4)
113
+
114
+ const dest = file()
115
+ const fd = fs.openSync(dest, 'w')
116
+ const stream = new SonicBoom({ fd, sync })
117
+ const source = fs.createReadStream(__filename)
118
+
119
+ source.pipe(stream)
120
+
121
+ stream.on('finish', () => {
122
+ fs.readFile(__filename, 'utf8', (err, expected) => {
123
+ t.error(err)
124
+ fs.readFile(dest, 'utf8', (err, data) => {
125
+ t.error(err)
126
+ t.equal(data, expected)
127
+ })
128
+ })
129
+ })
130
+ stream.on('close', () => {
131
+ t.pass('close emitted')
132
+ })
133
+ })
134
+
135
+ test('write things to a file', (t) => {
136
+ t.plan(6)
137
+
138
+ const dest = file()
139
+ const stream = new SonicBoom({ dest, sync })
140
+
141
+ stream.on('ready', () => {
142
+ t.pass('ready emitted')
143
+ })
144
+
145
+ t.ok(stream.write('hello world\n'))
146
+ t.ok(stream.write('something else\n'))
147
+
148
+ stream.end()
149
+
150
+ stream.on('finish', () => {
151
+ fs.readFile(dest, 'utf8', (err, data) => {
152
+ t.error(err)
153
+ t.equal(data, 'hello world\nsomething else\n')
154
+ })
155
+ })
156
+ stream.on('close', () => {
157
+ t.pass('close emitted')
158
+ })
159
+ })
160
+
161
+ test('flushSync', (t) => {
162
+ t.plan(4)
163
+
164
+ const dest = file()
165
+ const fd = fs.openSync(dest, 'w')
166
+ const stream = new SonicBoom({ fd, minLength: 4096, sync })
167
+
168
+ t.ok(stream.write('hello world\n'))
169
+ t.ok(stream.write('something else\n'))
170
+
171
+ stream.flushSync()
172
+
173
+ // let the file system settle down things
174
+ setImmediate(function () {
175
+ stream.end()
176
+ const data = fs.readFileSync(dest, 'utf8')
177
+ t.equal(data, 'hello world\nsomething else\n')
178
+
179
+ stream.on('close', () => {
180
+ t.pass('close emitted')
181
+ })
182
+ })
183
+ })
184
+
185
+ test('destroy', (t) => {
186
+ t.plan(5)
187
+
188
+ const dest = file()
189
+ const fd = fs.openSync(dest, 'w')
190
+ const stream = new SonicBoom({ fd, sync })
191
+
192
+ t.ok(stream.write('hello world\n'))
193
+ stream.destroy()
194
+ t.throws(() => { stream.write('hello world\n') })
195
+
196
+ fs.readFile(dest, 'utf8', function (err, data) {
197
+ t.error(err)
198
+ t.equal(data, 'hello world\n')
199
+ })
200
+
201
+ stream.on('finish', () => {
202
+ t.fail('finish emitted')
203
+ })
204
+
205
+ stream.on('close', () => {
206
+ t.pass('close emitted')
207
+ })
208
+ })
209
+
210
+ test('destroy while opening', (t) => {
211
+ t.plan(1)
212
+
213
+ const dest = file()
214
+ const stream = new SonicBoom({ dest })
215
+
216
+ stream.destroy()
217
+ stream.on('close', () => {
218
+ t.pass('close emitted')
219
+ })
220
+ })
221
+
222
+ test('minLength', (t) => {
223
+ t.plan(8)
224
+
225
+ const dest = file()
226
+ const stream = new SonicBoom({ dest, minLength: 4096, sync })
227
+
228
+ stream.on('ready', () => {
229
+ t.pass('ready emitted')
230
+ })
231
+
232
+ t.ok(stream.write('hello world\n'))
233
+ t.ok(stream.write('something else\n'))
234
+
235
+ const fail = t.fail
236
+ stream.on('drain', fail)
237
+
238
+ // bad use of timer
239
+ // TODO refactor
240
+ setTimeout(function () {
241
+ fs.readFile(dest, 'utf8', (err, data) => {
242
+ t.error(err)
243
+ t.equal(data, '')
244
+
245
+ stream.end()
246
+
247
+ stream.on('finish', () => {
248
+ fs.readFile(dest, 'utf8', (err, data) => {
249
+ t.error(err)
250
+ t.equal(data, 'hello world\nsomething else\n')
251
+ })
252
+ })
253
+ })
254
+ }, 100)
255
+
256
+ stream.on('close', () => {
257
+ t.pass('close emitted')
258
+ })
259
+ })
260
+
261
+ test('append', (t) => {
262
+ t.plan(4)
263
+
264
+ const dest = file()
265
+ fs.writeFileSync(dest, 'hello world\n')
266
+ const stream = new SonicBoom({ dest, append: false, sync })
267
+
268
+ stream.on('ready', () => {
269
+ t.pass('ready emitted')
270
+ })
271
+
272
+ t.ok(stream.write('something else\n'))
273
+
274
+ stream.flush()
275
+
276
+ stream.on('drain', () => {
277
+ fs.readFile(dest, 'utf8', (err, data) => {
278
+ t.error(err)
279
+ t.equal(data, 'something else\n')
280
+ stream.end()
281
+ })
282
+ })
283
+ })
284
+
285
+ test('mkdir', (t) => {
286
+ t.plan(4)
287
+
288
+ const dest = path.join(file(), 'out.log')
289
+ const stream = new SonicBoom({ dest, mkdir: true, sync })
290
+
291
+ stream.on('ready', () => {
292
+ t.pass('ready emitted')
293
+ })
294
+
295
+ t.ok(stream.write('hello world\n'))
296
+
297
+ stream.flush()
298
+
299
+ stream.on('drain', () => {
300
+ fs.readFile(dest, 'utf8', (err, data) => {
301
+ t.error(err)
302
+ t.equal(data, 'hello world\n')
303
+ stream.end()
304
+ })
305
+ })
306
+ })
307
+
308
+ test('flush', (t) => {
309
+ t.plan(5)
310
+
311
+ const dest = file()
312
+ const fd = fs.openSync(dest, 'w')
313
+ const stream = new SonicBoom({ fd, minLength: 4096, sync })
314
+
315
+ stream.on('ready', () => {
316
+ t.pass('ready emitted')
317
+ })
318
+
319
+ t.ok(stream.write('hello world\n'))
320
+ t.ok(stream.write('something else\n'))
321
+
322
+ stream.flush()
323
+
324
+ stream.on('drain', () => {
325
+ fs.readFile(dest, 'utf8', (err, data) => {
326
+ t.error(err)
327
+ t.equal(data, 'hello world\nsomething else\n')
328
+ stream.end()
329
+ })
330
+ })
331
+ })
332
+
333
+ test('flush with no data', (t) => {
334
+ t.plan(2)
335
+
336
+ const dest = file()
337
+ const fd = fs.openSync(dest, 'w')
338
+ const stream = new SonicBoom({ fd, minLength: 4096, sync })
339
+
340
+ stream.on('ready', () => {
341
+ t.pass('ready emitted')
342
+ })
343
+
344
+ stream.flush()
345
+
346
+ stream.on('drain', () => {
347
+ t.pass('drain emitted')
348
+ })
349
+ })
350
+
351
+ test('reopen', (t) => {
352
+ t.plan(9)
353
+
354
+ const dest = file()
355
+ const stream = new SonicBoom({ dest, sync })
356
+
357
+ t.ok(stream.write('hello world\n'))
358
+ t.ok(stream.write('something else\n'))
359
+
360
+ const after = dest + '-moved'
361
+
362
+ stream.once('drain', () => {
363
+ t.pass('drain emitted')
364
+
365
+ fs.renameSync(dest, after)
366
+ stream.reopen()
367
+
368
+ stream.once('ready', () => {
369
+ t.pass('ready emitted')
370
+ t.ok(stream.write('after reopen\n'))
371
+
372
+ stream.on('drain', () => {
373
+ fs.readFile(after, 'utf8', (err, data) => {
374
+ t.error(err)
375
+ t.equal(data, 'hello world\nsomething else\n')
376
+ fs.readFile(dest, 'utf8', (err, data) => {
377
+ t.error(err)
378
+ t.equal(data, 'after reopen\n')
379
+ stream.end()
380
+ })
381
+ })
382
+ })
383
+ })
384
+ })
385
+ })
386
+
387
+ test('reopen with buffer', (t) => {
388
+ t.plan(9)
389
+
390
+ const dest = file()
391
+ const stream = new SonicBoom({ dest, minLength: 4096, sync })
392
+
393
+ t.ok(stream.write('hello world\n'))
394
+ t.ok(stream.write('something else\n'))
395
+
396
+ const after = dest + '-moved'
397
+
398
+ stream.once('ready', () => {
399
+ t.pass('drain emitted')
400
+
401
+ stream.flush()
402
+ fs.renameSync(dest, after)
403
+ stream.reopen()
404
+
405
+ stream.once('ready', () => {
406
+ t.pass('ready emitted')
407
+ t.ok(stream.write('after reopen\n'))
408
+ stream.flush()
409
+
410
+ stream.on('drain', () => {
411
+ fs.readFile(after, 'utf8', (err, data) => {
412
+ t.error(err)
413
+ t.equal(data, 'hello world\nsomething else\n')
414
+ fs.readFile(dest, 'utf8', (err, data) => {
415
+ t.error(err)
416
+ t.equal(data, 'after reopen\n')
417
+ stream.end()
418
+ })
419
+ })
420
+ })
421
+ })
422
+ })
423
+ })
424
+
425
+ test('reopen if not open', (t) => {
426
+ t.plan(3)
427
+
428
+ const dest = file()
429
+ const stream = new SonicBoom({ dest, sync })
430
+
431
+ t.ok(stream.write('hello world\n'))
432
+ t.ok(stream.write('something else\n'))
433
+
434
+ stream.reopen()
435
+
436
+ stream.end()
437
+ stream.on('close', function () {
438
+ t.pass('ended')
439
+ })
440
+ })
441
+
442
+ test('end after reopen', (t) => {
443
+ t.plan(4)
444
+
445
+ const dest = file()
446
+ const stream = new SonicBoom({ dest, minLength: 4096, sync })
447
+
448
+ stream.once('ready', () => {
449
+ t.pass('ready emitted')
450
+ const after = dest + '-moved'
451
+ stream.reopen(after)
452
+ stream.write('after reopen\n')
453
+ stream.on('finish', () => {
454
+ t.pass('finish emitted')
455
+ fs.readFile(after, 'utf8', (err, data) => {
456
+ t.error(err)
457
+ t.equal(data, 'after reopen\n')
458
+ })
459
+ })
460
+ stream.end()
461
+ })
462
+ })
463
+
464
+ test('end after 2x reopen', (t) => {
465
+ t.plan(4)
466
+
467
+ const dest = file()
468
+ const stream = new SonicBoom({ dest, minLength: 4096, sync })
469
+
470
+ stream.once('ready', () => {
471
+ t.pass('ready emitted')
472
+ stream.reopen(dest + '-moved')
473
+ const after = dest + '-moved-moved'
474
+ stream.reopen(after)
475
+ stream.write('after reopen\n')
476
+ stream.on('finish', () => {
477
+ t.pass('finish emitted')
478
+ fs.readFile(after, 'utf8', (err, data) => {
479
+ t.error(err)
480
+ t.equal(data, 'after reopen\n')
481
+ })
482
+ })
483
+ stream.end()
484
+ })
485
+ })
486
+
487
+ test('end if not ready', (t) => {
488
+ t.plan(3)
489
+
490
+ const dest = file()
491
+ const stream = new SonicBoom({ dest, minLength: 4096, sync })
492
+ const after = dest + '-moved'
493
+ stream.reopen(after)
494
+ stream.write('after reopen\n')
495
+ stream.on('finish', () => {
496
+ t.pass('finish emitted')
497
+ fs.readFile(after, 'utf8', (err, data) => {
498
+ t.error(err)
499
+ t.equal(data, 'after reopen\n')
500
+ })
501
+ })
502
+ stream.end()
503
+ })
504
+
505
+ test('reopen with file', (t) => {
506
+ t.plan(9)
507
+
508
+ const dest = file()
509
+ const stream = new SonicBoom({ dest, minLength: 0, sync })
510
+
511
+ t.ok(stream.write('hello world\n'))
512
+ t.ok(stream.write('something else\n'))
513
+
514
+ const after = dest + '-new'
515
+
516
+ stream.once('drain', () => {
517
+ t.pass('drain emitted')
518
+
519
+ stream.reopen(after)
520
+
521
+ stream.once('ready', () => {
522
+ t.pass('ready emitted')
523
+ t.ok(stream.write('after reopen\n'))
524
+
525
+ stream.on('drain', () => {
526
+ fs.readFile(dest, 'utf8', (err, data) => {
527
+ t.error(err)
528
+ t.equal(data, 'hello world\nsomething else\n')
529
+ fs.readFile(after, 'utf8', (err, data) => {
530
+ t.error(err)
531
+ t.equal(data, 'after reopen\n')
532
+ stream.end()
533
+ })
534
+ })
535
+ })
536
+ })
537
+ })
538
+ })
539
+
540
+ test('chunk data accordingly', (t) => {
541
+ t.plan(2)
542
+
543
+ const child = fork(join(__dirname, 'fixtures', 'firehose.js'), { silent: true })
544
+ const str = Buffer.alloc(10000).fill('a').toString()
545
+
546
+ let data = ''
547
+
548
+ child.stdout.on('data', function (chunk) {
549
+ data += chunk.toString()
550
+ })
551
+
552
+ child.stdout.on('end', function () {
553
+ t.equal(data, str)
554
+ })
555
+
556
+ child.on('close', function (code) {
557
+ t.equal(code, 0)
558
+ })
559
+ })
560
+
561
+ test('write later on recoverable error', (t) => {
562
+ t.plan(8)
563
+
564
+ const fakeFs = Object.create(fs)
565
+ const SonicBoom = proxyquire('.', {
566
+ fs: fakeFs
567
+ })
568
+
569
+ const dest = file()
570
+ const fd = fs.openSync(dest, 'w')
571
+ const stream = new SonicBoom({ fd, minLength: 0, sync })
572
+
573
+ stream.on('ready', () => {
574
+ t.pass('ready emitted')
575
+ })
576
+ stream.on('error', () => {
577
+ t.pass('error emitted')
578
+ })
579
+
580
+ if (sync) {
581
+ fakeFs.writeSync = function (fd, buf, enc) {
582
+ t.pass('fake fs.writeSync called')
583
+ throw new Error('recoverable error')
584
+ }
585
+ } else {
586
+ fakeFs.write = function (fd, buf, enc, cb) {
587
+ t.pass('fake fs.write called')
588
+ setTimeout(() => cb(new Error('recoverable error')), 0)
589
+ }
590
+ }
591
+
592
+ t.ok(stream.write('hello world\n'))
593
+
594
+ setTimeout(() => {
595
+ if (sync) {
596
+ fakeFs.writeSync = fs.writeSync
597
+ } else {
598
+ fakeFs.write = fs.write
599
+ }
600
+
601
+ t.ok(stream.write('something else\n'))
602
+
603
+ stream.end()
604
+ stream.on('finish', () => {
605
+ fs.readFile(dest, 'utf8', (err, data) => {
606
+ t.error(err)
607
+ t.equal(data, 'hello world\nsomething else\n')
608
+ })
609
+ })
610
+ stream.on('close', () => {
611
+ t.pass('close emitted')
612
+ })
613
+ }, 0)
614
+ })
615
+
616
+ test('reopen throws an error', (t) => {
617
+ t.plan(sync ? 10 : 9)
618
+
619
+ const fakeFs = Object.create(fs)
620
+ const SonicBoom = proxyquire('.', {
621
+ fs: fakeFs
622
+ })
623
+
624
+ const dest = file()
625
+ const stream = new SonicBoom({ dest, sync })
626
+
627
+ t.ok(stream.write('hello world\n'))
628
+ t.ok(stream.write('something else\n'))
629
+
630
+ const after = dest + '-moved'
631
+
632
+ stream.on('error', () => {
633
+ t.pass('error emitted')
634
+ })
635
+
636
+ stream.once('drain', () => {
637
+ t.pass('drain emitted')
638
+
639
+ fs.renameSync(dest, after)
640
+ if (sync) {
641
+ fakeFs.openSync = function (file, flags) {
642
+ t.pass('fake fs.openSync called')
643
+ throw new Error('open error')
644
+ }
645
+ } else {
646
+ fakeFs.open = function (file, flags, mode, cb) {
647
+ t.pass('fake fs.open called')
648
+ setTimeout(() => cb(new Error('open error')), 0)
649
+ }
650
+ }
651
+
652
+ if (sync) {
653
+ try {
654
+ stream.reopen()
655
+ } catch (err) {
656
+ t.pass('reopen throwed')
657
+ }
658
+ } else {
659
+ stream.reopen()
660
+ }
661
+
662
+ setTimeout(() => {
663
+ t.ok(stream.write('after reopen\n'))
664
+
665
+ stream.end()
666
+ stream.on('finish', () => {
667
+ fs.readFile(after, 'utf8', (err, data) => {
668
+ t.error(err)
669
+ t.equal(data, 'hello world\nsomething else\nafter reopen\n')
670
+ })
671
+ })
672
+ stream.on('close', () => {
673
+ t.pass('close emitted')
674
+ })
675
+ }, 0)
676
+ })
677
+ })
678
+
679
+ test('mode', { skip: isWindows }, (t) => {
680
+ t.plan(6)
681
+
682
+ const dest = file()
683
+ const mode = 0o666
684
+ const stream = new SonicBoom({ dest, sync, mode })
685
+
686
+ stream.on('ready', () => {
687
+ t.pass('ready emitted')
688
+ })
689
+
690
+ t.ok(stream.write('hello world\n'))
691
+ t.ok(stream.write('something else\n'))
692
+
693
+ stream.end()
694
+
695
+ stream.on('finish', () => {
696
+ fs.readFile(dest, 'utf8', (err, data) => {
697
+ t.error(err)
698
+ t.equal(data, 'hello world\nsomething else\n')
699
+ t.equal(fs.statSync(dest).mode & 0o777, stream.mode)
700
+ })
701
+ })
702
+ })
703
+
704
+ test('mode default', { skip: isWindows }, (t) => {
705
+ t.plan(6)
706
+
707
+ const dest = file()
708
+ const defaultMode = 0o666
709
+ const stream = new SonicBoom({ dest, sync })
710
+
711
+ stream.on('ready', () => {
712
+ t.pass('ready emitted')
713
+ })
714
+
715
+ t.ok(stream.write('hello world\n'))
716
+ t.ok(stream.write('something else\n'))
717
+
718
+ stream.end()
719
+
720
+ stream.on('finish', () => {
721
+ fs.readFile(dest, 'utf8', (err, data) => {
722
+ t.error(err)
723
+ t.equal(data, 'hello world\nsomething else\n')
724
+ t.equal(fs.statSync(dest).mode & 0o777, defaultMode)
725
+ })
726
+ })
727
+ })
728
+
729
+ test('mode on mkdir', { skip: isWindows }, (t) => {
730
+ t.plan(5)
731
+
732
+ const dest = path.join(file(), 'out.log')
733
+ const mode = 0o666
734
+ const stream = new SonicBoom({ dest, mkdir: true, mode, sync })
735
+
736
+ stream.on('ready', () => {
737
+ t.pass('ready emitted')
738
+ })
739
+
740
+ t.ok(stream.write('hello world\n'))
741
+
742
+ stream.flush()
743
+
744
+ stream.on('drain', () => {
745
+ fs.readFile(dest, 'utf8', (err, data) => {
746
+ t.error(err)
747
+ t.equal(data, 'hello world\n')
748
+ t.equal(fs.statSync(dest).mode & 0o777, stream.mode)
749
+ stream.end()
750
+ })
751
+ })
752
+ })
753
+
754
+ test('mode on append', { skip: isWindows }, (t) => {
755
+ t.plan(5)
756
+
757
+ const dest = file()
758
+ fs.writeFileSync(dest, 'hello world\n', 'utf8', 0o422)
759
+ const mode = isWindows ? 0o444 : 0o666
760
+ const stream = new SonicBoom({ dest, append: false, mode, sync })
761
+
762
+ stream.on('ready', () => {
763
+ t.pass('ready emitted')
764
+ })
765
+
766
+ t.ok(stream.write('something else\n'))
767
+
768
+ stream.flush()
769
+
770
+ stream.on('drain', () => {
771
+ fs.readFile(dest, 'utf8', (err, data) => {
772
+ t.error(err)
773
+ t.equal(data, 'something else\n')
774
+ t.equal(fs.statSync(dest).mode & 0o777, stream.mode)
775
+ stream.end()
776
+ })
777
+ })
778
+ })
779
+
780
+ test('emit write events', (t) => {
781
+ t.plan(7)
782
+
783
+ const dest = file()
784
+ const stream = new SonicBoom({ dest, sync })
785
+
786
+ stream.on('ready', () => {
787
+ t.pass('ready emitted')
788
+ })
789
+
790
+ let length = 0
791
+ stream.on('write', (bytes) => {
792
+ length += bytes
793
+ })
794
+
795
+ t.ok(stream.write('hello world\n'))
796
+ t.ok(stream.write('something else\n'))
797
+
798
+ stream.end()
799
+
800
+ stream.on('finish', () => {
801
+ fs.readFile(dest, 'utf8', (err, data) => {
802
+ t.error(err)
803
+ t.equal(data, 'hello world\nsomething else\n')
804
+ t.equal(length, 27)
805
+ })
806
+ })
807
+ stream.on('close', () => {
808
+ t.pass('close emitted')
809
+ })
810
+ })
811
+ }
812
+
813
+ test('drain deadlock', (t) => {
814
+ t.plan(4)
815
+
816
+ const dest = file()
817
+ const stream = new SonicBoom({ dest, sync: false, minLength: 9999 })
818
+
819
+ t.ok(stream.write(Buffer.alloc(1500).fill('x').toString()))
820
+ t.ok(stream.write(Buffer.alloc(1500).fill('x').toString()))
821
+ t.ok(!stream.write(Buffer.alloc(MAX_WRITE).fill('x').toString()))
822
+ stream.on('drain', () => {
823
+ t.pass()
824
+ })
825
+ })
826
+
827
+ test('retry on EAGAIN', (t) => {
828
+ t.plan(7)
829
+
830
+ const fakeFs = Object.create(fs)
831
+ fakeFs.write = function (fd, buf, enc, cb) {
832
+ t.pass('fake fs.write called')
833
+ fakeFs.write = fs.write
834
+ const err = new Error('EAGAIN')
835
+ err.code = 'EAGAIN'
836
+ process.nextTick(cb, err)
837
+ }
838
+ const SonicBoom = proxyquire('.', {
839
+ fs: fakeFs
840
+ })
841
+
842
+ const dest = file()
843
+ const fd = fs.openSync(dest, 'w')
844
+ const stream = new SonicBoom({ fd, sync: false, minLength: 0 })
845
+
846
+ stream.on('ready', () => {
847
+ t.pass('ready emitted')
848
+ })
849
+
850
+ t.ok(stream.write('hello world\n'))
851
+ t.ok(stream.write('something else\n'))
852
+
853
+ stream.end()
854
+
855
+ stream.on('finish', () => {
856
+ fs.readFile(dest, 'utf8', (err, data) => {
857
+ t.error(err)
858
+ t.equal(data, 'hello world\nsomething else\n')
859
+ })
860
+ })
861
+ stream.on('close', () => {
862
+ t.pass('close emitted')
863
+ })
864
+ })
865
+
866
+ test('emit error on async EAGAIN', (t) => {
867
+ t.plan(11)
868
+
869
+ const fakeFs = Object.create(fs)
870
+ fakeFs.write = function (fd, buf, enc, cb) {
871
+ t.pass('fake fs.write called')
872
+ fakeFs.write = fs.write
873
+ const err = new Error('EAGAIN')
874
+ err.code = 'EAGAIN'
875
+ process.nextTick(cb, err)
876
+ }
877
+ const SonicBoom = proxyquire('.', {
878
+ fs: fakeFs
879
+ })
880
+
881
+ const dest = file()
882
+ const fd = fs.openSync(dest, 'w')
883
+ const stream = new SonicBoom({
884
+ fd,
885
+ sync: false,
886
+ minLength: 12,
887
+ retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
888
+ t.equal(err.code, 'EAGAIN')
889
+ t.equal(writeBufferLen, 12)
890
+ t.equal(remainingBufferLen, 0)
891
+ return false
892
+ }
893
+ })
894
+
895
+ stream.on('ready', () => {
896
+ t.pass('ready emitted')
897
+ })
898
+
899
+ stream.once('error', err => {
900
+ t.equal(err.code, 'EAGAIN')
901
+ t.ok(stream.write('something else\n'))
902
+ })
903
+
904
+ t.ok(stream.write('hello world\n'))
905
+
906
+ stream.end()
907
+
908
+ stream.on('finish', () => {
909
+ fs.readFile(dest, 'utf8', (err, data) => {
910
+ t.error(err)
911
+ t.equal(data, 'hello world\nsomething else\n')
912
+ })
913
+ })
914
+ stream.on('close', () => {
915
+ t.pass('close emitted')
916
+ })
917
+ })
918
+
919
+ test('retry on EAGAIN (sync)', (t) => {
920
+ t.plan(7)
921
+
922
+ const fakeFs = Object.create(fs)
923
+ fakeFs.writeSync = function (fd, buf, enc, cb) {
924
+ t.pass('fake fs.writeSync called')
925
+ fakeFs.writeSync = fs.writeSync
926
+ const err = new Error('EAGAIN')
927
+ err.code = 'EAGAIN'
928
+ throw err
929
+ }
930
+ const SonicBoom = proxyquire('.', {
931
+ fs: fakeFs
932
+ })
933
+
934
+ const dest = file()
935
+ const fd = fs.openSync(dest, 'w')
936
+ const stream = new SonicBoom({ fd, minLength: 0, sync: true })
937
+
938
+ stream.on('ready', () => {
939
+ t.pass('ready emitted')
940
+ })
941
+
942
+ t.ok(stream.write('hello world\n'))
943
+ t.ok(stream.write('something else\n'))
944
+
945
+ stream.end()
946
+
947
+ stream.on('finish', () => {
948
+ fs.readFile(dest, 'utf8', (err, data) => {
949
+ t.error(err)
950
+ t.equal(data, 'hello world\nsomething else\n')
951
+ })
952
+ })
953
+ stream.on('close', () => {
954
+ t.pass('close emitted')
955
+ })
956
+ })
957
+
958
+ test('emit error on EAGAIN (sync)', (t) => {
959
+ t.plan(11)
960
+
961
+ const fakeFs = Object.create(fs)
962
+ fakeFs.writeSync = function (fd, buf, enc, cb) {
963
+ t.pass('fake fs.writeSync called')
964
+ fakeFs.writeSync = fs.writeSync
965
+ const err = new Error('EAGAIN')
966
+ err.code = 'EAGAIN'
967
+ throw err
968
+ }
969
+ const SonicBoom = proxyquire('.', {
970
+ fs: fakeFs
971
+ })
972
+
973
+ const dest = file()
974
+ const fd = fs.openSync(dest, 'w')
975
+ const stream = new SonicBoom({
976
+ fd,
977
+ minLength: 0,
978
+ sync: true,
979
+ retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
980
+ t.equal(err.code, 'EAGAIN')
981
+ t.equal(writeBufferLen, 12)
982
+ t.equal(remainingBufferLen, 0)
983
+ return false
984
+ }
985
+ })
986
+
987
+ stream.on('ready', () => {
988
+ t.pass('ready emitted')
989
+ })
990
+
991
+ stream.once('error', err => {
992
+ t.equal(err.code, 'EAGAIN')
993
+ t.ok(stream.write('something else\n'))
994
+ })
995
+
996
+ t.ok(stream.write('hello world\n'))
997
+
998
+ stream.end()
999
+
1000
+ stream.on('finish', () => {
1001
+ fs.readFile(dest, 'utf8', (err, data) => {
1002
+ t.error(err)
1003
+ t.equal(data, 'hello world\nsomething else\n')
1004
+ })
1005
+ })
1006
+ stream.on('close', () => {
1007
+ t.pass('close emitted')
1008
+ })
1009
+ })
1010
+
1011
+ test('retry in flushSync on EAGAIN', (t) => {
1012
+ t.plan(7)
1013
+
1014
+ const fakeFs = Object.create(fs)
1015
+ const SonicBoom = proxyquire('.', {
1016
+ fs: fakeFs
1017
+ })
1018
+
1019
+ const dest = file()
1020
+ const fd = fs.openSync(dest, 'w')
1021
+ const stream = new SonicBoom({ fd, sync: false, minLength: 0 })
1022
+
1023
+ stream.on('ready', () => {
1024
+ t.pass('ready emitted')
1025
+ })
1026
+
1027
+ t.ok(stream.write('hello world\n'))
1028
+
1029
+ fakeFs.writeSync = function (fd, buf, enc) {
1030
+ t.pass('fake fs.write called')
1031
+ fakeFs.writeSync = fs.writeSync
1032
+ const err = new Error('EAGAIN')
1033
+ err.code = 'EAGAIN'
1034
+ throw err
1035
+ }
1036
+
1037
+ t.ok(stream.write('something else\n'))
1038
+
1039
+ stream.flushSync()
1040
+ stream.end()
1041
+
1042
+ stream.on('finish', () => {
1043
+ fs.readFile(dest, 'utf8', (err, data) => {
1044
+ t.error(err)
1045
+ t.equal(data, 'hello world\nsomething else\n')
1046
+ })
1047
+ })
1048
+ stream.on('close', () => {
1049
+ t.pass('close emitted')
1050
+ })
1051
+ })
1052
+
1053
+ test('throw error in flushSync on EAGAIN', (t) => {
1054
+ t.plan(11)
1055
+
1056
+ const fakeFs = Object.create(fs)
1057
+ const SonicBoom = proxyquire('.', {
1058
+ fs: fakeFs
1059
+ })
1060
+
1061
+ const dest = file()
1062
+ const fd = fs.openSync(dest, 'w')
1063
+ const stream = new SonicBoom({
1064
+ fd,
1065
+ sync: false,
1066
+ minLength: 1000,
1067
+ retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
1068
+ t.equal(err.code, 'EAGAIN')
1069
+ t.equal(writeBufferLen, 12)
1070
+ t.equal(remainingBufferLen, 0)
1071
+ return false
1072
+ }
1073
+ })
1074
+
1075
+ stream.on('ready', () => {
1076
+ t.pass('ready emitted')
1077
+ })
1078
+
1079
+ const err = new Error('EAGAIN')
1080
+ err.code = 'EAGAIN'
1081
+ fakeFs.writeSync = function (fd, buf, enc) {
1082
+ Error.captureStackTrace(err)
1083
+ t.pass('fake fs.write called')
1084
+ fakeFs.writeSync = fs.writeSync
1085
+ throw err
1086
+ }
1087
+
1088
+ t.ok(stream.write('hello world\n'))
1089
+ t.throws(stream.flushSync.bind(stream), err, 'EAGAIN')
1090
+
1091
+ t.ok(stream.write('something else\n'))
1092
+ stream.flushSync()
1093
+
1094
+ stream.end()
1095
+
1096
+ stream.on('finish', () => {
1097
+ fs.readFile(dest, 'utf8', (err, data) => {
1098
+ t.error(err)
1099
+ t.equal(data, 'hello world\nsomething else\n')
1100
+ })
1101
+ })
1102
+ stream.on('close', () => {
1103
+ t.pass('close emitted')
1104
+ })
1105
+ })
1106
+
1107
+ test('retryEAGAIN receives remaining buffer on async if write fails', (t) => {
1108
+ t.plan(12)
1109
+
1110
+ const fakeFs = Object.create(fs)
1111
+ const SonicBoom = proxyquire('.', {
1112
+ fs: fakeFs
1113
+ })
1114
+
1115
+ const dest = file()
1116
+ const fd = fs.openSync(dest, 'w')
1117
+ const stream = new SonicBoom({
1118
+ fd,
1119
+ sync: false,
1120
+ minLength: 12,
1121
+ retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
1122
+ t.equal(err.code, 'EAGAIN')
1123
+ t.equal(writeBufferLen, 12)
1124
+ t.equal(remainingBufferLen, 11)
1125
+ return false
1126
+ }
1127
+ })
1128
+
1129
+ stream.on('ready', () => {
1130
+ t.pass('ready emitted')
1131
+ })
1132
+
1133
+ stream.once('error', err => {
1134
+ t.equal(err.code, 'EAGAIN')
1135
+ t.ok(stream.write('done'))
1136
+ })
1137
+
1138
+ fakeFs.write = function (fd, buf, enc, cb) {
1139
+ t.pass('fake fs.write called')
1140
+ fakeFs.write = fs.write
1141
+ const err = new Error('EAGAIN')
1142
+ err.code = 'EAGAIN'
1143
+ t.ok(stream.write('sonic boom\n'))
1144
+ process.nextTick(cb, err)
1145
+ }
1146
+
1147
+ t.ok(stream.write('hello world\n'))
1148
+
1149
+ stream.end()
1150
+
1151
+ stream.on('finish', () => {
1152
+ fs.readFile(dest, 'utf8', (err, data) => {
1153
+ t.error(err)
1154
+ t.equal(data, 'hello world\nsonic boom\ndone')
1155
+ })
1156
+ })
1157
+ stream.on('close', () => {
1158
+ t.pass('close emitted')
1159
+ })
1160
+ })
1161
+
1162
+ test('retryEAGAIN receives remaining buffer if exceeds maxWrite', (t) => {
1163
+ t.plan(17)
1164
+
1165
+ const fakeFs = Object.create(fs)
1166
+ const SonicBoom = proxyquire('.', {
1167
+ fs: fakeFs
1168
+ })
1169
+
1170
+ const dest = file()
1171
+ const fd = fs.openSync(dest, 'w')
1172
+ const buf = Buffer.alloc(MAX_WRITE - 2).fill('x').toString() // 1 MB
1173
+ const stream = new SonicBoom({
1174
+ fd,
1175
+ sync: false,
1176
+ minLength: MAX_WRITE - 1,
1177
+ retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
1178
+ t.equal(err.code, 'EAGAIN', 'retryEAGAIN received EAGAIN error')
1179
+ t.equal(writeBufferLen, buf.length, 'writeBufferLen === buf.length')
1180
+ t.equal(remainingBufferLen, 23, 'remainingBufferLen === 23')
1181
+ return false
1182
+ }
1183
+ })
1184
+
1185
+ stream.on('ready', () => {
1186
+ t.pass('ready emitted')
1187
+ })
1188
+
1189
+ fakeFs.write = function (fd, buf, enc, cb) {
1190
+ t.pass('fake fs.write called')
1191
+ const err = new Error('EAGAIN')
1192
+ err.code = 'EAGAIN'
1193
+ process.nextTick(cb, err)
1194
+ }
1195
+
1196
+ fakeFs.writeSync = function (fd, buf, enc, cb) {
1197
+ t.pass('fake fs.write called')
1198
+ const err = new Error('EAGAIN')
1199
+ err.code = 'EAGAIN'
1200
+ throw err
1201
+ }
1202
+
1203
+ t.ok(stream.write(buf), 'write buf')
1204
+ t.notOk(stream.write('hello world\nsonic boom\n'), 'write hello world sonic boom')
1205
+
1206
+ stream.once('error', err => {
1207
+ t.equal(err.code, 'EAGAIN', 'bubbled error should be EAGAIN')
1208
+
1209
+ try {
1210
+ stream.flushSync()
1211
+ } catch (err) {
1212
+ t.equal(err.code, 'EAGAIN', 'thrown error should be EAGAIN')
1213
+ fakeFs.write = fs.write
1214
+ fakeFs.writeSync = fs.writeSync
1215
+ stream.end()
1216
+ }
1217
+ })
1218
+
1219
+ stream.on('finish', () => {
1220
+ t.pass('finish emitted')
1221
+ fs.readFile(dest, 'utf8', (err, data) => {
1222
+ t.error(err)
1223
+ t.equal(data, `${buf}hello world\nsonic boom\n`, 'data on file should match written')
1224
+ })
1225
+ })
1226
+ stream.on('close', () => {
1227
+ t.pass('close emitted')
1228
+ })
1229
+ })
1230
+
1231
+ test('write buffers that are not totally written', (t) => {
1232
+ t.plan(9)
1233
+
1234
+ const fakeFs = Object.create(fs)
1235
+ fakeFs.write = function (fd, buf, enc, cb) {
1236
+ t.pass('fake fs.write called')
1237
+ fakeFs.write = function (fd, buf, enc, cb) {
1238
+ t.pass('calling real fs.write, ' + buf)
1239
+ fs.write(fd, buf, enc, cb)
1240
+ }
1241
+ process.nextTick(cb, null, 0)
1242
+ }
1243
+ const SonicBoom = proxyquire('.', {
1244
+ fs: fakeFs
1245
+ })
1246
+
1247
+ const dest = file()
1248
+ const fd = fs.openSync(dest, 'w')
1249
+ const stream = new SonicBoom({ fd, minLength: 0, sync: false })
1250
+
1251
+ stream.on('ready', () => {
1252
+ t.pass('ready emitted')
1253
+ })
1254
+
1255
+ t.ok(stream.write('hello world\n'))
1256
+ t.ok(stream.write('something else\n'))
1257
+
1258
+ stream.end()
1259
+
1260
+ stream.on('finish', () => {
1261
+ fs.readFile(dest, 'utf8', (err, data) => {
1262
+ t.error(err)
1263
+ t.equal(data, 'hello world\nsomething else\n')
1264
+ })
1265
+ })
1266
+ stream.on('close', () => {
1267
+ t.pass('close emitted')
1268
+ })
1269
+ })
1270
+
1271
+ test('write buffers that are not totally written with sync mode', (t) => {
1272
+ t.plan(9)
1273
+
1274
+ const fakeFs = Object.create(fs)
1275
+ fakeFs.writeSync = function (fd, buf, enc) {
1276
+ t.pass('fake fs.write called')
1277
+ fakeFs.writeSync = (fd, buf, enc) => {
1278
+ t.pass('calling real fs.writeSync, ' + buf)
1279
+ return fs.writeSync(fd, buf, enc)
1280
+ }
1281
+ return 0
1282
+ }
1283
+ const SonicBoom = proxyquire('.', {
1284
+ fs: fakeFs
1285
+ })
1286
+
1287
+ const dest = file()
1288
+ const fd = fs.openSync(dest, 'w')
1289
+ const stream = new SonicBoom({ fd, minLength: 0, sync: true })
1290
+
1291
+ stream.on('ready', () => {
1292
+ t.pass('ready emitted')
1293
+ })
1294
+
1295
+ t.ok(stream.write('hello world\n'))
1296
+ t.ok(stream.write('something else\n'))
1297
+
1298
+ stream.end()
1299
+
1300
+ stream.on('finish', () => {
1301
+ fs.readFile(dest, 'utf8', (err, data) => {
1302
+ t.error(err)
1303
+ t.equal(data, 'hello world\nsomething else\n')
1304
+ })
1305
+ })
1306
+ stream.on('close', () => {
1307
+ t.pass('close emitted')
1308
+ })
1309
+ })
1310
+
1311
+ test('sync writing is fully sync', (t) => {
1312
+ t.plan(6)
1313
+
1314
+ const fakeFs = Object.create(fs)
1315
+ fakeFs.writeSync = function (fd, buf, enc, cb) {
1316
+ t.pass('fake fs.write called')
1317
+ return fs.writeSync(fd, buf, enc)
1318
+ }
1319
+ const SonicBoom = proxyquire('.', {
1320
+ fs: fakeFs
1321
+ })
1322
+
1323
+ const dest = file()
1324
+ const fd = fs.openSync(dest, 'w')
1325
+ const stream = new SonicBoom({ fd, minLength: 0, sync: true })
1326
+ t.ok(stream.write('hello world\n'))
1327
+ t.ok(stream.write('something else\n'))
1328
+
1329
+ // 'drain' will be only emitted once,
1330
+ // the number of assertions at the top check this.
1331
+ stream.on('drain', () => {
1332
+ t.pass('drain emitted')
1333
+ })
1334
+
1335
+ const data = fs.readFileSync(dest, 'utf8')
1336
+ t.equal(data, 'hello world\nsomething else\n')
1337
+ })
1338
+
1339
+ test('write enormously large buffers async', (t) => {
1340
+ t.plan(3)
1341
+
1342
+ const dest = file()
1343
+ const fd = fs.openSync(dest, 'w')
1344
+ const stream = new SonicBoom({ fd, minLength: 0, sync: false })
1345
+
1346
+ const buf = Buffer.alloc(1024).fill('x').toString() // 1 MB
1347
+ let length = 0
1348
+
1349
+ for (let i = 0; i < 1024 * 512; i++) {
1350
+ length += buf.length
1351
+ stream.write(buf)
1352
+ }
1353
+
1354
+ stream.end()
1355
+
1356
+ stream.on('finish', () => {
1357
+ fs.stat(dest, (err, stat) => {
1358
+ t.error(err)
1359
+ t.equal(stat.size, length)
1360
+ })
1361
+ })
1362
+ stream.on('close', () => {
1363
+ t.pass('close emitted')
1364
+ })
1365
+ })
1366
+
1367
+ test('write enormously large buffers sync', (t) => {
1368
+ t.plan(3)
1369
+
1370
+ const dest = file()
1371
+ const fd = fs.openSync(dest, 'w')
1372
+ const stream = new SonicBoom({ fd, minLength: 0, sync: true })
1373
+
1374
+ const buf = Buffer.alloc(1024).fill('x').toString() // 1 MB
1375
+ let length = 0
1376
+
1377
+ for (let i = 0; i < 1024 * 512; i++) {
1378
+ length += buf.length
1379
+ stream.write(buf)
1380
+ }
1381
+
1382
+ stream.end()
1383
+
1384
+ stream.on('finish', () => {
1385
+ fs.stat(dest, (err, stat) => {
1386
+ t.error(err)
1387
+ t.equal(stat.size, length)
1388
+ })
1389
+ })
1390
+ stream.on('close', () => {
1391
+ t.pass('close emitted')
1392
+ })
1393
+ })
1394
+
1395
+ test('write enormously large buffers sync with utf8 multi-byte split', (t) => {
1396
+ t.plan(4)
1397
+
1398
+ const dest = file()
1399
+ const fd = fs.openSync(dest, 'w')
1400
+ const stream = new SonicBoom({ fd, minLength: 0, sync: true })
1401
+
1402
+ let buf = Buffer.alloc((1024 * 16) - 2).fill('x') // 16MB - 3B
1403
+ const length = buf.length + 4
1404
+ buf = buf.toString() + '🌲' // 16 MB + 1B
1405
+
1406
+ stream.write(buf)
1407
+
1408
+ stream.end()
1409
+
1410
+ stream.on('finish', () => {
1411
+ fs.stat(dest, (err, stat) => {
1412
+ t.error(err)
1413
+ t.equal(stat.size, length)
1414
+ const char = Buffer.alloc(4)
1415
+ const fd = fs.openSync(dest, 'r')
1416
+ fs.readSync(fd, char, 0, 4, length - 4)
1417
+ t.equal(char.toString(), '🌲')
1418
+ })
1419
+ })
1420
+ stream.on('close', () => {
1421
+ t.pass('close emitted')
1422
+ })
1423
+ })
1424
+
1425
+ // for context see this issue https://github.com/pinojs/pino/issues/871
1426
+ test('file specified by dest path available immediately when options.sync is true', (t) => {
1427
+ t.plan(3)
1428
+ const dest = file()
1429
+ const stream = new SonicBoom({ dest, sync: true })
1430
+ t.ok(stream.write('hello world\n'))
1431
+ t.ok(stream.write('something else\n'))
1432
+ stream.flushSync()
1433
+ t.pass('file opened and written to without error')
1434
+ })
1435
+
1436
+ test('sync error handling', (t) => {
1437
+ t.plan(1)
1438
+ try {
1439
+ /* eslint no-new: off */
1440
+ new SonicBoom({ dest: '/path/to/nowwhere', sync: true })
1441
+ t.fail('must throw synchronously')
1442
+ } catch (err) {
1443
+ t.pass('an error happened')
1444
+ }
1445
+ })
1446
+
1447
+ for (const fd of [1, 2]) {
1448
+ test(`fd ${fd}`, (t) => {
1449
+ t.plan(1)
1450
+
1451
+ const fakeFs = Object.create(fs)
1452
+ const SonicBoom = proxyquire('.', {
1453
+ fs: fakeFs
1454
+ })
1455
+
1456
+ const stream = new SonicBoom({ fd })
1457
+
1458
+ fakeFs.close = function (fd, cb) {
1459
+ t.fail(`should not close fd ${fd}`)
1460
+ }
1461
+
1462
+ stream.end()
1463
+
1464
+ stream.on('close', () => {
1465
+ t.pass('close emitted')
1466
+ })
1467
+ })
1468
+ }
1469
+
1470
+ test('write enormously large buffers async atomicly', (t) => {
1471
+ const fakeFs = Object.create(fs)
1472
+ const SonicBoom = proxyquire('.', {
1473
+ fs: fakeFs
1474
+ })
1475
+
1476
+ const dest = file()
1477
+ const fd = fs.openSync(dest, 'w')
1478
+ const stream = new SonicBoom({ fd, minLength: 0, sync: false })
1479
+
1480
+ const buf = Buffer.alloc(1023).fill('x').toString()
1481
+
1482
+ fakeFs.write = function (fd, _buf, enc, cb) {
1483
+ if (_buf.length % buf.length !== 0) {
1484
+ t.fail('write called with wrong buffer size')
1485
+ }
1486
+
1487
+ setImmediate(cb, null, _buf.length)
1488
+ }
1489
+
1490
+ for (let i = 0; i < 1024 * 512; i++) {
1491
+ stream.write(buf)
1492
+ }
1493
+
1494
+ setImmediate(() => {
1495
+ for (let i = 0; i < 1024 * 512; i++) {
1496
+ stream.write(buf)
1497
+ }
1498
+
1499
+ stream.end()
1500
+ })
1501
+
1502
+ stream.on('close', () => {
1503
+ t.pass('close emitted')
1504
+ t.end()
1505
+ })
1506
+ })
1507
+
1508
+ test('write should not drop new data if buffer is not full', (t) => {
1509
+ t.plan(2)
1510
+ const fakeFs = Object.create(fs)
1511
+ const SonicBoom = proxyquire('.', {
1512
+ fs: fakeFs
1513
+ })
1514
+
1515
+ const dest = file()
1516
+ const fd = fs.openSync(dest, 'w')
1517
+ const stream = new SonicBoom({ fd, minLength: 101, maxLength: 102, sync: false })
1518
+
1519
+ const buf = Buffer.alloc(100).fill('x').toString()
1520
+
1521
+ fakeFs.write = function (fd, _buf, enc, cb) {
1522
+ t.equal(_buf.length, buf.length + 2)
1523
+ setImmediate(cb, null, _buf.length)
1524
+ fakeFs.write = () => t.error('shouldnt call write again')
1525
+ stream.end()
1526
+ }
1527
+
1528
+ stream.on('drop', (data) => {
1529
+ t.error('should not drop')
1530
+ })
1531
+
1532
+ stream.write(buf)
1533
+ stream.write('aa')
1534
+
1535
+ stream.on('close', () => {
1536
+ t.pass('close emitted')
1537
+ })
1538
+ })
1539
+
1540
+ test('write should drop new data if buffer is full', (t) => {
1541
+ t.plan(3)
1542
+ const fakeFs = Object.create(fs)
1543
+ const SonicBoom = proxyquire('.', {
1544
+ fs: fakeFs
1545
+ })
1546
+
1547
+ const dest = file()
1548
+ const fd = fs.openSync(dest, 'w')
1549
+ const stream = new SonicBoom({ fd, minLength: 101, maxLength: 102, sync: false })
1550
+
1551
+ const buf = Buffer.alloc(100).fill('x').toString()
1552
+
1553
+ fakeFs.write = function (fd, _buf, enc, cb) {
1554
+ t.equal(_buf.length, buf.length)
1555
+ setImmediate(cb, null, _buf.length)
1556
+ fakeFs.write = () => t.error('shouldnt call write more than once')
1557
+ }
1558
+
1559
+ stream.on('drop', (data) => {
1560
+ t.equal(data.length, 3)
1561
+ stream.end()
1562
+ })
1563
+
1564
+ stream.write(buf)
1565
+ stream.write('aaa')
1566
+
1567
+ stream.on('close', () => {
1568
+ t.pass('close emitted')
1569
+ })
1570
+ })
1571
+
1572
+ test('should throw if minLength >= maxWrite', (t) => {
1573
+ t.plan(1)
1574
+ t.throws(() => {
1575
+ const dest = file()
1576
+ const fd = fs.openSync(dest, 'w')
1577
+
1578
+ new SonicBoom({
1579
+ fd,
1580
+ minLength: MAX_WRITE
1581
+ })
1582
+ })
1583
+ })
1584
+
1585
+ test('make sure `maxWrite` is passed', (t) => {
1586
+ t.plan(1)
1587
+ const dest = file()
1588
+ const stream = new SonicBoom({ dest, maxLength: 65536 })
1589
+ t.equal(stream.maxLength, 65536)
1590
+ })
1591
+
1592
+ test('fsync with sync', (t) => {
1593
+ t.plan(5)
1594
+
1595
+ const fakeFs = Object.create(fs)
1596
+ fakeFs.fsyncSync = function (fd) {
1597
+ t.pass('fake fs.fsyncSync called')
1598
+ return fs.fsyncSync(fd)
1599
+ }
1600
+ const SonicBoom = proxyquire('.', {
1601
+ fs: fakeFs
1602
+ })
1603
+
1604
+ const dest = file()
1605
+ const fd = fs.openSync(dest, 'w')
1606
+ const stream = new SonicBoom({ fd, sync: true, fsync: true })
1607
+
1608
+ t.ok(stream.write('hello world\n'))
1609
+ t.ok(stream.write('something else\n'))
1610
+
1611
+ stream.end()
1612
+
1613
+ const data = fs.readFileSync(dest, 'utf8')
1614
+ t.equal(data, 'hello world\nsomething else\n')
1615
+ })
1616
+
1617
+ test('fsync with async', (t) => {
1618
+ t.plan(7)
1619
+
1620
+ const fakeFs = Object.create(fs)
1621
+ fakeFs.fsyncSync = function (fd) {
1622
+ t.pass('fake fs.fsyncSync called')
1623
+ return fs.fsyncSync(fd)
1624
+ }
1625
+ const SonicBoom = proxyquire('.', {
1626
+ fs: fakeFs
1627
+ })
1628
+
1629
+ const dest = file()
1630
+ const fd = fs.openSync(dest, 'w')
1631
+ const stream = new SonicBoom({ fd, fsync: true })
1632
+
1633
+ t.ok(stream.write('hello world\n'))
1634
+ t.ok(stream.write('something else\n'))
1635
+
1636
+ stream.end()
1637
+
1638
+ stream.on('finish', () => {
1639
+ fs.readFile(dest, 'utf8', (err, data) => {
1640
+ t.error(err)
1641
+ t.equal(data, 'hello world\nsomething else\n')
1642
+ })
1643
+ })
1644
+ stream.on('close', () => {
1645
+ t.pass('close emitted')
1646
+ })
1647
+ })
1648
+
1649
+ test('._len must always be equal or greater than 0', (t) => {
1650
+ t.plan(3)
1651
+
1652
+ const dest = file()
1653
+ const fd = fs.openSync(dest, 'w')
1654
+ const stream = new SonicBoom({ fd, sync: true })
1655
+
1656
+ t.ok(stream.write('hello world 👀\n'))
1657
+ t.ok(stream.write('another line 👀\n'))
1658
+
1659
+ t.equal(stream._len, 0)
1660
+
1661
+ stream.end()
1662
+ })
1663
+
1664
+ test('._len must always be equal or greater than 0', (t) => {
1665
+ const n = 20
1666
+ t.plan(n + 3)
1667
+
1668
+ const dest = file()
1669
+ const fd = fs.openSync(dest, 'w')
1670
+ const stream = new SonicBoom({ fd, sync: true, minLength: 20 })
1671
+
1672
+ let str = ''
1673
+ for (let i = 0; i < 20; i++) {
1674
+ t.ok(stream.write('👀'))
1675
+ str += '👀'
1676
+ }
1677
+
1678
+ t.equal(stream._len, 0)
1679
+
1680
+ fs.readFile(dest, 'utf8', (err, data) => {
1681
+ t.error(err)
1682
+ t.equal(data, str)
1683
+ })
1684
+ })