@c9up/ream 0.2.6 → 0.2.8

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 (71) hide show
  1. package/dist/HttpKernel.d.ts.map +1 -1
  2. package/dist/HttpKernel.js +10 -0
  3. package/dist/HttpKernel.js.map +1 -1
  4. package/dist/Ignitor.d.ts.map +1 -1
  5. package/dist/Ignitor.js +17 -0
  6. package/dist/Ignitor.js.map +1 -1
  7. package/dist/bootstrap/hyper-server.js.map +1 -1
  8. package/dist/debug.d.ts +22 -0
  9. package/dist/debug.d.ts.map +1 -0
  10. package/dist/debug.js +23 -0
  11. package/dist/debug.js.map +1 -0
  12. package/dist/dumper/Dumper.d.ts +80 -0
  13. package/dist/dumper/Dumper.d.ts.map +1 -0
  14. package/dist/dumper/Dumper.js +129 -0
  15. package/dist/dumper/Dumper.js.map +1 -0
  16. package/dist/helpers/is.d.ts.map +1 -1
  17. package/dist/helpers/is.js +1 -4
  18. package/dist/helpers/is.js.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/middleware/Pipeline.d.ts.map +1 -1
  22. package/dist/middleware/Pipeline.js +7 -0
  23. package/dist/middleware/Pipeline.js.map +1 -1
  24. package/dist/repl/Repl.d.ts +88 -0
  25. package/dist/repl/Repl.d.ts.map +1 -0
  26. package/dist/repl/Repl.js +123 -0
  27. package/dist/repl/Repl.js.map +1 -0
  28. package/dist/scheduler/Scheduler.d.ts.map +1 -1
  29. package/dist/scheduler/Scheduler.js +12 -4
  30. package/dist/scheduler/Scheduler.js.map +1 -1
  31. package/dist/services/dumper.d.ts +25 -0
  32. package/dist/services/dumper.d.ts.map +1 -0
  33. package/dist/services/dumper.js +27 -0
  34. package/dist/services/dumper.js.map +1 -0
  35. package/dist/services/logger.d.ts +29 -0
  36. package/dist/services/logger.d.ts.map +1 -0
  37. package/dist/services/logger.js +40 -0
  38. package/dist/services/logger.js.map +1 -0
  39. package/dist/services/repl.d.ts +19 -0
  40. package/dist/services/repl.d.ts.map +1 -0
  41. package/dist/services/repl.js +19 -0
  42. package/dist/services/repl.js.map +1 -0
  43. package/dist/session/Session.js.map +1 -1
  44. package/dist/testing/TestClient.d.ts +18 -3
  45. package/dist/testing/TestClient.d.ts.map +1 -1
  46. package/dist/testing/TestClient.js +45 -4
  47. package/dist/testing/TestClient.js.map +1 -1
  48. package/dist/testing/testUtils.d.ts +62 -0
  49. package/dist/testing/testUtils.d.ts.map +1 -0
  50. package/dist/testing/testUtils.js +77 -0
  51. package/dist/testing/testUtils.js.map +1 -0
  52. package/events.win32-x64-msvc.node +0 -0
  53. package/index.win32-x64-msvc.node +0 -0
  54. package/package.json +25 -1
  55. package/scheduler.win32-x64-msvc.node +0 -0
  56. package/src/HttpKernel.ts +27 -0
  57. package/src/Ignitor.ts +17 -1
  58. package/src/bootstrap/hyper-server.ts +1 -1
  59. package/src/debug.ts +25 -0
  60. package/src/dumper/Dumper.ts +164 -0
  61. package/src/helpers/is.ts +1 -6
  62. package/src/index.ts +1 -1
  63. package/src/middleware/Pipeline.ts +7 -0
  64. package/src/repl/Repl.ts +162 -0
  65. package/src/scheduler/Scheduler.ts +10 -4
  66. package/src/services/dumper.ts +30 -0
  67. package/src/services/logger.ts +49 -0
  68. package/src/services/repl.ts +21 -0
  69. package/src/session/Session.ts +2 -2
  70. package/src/testing/TestClient.ts +47 -5
  71. package/src/testing/testUtils.ts +90 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Test utilities, in the shape AdonisJS gives them: `testUtils.httpServer()`
3
+ * starts the application's HTTP server for a test run and hands back the
4
+ * function that closes it.
5
+ *
6
+ * // tests/bootstrap.ts
7
+ * configureSuite(suite) {
8
+ * if (['functional', 'e2e'].includes(suite.name)) {
9
+ * return suite.setup(() => testUtils.httpServer().start())
10
+ * }
11
+ * }
12
+ *
13
+ * The point of the shape is WHERE the server starts. A suite that does not
14
+ * declare the hook never starts one, so a unit suite pays nothing — which is
15
+ * the same saving a lazily-booted client buys, obtained by scoping instead of
16
+ * by deferring, and obtained per SUITE rather than per file.
17
+ *
18
+ * `start()` returning its own teardown is what makes it a one-liner in a hook:
19
+ * a setup hook may return its undo, so there is no matching `teardown` to
20
+ * write and no way to forget it.
21
+ */
22
+
23
+ import { TestClient } from './TestClient.js'
24
+
25
+ /** Boots the app on `port` and reports the port it bound plus how to stop it. */
26
+ export type BootServer = (
27
+ port: number,
28
+ ) => Promise<{ port: number; close: () => Promise<void> | void }>
29
+
30
+ /**
31
+ * What `testUtils.httpServer()` returns — AdonisJS `HttpServerUtils`.
32
+ */
33
+ export class HttpServerUtils {
34
+ readonly #boot: BootServer
35
+ readonly #onStarted: (client: TestClient) => void
36
+
37
+ constructor(boot: BootServer, onStarted: (client: TestClient) => void) {
38
+ this.#boot = boot
39
+ this.#onStarted = onStarted
40
+ }
41
+
42
+ /**
43
+ * Start the server. Returns the function that closes it, so a setup hook can
44
+ * return this call directly.
45
+ */
46
+ async start(): Promise<() => Promise<void>> {
47
+ const client = new TestClient(this.#boot)
48
+ await client.boot()
49
+ this.#onStarted(client)
50
+ return () => client.close()
51
+ }
52
+ }
53
+
54
+ /**
55
+ * The utilities themselves — AdonisJS `TestUtils`.
56
+ *
57
+ * Constructed with how to boot the app, because ream has no ambient
58
+ * application to reach for: the app is whatever the test bootstrap hands over.
59
+ * That is the one place this differs from AdonisJS, where `testUtils` is a
60
+ * service resolved from the container and already knows its app.
61
+ */
62
+ export class TestUtils {
63
+ readonly #boot: BootServer
64
+ #client: TestClient | undefined
65
+
66
+ constructor(boot: BootServer) {
67
+ this.#boot = boot
68
+ }
69
+
70
+ /** Start/stop the HTTP server for a suite. */
71
+ httpServer(): HttpServerUtils {
72
+ return new HttpServerUtils(this.#boot, (client) => {
73
+ this.#client = client
74
+ })
75
+ }
76
+
77
+ /**
78
+ * The client for the server this run started, or `undefined` before
79
+ * `httpServer().start()`. A plugin reads it to put a client on the test
80
+ * context without booting a second server.
81
+ */
82
+ client(): TestClient | undefined {
83
+ return this.#client
84
+ }
85
+ }
86
+
87
+ /** Build the utilities for an app booted by `boot`. */
88
+ export function createTestUtils(boot: BootServer): TestUtils {
89
+ return new TestUtils(boot)
90
+ }