@toa.io/userland 1.0.0-alpha.28 → 1.0.0-alpha.283
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/CHANGELOG.md +329 -0
- package/example/components/echo/manifest.toa.yaml +14 -5
- package/example/components/echo/operations/get.js +1 -5
- package/example/components/echo/operations/resolve.js +1 -5
- package/example/components/echo/operations/signal.js +1 -5
- package/example/components/math.calculations/manifest.toa.yaml +17 -6
- package/example/components/math.calculations/operations/add.js +1 -5
- package/example/components/math.calculations/operations/increment.js +1 -5
- package/example/components/math.proxy/manifest.toa.yaml +8 -3
- package/example/components/math.proxy/operations/add.js +1 -5
- package/example/components/tea.pots/manifest.toa.yaml +37 -9
- package/example/components/tea.pots/operations/same.js +1 -5
- package/example/components/tea.pots/receivers/store.orders.created.js +1 -5
- package/example/components/web/manifest.toa.yaml +2 -4
- package/example/components/web/operations/get.js +2 -6
- package/example/context.toa.yaml +0 -5
- package/example/stage/call.test.js +14 -10
- package/example/stage/events.test.js +63 -16
- package/example/stage/invoke.test.js +11 -8
- package/package.json +18 -12
- package/stage/package.json +1 -0
- package/stage/src/component.js +3 -12
- package/stage/src/composition.js +3 -11
- package/stage/src/index.js +7 -17
- package/stage/src/manifest.js +2 -6
- package/stage/src/remote.js +11 -8
- package/stage/src/service.js +10 -9
- package/stage/src/shutdown.js +2 -8
- package/stage/src/state.js +1 -4
- package/stage/test/boot.mock.js +9 -11
- package/stage/test/component.test.js +16 -10
- package/stage/test/composition.test.js +11 -20
- package/stage/test/manifest.test.js +11 -8
- package/stage/test/remote.test.js +14 -12
- package/stage/test/shutdown.test.js +26 -22
- package/stage/test/state.mock.js +5 -6
- package/stage/test/state.test.js +10 -9
- package/stage/types/index.d.ts +0 -2
- package/stage/src/binding/binding.js +0 -50
- package/stage/src/binding/consumer.js +0 -32
- package/stage/src/binding/emitter.js +0 -27
- package/stage/src/binding/factory.js +0 -49
- package/stage/src/binding/index.js +0 -10
- package/stage/src/binding/label.js +0 -12
- package/stage/src/binding/producer.js +0 -43
- package/stage/src/binding/receiver.js +0 -34
- package/stage/test/binding/binding.test.js +0 -15
- package/stage/test/binding/consumer.test.js +0 -52
- package/stage/test/binding/emitter.test.js +0 -78
- package/stage/test/binding/producer.fixtures.js +0 -10
- package/stage/test/binding/producer.test.js +0 -49
- package/stage/test/binding/receiver.fixtures.js +0 -7
- package/stage/test/binding/receiver.test.js +0 -54
- package/stage/test/binding.mock.js +0 -8
- package/stage/types/binding.d.ts +0 -20
|
@@ -1,51 +1,98 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, before, after } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
|
+
import * as boot from '@toa.io/boot'
|
|
6
|
+
import { Connector, Locator } from '@toa.io/core'
|
|
7
|
+
import { timeout } from '@toa.io/generic'
|
|
8
|
+
import * as stage from '@toa.io/userland/stage'
|
|
5
9
|
|
|
6
|
-
const
|
|
7
|
-
const root = resolve(__dirname, '../components')
|
|
10
|
+
const root = resolve(import.meta.dirname, '../components')
|
|
8
11
|
|
|
9
12
|
let remote
|
|
13
|
+
let emitter
|
|
14
|
+
let consumer
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
before(async () => {
|
|
12
17
|
process.env.TOA_DEV = '1'
|
|
18
|
+
process.env.TOA_CONFIGURATION_TEA_POTS = '{}'
|
|
19
|
+
|
|
20
|
+
// the outbox pumps on a tick; at the default five seconds a test would end before it ran
|
|
21
|
+
process.env.TOA_OUTBOX_INTERVAL = '100'
|
|
13
22
|
|
|
14
23
|
const path = resolve(root, 'tea.pots')
|
|
15
24
|
|
|
16
25
|
await stage.composition([path])
|
|
17
26
|
|
|
18
27
|
remote = await stage.remote('tea.pots')
|
|
28
|
+
|
|
29
|
+
// what `store.orders` would emit, sent the way it would send it
|
|
30
|
+
emitter = await boot.bindings.emit(AMQP, new Locator('orders', 'store'), 'created')
|
|
31
|
+
|
|
32
|
+
await emitter.connect()
|
|
19
33
|
})
|
|
20
34
|
|
|
21
|
-
|
|
35
|
+
after(async () => {
|
|
36
|
+
await consumer?.disconnect()
|
|
37
|
+
await emitter.disconnect()
|
|
22
38
|
await stage.shutdown()
|
|
23
39
|
|
|
24
40
|
delete process.env.TOA_DEV
|
|
41
|
+
delete process.env.TOA_CONFIGURATION_TEA_POTS
|
|
42
|
+
delete process.env.TOA_OUTBOX_INTERVAL
|
|
25
43
|
})
|
|
26
44
|
|
|
27
45
|
it('should receive event', async () => {
|
|
28
46
|
const created = await remote.invoke('transit', { input: { material: 'glass' } })
|
|
29
47
|
const id = created.id
|
|
30
|
-
const payload = { pot: id }
|
|
31
|
-
const message = { payload }
|
|
32
48
|
const request = { query: { id } }
|
|
33
49
|
|
|
34
|
-
await
|
|
50
|
+
await emitter.emit({ payload: { pot: id } })
|
|
51
|
+
|
|
52
|
+
// the receiver books the pot on delivery, which is asynchronous
|
|
53
|
+
const deadline = Date.now() + 5000
|
|
35
54
|
|
|
36
|
-
|
|
55
|
+
let reply
|
|
37
56
|
|
|
38
|
-
|
|
57
|
+
do {
|
|
58
|
+
await timeout(50)
|
|
59
|
+
|
|
60
|
+
reply = await remote.invoke('observe', request)
|
|
61
|
+
} while (reply.booked !== true && Date.now() < deadline)
|
|
62
|
+
|
|
63
|
+
assert.deepStrictEqual(reply.booked, true)
|
|
39
64
|
})
|
|
40
65
|
|
|
41
66
|
it('should emit event', async () => {
|
|
42
|
-
expect.assertions(1)
|
|
43
|
-
|
|
44
67
|
const material = 'steel'
|
|
45
68
|
|
|
46
|
-
|
|
47
|
-
|
|
69
|
+
const received = new Promise((resolve) => {
|
|
70
|
+
consumer = boot.receive('tea.pots.created', new Subscriber(resolve))
|
|
48
71
|
})
|
|
49
72
|
|
|
73
|
+
consumer = await consumer
|
|
74
|
+
|
|
75
|
+
await consumer.connect()
|
|
50
76
|
await remote.invoke('transit', { input: { material } })
|
|
77
|
+
|
|
78
|
+
const payload = await received
|
|
79
|
+
|
|
80
|
+
assert.deepStrictEqual(payload.material, material)
|
|
51
81
|
})
|
|
82
|
+
|
|
83
|
+
/** What the event consumer hands deliveries to. */
|
|
84
|
+
class Subscriber extends Connector {
|
|
85
|
+
#handler
|
|
86
|
+
|
|
87
|
+
constructor (handler) {
|
|
88
|
+
super()
|
|
89
|
+
|
|
90
|
+
this.#handler = handler
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async receive (message) {
|
|
94
|
+
this.#handler(message.payload)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const AMQP = '@toa.io/bindings.amqp'
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, before, after } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
|
+
import * as stage from '@toa.io/userland/stage'
|
|
5
6
|
|
|
6
|
-
const root = resolve(
|
|
7
|
+
const root = resolve(import.meta.dirname, '../components')
|
|
7
8
|
|
|
8
9
|
/** @type {toa.core.Component} */
|
|
9
10
|
let component
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
before(async () => {
|
|
12
13
|
process.env.TOA_DEV = '1'
|
|
14
|
+
process.env.TOA_CONFIGURATION_DEFAULT_ECHO = '{}'
|
|
15
|
+
process.env.TOA_CONFIGURATION_TEA_POTS = '{}'
|
|
13
16
|
|
|
14
17
|
const path = resolve(root, 'math.calculations')
|
|
15
18
|
|
|
16
19
|
component = await stage.component(path)
|
|
17
20
|
})
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
after(async () => {
|
|
20
23
|
await stage.shutdown()
|
|
21
24
|
|
|
22
25
|
delete process.env.TOA_DEV
|
|
@@ -28,6 +31,6 @@ it('should invoke', async () => {
|
|
|
28
31
|
|
|
29
32
|
const reply = await component.invoke('add', { input: { a, b } })
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
assert.strictEqual(reply.exception, undefined)
|
|
35
|
+
assert.deepStrictEqual(reply.output, a + b)
|
|
33
36
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/userland",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.283",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Toa development kit",
|
|
5
6
|
"homepage": "https://toa.io",
|
|
6
7
|
"author": {
|
|
@@ -16,23 +17,28 @@
|
|
|
16
17
|
"url": "https://github.com/toa-io/toa/issues"
|
|
17
18
|
},
|
|
18
19
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
20
|
+
"node": ">= 24.0.0"
|
|
20
21
|
},
|
|
21
22
|
"publishConfig": {
|
|
22
23
|
"access": "public"
|
|
23
24
|
},
|
|
24
25
|
"main": "src/index.js",
|
|
25
|
-
"
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./src/index.js",
|
|
28
|
+
"./stage": {
|
|
29
|
+
"types": "./stage/types/index.d.ts",
|
|
30
|
+
"default": "./stage/src/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
26
34
|
"dependencies": {
|
|
27
|
-
"@toa.io/boot": "1.0.0-alpha.
|
|
28
|
-
"@toa.io/core": "1.0.0-alpha.
|
|
29
|
-
"@toa.io/
|
|
30
|
-
"@toa.io/
|
|
31
|
-
"@toa.io/
|
|
32
|
-
"@toa.io/schemas": "1.0.0-alpha.28",
|
|
35
|
+
"@toa.io/boot": "1.0.0-alpha.283",
|
|
36
|
+
"@toa.io/core": "1.0.0-alpha.283",
|
|
37
|
+
"@toa.io/generic": "1.0.0-alpha.283",
|
|
38
|
+
"@toa.io/norm": "1.0.0-alpha.283",
|
|
39
|
+
"@toa.io/schemas": "1.0.0-alpha.283",
|
|
33
40
|
"@toa.io/storages.null": "0.22.0",
|
|
34
|
-
"
|
|
35
|
-
"tap": "16.3.4"
|
|
41
|
+
"js-yaml": "5.4.1"
|
|
36
42
|
},
|
|
37
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "2f52b023bed0ccb2ecdb2b82fe59fbe38bf282e1"
|
|
38
44
|
}
|
package/stage/package.json
CHANGED
package/stage/src/component.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const boot = require('@toa.io/boot')
|
|
4
|
-
const { state } = require('./state')
|
|
1
|
+
import * as boot from '@toa.io/boot'
|
|
2
|
+
import { state } from './state.js'
|
|
5
3
|
|
|
6
4
|
/** @type {toa.stage.Component} */
|
|
7
|
-
const component = async (path, options) => {
|
|
8
|
-
options = Object.assign({}, DEFAULTS, options)
|
|
9
|
-
|
|
5
|
+
export const component = async (path, options) => {
|
|
10
6
|
const manifest = await boot.manifest(path, options)
|
|
11
7
|
const component = await boot.component(manifest)
|
|
12
8
|
|
|
@@ -16,8 +12,3 @@ const component = async (path, options) => {
|
|
|
16
12
|
|
|
17
13
|
return component
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
const binding = require.resolve('./binding')
|
|
21
|
-
const DEFAULTS = { bindings: [binding] }
|
|
22
|
-
|
|
23
|
-
exports.component = component
|
package/stage/src/composition.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const boot = require('@toa.io/boot')
|
|
4
|
-
const { state } = require('./state')
|
|
5
|
-
|
|
6
|
-
const binding = require.resolve('./binding')
|
|
1
|
+
import * as boot from '@toa.io/boot'
|
|
2
|
+
import { state } from './state.js'
|
|
7
3
|
|
|
8
4
|
/** @type {toa.stage.Composition} */
|
|
9
|
-
const composition = async (paths, options) => {
|
|
10
|
-
options ??= { bindings: [binding] }
|
|
11
|
-
|
|
5
|
+
export const composition = async (paths, options) => {
|
|
12
6
|
const composition = await boot.composition(paths, options)
|
|
13
7
|
|
|
14
8
|
await composition.connect()
|
|
15
9
|
|
|
16
10
|
state.compositions.push(composition)
|
|
17
11
|
}
|
|
18
|
-
|
|
19
|
-
exports.composition = composition
|
package/stage/src/index.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { manifest } from './manifest.js'
|
|
2
|
+
import { component } from './component.js'
|
|
3
|
+
import { composition } from './composition.js'
|
|
4
|
+
import { service } from './service.js'
|
|
5
|
+
import { remote } from './remote.js'
|
|
6
|
+
import { shutdown } from './shutdown.js'
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
const { component } = require('./component')
|
|
5
|
-
const { composition } = require('./composition')
|
|
6
|
-
const { service } = require('./service')
|
|
7
|
-
const { remote } = require('./remote')
|
|
8
|
-
const { shutdown } = require('./shutdown')
|
|
9
|
-
const binding = require('./binding')
|
|
10
|
-
|
|
11
|
-
exports.manifest = manifest
|
|
12
|
-
exports.component = component
|
|
13
|
-
exports.composition = composition
|
|
14
|
-
exports.compose = composition
|
|
15
|
-
exports.serve = service
|
|
16
|
-
exports.remote = remote
|
|
17
|
-
exports.shutdown = shutdown
|
|
18
|
-
exports.binding = binding
|
|
8
|
+
export { manifest, component, composition, composition as compose, service as serve, remote, shutdown }
|
package/stage/src/manifest.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const boot = require('@toa.io/boot')
|
|
1
|
+
import * as boot from '@toa.io/boot'
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @type {toa.stage.Manifest}
|
|
7
5
|
*/
|
|
8
|
-
const manifest = async (path) => {
|
|
6
|
+
export const manifest = async (path) => {
|
|
9
7
|
return boot.manifest(path)
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
exports.manifest = manifest
|
package/stage/src/remote.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import * as boot from '@toa.io/boot'
|
|
2
|
+
import { Locator } from '@toa.io/core'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const { Locator } = require('@toa.io/core')
|
|
5
|
-
|
|
6
|
-
const { state } = require('./state')
|
|
4
|
+
import { state } from './state.js'
|
|
7
5
|
|
|
8
6
|
/** @type {toa.stage.Remote} */
|
|
9
|
-
const remote = async (id) => {
|
|
7
|
+
export const remote = async (id) => {
|
|
10
8
|
const segments = id.split('.')
|
|
11
9
|
|
|
12
10
|
if (segments.length === 1) segments.unshift('default')
|
|
13
11
|
|
|
14
12
|
const [namespace, name] = segments
|
|
15
13
|
const locator = new Locator(name, namespace)
|
|
16
|
-
const remote = await boot.remote(locator)
|
|
14
|
+
const remote = await boot.remote(locator, SOURCE)
|
|
17
15
|
|
|
18
16
|
await remote.connect()
|
|
19
17
|
|
|
@@ -22,4 +20,9 @@ const remote = async (id) => {
|
|
|
22
20
|
return remote
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A feature suite calls components the way a service does, so it says so: without this
|
|
25
|
+
* every call it makes is attributed to an unidentified origin, and a test run leaves
|
|
26
|
+
* `unknown` on the application's map.
|
|
27
|
+
*/
|
|
28
|
+
const SOURCE = { service: 'features' }
|
package/stage/src/service.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import { pathToFileURL } from 'node:url'
|
|
3
|
+
import * as boot from '@toa.io/boot'
|
|
4
|
+
import { state } from './state.js'
|
|
5
|
+
import { shortcuts } from '@toa.io/norm'
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const { shortcuts } = require('@toa.io/norm')
|
|
7
|
+
// a shortcut resolves to a package name, which is not a path
|
|
8
|
+
const require = createRequire(import.meta.url)
|
|
6
9
|
|
|
7
|
-
const service = async (ref) => {
|
|
10
|
+
export const service = async (ref) => {
|
|
8
11
|
const path = shortcuts.resolve(ref)
|
|
9
|
-
const { Factory } = require(path)
|
|
12
|
+
const { Factory } = await import(pathToFileURL(require.resolve(path)).href)
|
|
10
13
|
const factory = new Factory(boot)
|
|
11
|
-
const service = factory.service()
|
|
14
|
+
const service = await factory.service()
|
|
12
15
|
|
|
13
16
|
await service.connect()
|
|
14
17
|
|
|
@@ -16,5 +19,3 @@ const service = async (ref) => {
|
|
|
16
19
|
|
|
17
20
|
return service
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
exports.service = service
|
package/stage/src/shutdown.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { state } = require('./state')
|
|
4
|
-
const { binding } = require('./binding')
|
|
1
|
+
import { state } from './state.js'
|
|
5
2
|
|
|
6
3
|
/** @type {toa.stage.Shutdown} */
|
|
7
|
-
const shutdown = async () => {
|
|
4
|
+
export const shutdown = async () => {
|
|
8
5
|
const components = state.components.map((component) => component.disconnect())
|
|
9
6
|
const compositions = state.compositions.map((composition) => composition.disconnect())
|
|
10
7
|
const services = state.services.map((service) => service.disconnect())
|
|
@@ -14,7 +11,4 @@ const shutdown = async () => {
|
|
|
14
11
|
await Promise.all(disconnections)
|
|
15
12
|
|
|
16
13
|
state.reset()
|
|
17
|
-
binding.reset()
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
exports.shutdown = shutdown
|
package/stage/src/state.js
CHANGED
package/stage/test/boot.mock.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { mock } from 'node:test'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { generate } from 'randomstring'
|
|
4
4
|
|
|
5
5
|
const connector = () => ({
|
|
6
|
-
connect:
|
|
7
|
-
disconnect:
|
|
8
|
-
link:
|
|
6
|
+
connect: mock.fn(),
|
|
7
|
+
disconnect: mock.fn(),
|
|
8
|
+
link: mock.fn()
|
|
9
9
|
})
|
|
10
10
|
|
|
11
|
-
const manifest =
|
|
12
|
-
const component =
|
|
13
|
-
const composition =
|
|
14
|
-
const remote =
|
|
15
|
-
|
|
16
|
-
module.exports = { manifest, component, composition, remote }
|
|
11
|
+
export const manifest = mock.fn(async () => generate())
|
|
12
|
+
export const component = mock.fn(async () => connector())
|
|
13
|
+
export const composition = mock.fn(async () => connector())
|
|
14
|
+
export const remote = mock.fn(async () => connector())
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
import { generate } from 'randomstring'
|
|
6
|
+
import * as _boot from './boot.mock.js'
|
|
4
7
|
|
|
5
8
|
const mock = {
|
|
6
|
-
boot:
|
|
9
|
+
boot: _boot
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
13
|
|
|
11
|
-
const stage =
|
|
14
|
+
const stage = await import('../src/index.js')
|
|
12
15
|
|
|
13
16
|
it('should be', () => {
|
|
14
|
-
|
|
17
|
+
assert.notStrictEqual(stage.component, undefined)
|
|
15
18
|
})
|
|
16
19
|
|
|
17
20
|
it('should boot component', async () => {
|
|
18
21
|
const path = generate()
|
|
19
22
|
const component = await stage.component(path)
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
assert.deepStrictEqual(mock.boot.manifest.mock.calls[0].arguments[0], path)
|
|
25
|
+
const manifest = await mock.boot.manifest.mock.calls[0].result
|
|
26
|
+
|
|
27
|
+
assert.ok(mock.boot.component.mock.calls.some((call) =>
|
|
28
|
+
call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], manifest)))
|
|
29
|
+
assert.deepStrictEqual(component, await mock.boot.component.mock.calls[0].result)
|
|
30
|
+
assert.ok(component.connect.mock.callCount() > 0)
|
|
25
31
|
})
|
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { generate } from 'randomstring'
|
|
5
|
+
import * as _boot from './boot.mock.js'
|
|
4
6
|
|
|
5
7
|
const mock = {
|
|
6
|
-
boot:
|
|
8
|
+
boot: _boot
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
12
|
|
|
11
|
-
const stage =
|
|
13
|
+
const stage = await import('../src/index.js')
|
|
12
14
|
|
|
13
15
|
const paths = [generate(), generate()]
|
|
14
16
|
|
|
15
17
|
it('should be', () => {
|
|
16
|
-
|
|
18
|
+
assert.notStrictEqual(stage.composition, undefined)
|
|
17
19
|
})
|
|
18
20
|
|
|
19
21
|
it('should boot composition', async () => {
|
|
20
22
|
await stage.composition(paths)
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
assert.deepStrictEqual(mock.boot.composition.mock.calls[0].arguments[0], paths)
|
|
23
25
|
|
|
24
|
-
const composition = await mock.boot.composition.mock.
|
|
26
|
+
const composition = await mock.boot.composition.mock.calls[0].result
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should override bindings', async () => {
|
|
30
|
-
await stage.composition(paths)
|
|
31
|
-
|
|
32
|
-
const path = require.resolve('../src/binding')
|
|
33
|
-
|
|
34
|
-
/** @type {toa.boot.composition.Options} */
|
|
35
|
-
const options = { bindings: [path] }
|
|
36
|
-
|
|
37
|
-
expect(mock.boot.composition.mock.calls[0][1]).toStrictEqual(options)
|
|
28
|
+
assert.ok(composition.connect.mock.callCount() > 0)
|
|
38
29
|
})
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
import { generate } from 'randomstring'
|
|
6
|
+
import * as _boot from './boot.mock.js'
|
|
4
7
|
|
|
5
8
|
const mock = {
|
|
6
|
-
boot:
|
|
9
|
+
boot: _boot
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
13
|
|
|
11
|
-
const stage =
|
|
14
|
+
const stage = await import('../src/index.js')
|
|
12
15
|
|
|
13
16
|
it('should be', () => {
|
|
14
|
-
|
|
17
|
+
assert.notStrictEqual(stage.manifest, undefined)
|
|
15
18
|
})
|
|
16
19
|
|
|
17
20
|
it('should boot manifest', async () => {
|
|
@@ -19,6 +22,6 @@ it('should boot manifest', async () => {
|
|
|
19
22
|
|
|
20
23
|
const manifest = await stage.manifest(path)
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
assert.ok(mock.boot.manifest.mock.calls.some((call) => call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], path)))
|
|
26
|
+
assert.deepStrictEqual(manifest, await mock.boot.manifest.mock.calls[0].result)
|
|
24
27
|
})
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, mock as mocking } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { generate } from 'randomstring'
|
|
5
|
+
import * as _boot from './boot.mock.js'
|
|
4
6
|
|
|
5
7
|
const mock = {
|
|
6
|
-
boot:
|
|
8
|
+
boot: _boot
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
mocking.module('@toa.io/boot', { namedExports: mock.boot })
|
|
10
12
|
|
|
11
|
-
const stage =
|
|
13
|
+
const stage = await import('../src/index.js')
|
|
12
14
|
|
|
13
15
|
it('should be', () => {
|
|
14
|
-
|
|
16
|
+
assert.notStrictEqual(stage.remote, undefined)
|
|
15
17
|
})
|
|
16
18
|
|
|
17
19
|
it('should connect remote', async () => {
|
|
@@ -21,12 +23,12 @@ it('should connect remote', async () => {
|
|
|
21
23
|
|
|
22
24
|
const remote = await stage.remote(id)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
assert.ok(mock.boot.remote.mock.callCount() > 0)
|
|
27
|
+
assert.deepStrictEqual(remote, await mock.boot.remote.mock.calls[0].result)
|
|
28
|
+
assert.ok(remote.connect.mock.callCount() > 0)
|
|
27
29
|
|
|
28
|
-
const locator = mock.boot.remote.mock.calls[0][0]
|
|
30
|
+
const locator = mock.boot.remote.mock.calls[0].arguments[0]
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
assert.notStrictEqual(locator, undefined)
|
|
33
|
+
assert.partialDeepStrictEqual(locator, { name, namespace })
|
|
32
34
|
})
|