@c9up/ream 0.2.6 → 0.2.7
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.
- package/dist/Ignitor.d.ts.map +1 -1
- package/dist/Ignitor.js +17 -0
- package/dist/Ignitor.js.map +1 -1
- package/dist/bootstrap/hyper-server.js.map +1 -1
- package/dist/helpers/is.d.ts.map +1 -1
- package/dist/helpers/is.js +1 -4
- package/dist/helpers/is.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/scheduler/Scheduler.d.ts.map +1 -1
- package/dist/scheduler/Scheduler.js +12 -4
- package/dist/scheduler/Scheduler.js.map +1 -1
- package/dist/services/logger.d.ts +29 -0
- package/dist/services/logger.d.ts.map +1 -0
- package/dist/services/logger.js +40 -0
- package/dist/services/logger.js.map +1 -0
- package/dist/session/Session.js.map +1 -1
- package/dist/testing/TestClient.d.ts +18 -3
- package/dist/testing/TestClient.d.ts.map +1 -1
- package/dist/testing/TestClient.js +45 -4
- package/dist/testing/TestClient.js.map +1 -1
- package/dist/testing/testUtils.d.ts +62 -0
- package/dist/testing/testUtils.d.ts.map +1 -0
- package/dist/testing/testUtils.js +77 -0
- package/dist/testing/testUtils.js.map +1 -0
- package/events.win32-x64-msvc.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +9 -1
- package/scheduler.win32-x64-msvc.node +0 -0
- package/src/Ignitor.ts +17 -1
- package/src/bootstrap/hyper-server.ts +1 -1
- package/src/helpers/is.ts +1 -6
- package/src/index.ts +1 -1
- package/src/scheduler/Scheduler.ts +10 -4
- package/src/services/logger.ts +49 -0
- package/src/session/Session.ts +2 -2
- package/src/testing/TestClient.ts +47 -5
- 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
|
+
}
|