@platformatic/runtime 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +13 -0
- package/README.md +13 -0
- package/fixtures/configs/invalid-entrypoint.json +14 -0
- package/fixtures/configs/missing-property.config.json +13 -0
- package/fixtures/configs/missing-service-config.json +7 -0
- package/fixtures/configs/monorepo-composer.json +19 -0
- package/fixtures/configs/monorepo-create-cycle.json +21 -0
- package/fixtures/configs/monorepo-no-cycles.json +20 -0
- package/fixtures/configs/monorepo.json +20 -0
- package/fixtures/configs/no-services.config.json +5 -0
- package/fixtures/configs/no-sources.config.json +4 -0
- package/fixtures/configs/service-throws-on-start.json +11 -0
- package/fixtures/monorepo/composerApp/platformatic.composer.json +39 -0
- package/fixtures/monorepo/docs/README.md +1 -0
- package/fixtures/monorepo/serviceApp/deps/dep1.js +7 -0
- package/fixtures/monorepo/serviceApp/deps/dep2.mjs +2 -0
- package/fixtures/monorepo/serviceApp/deps/dep3.mjs +2 -0
- package/fixtures/monorepo/serviceApp/deps/dep4.js +1 -0
- package/fixtures/monorepo/serviceApp/platformatic.service.json +22 -0
- package/fixtures/monorepo/serviceApp/plugin.js +25 -0
- package/fixtures/monorepo/serviceApp/with-logger/package.json +5 -0
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.cjs +25 -0
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.d.ts +38 -0
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.openapi.json +22 -0
- package/fixtures/monorepo/serviceAppWithLogger/platformatic.service.json +19 -0
- package/fixtures/monorepo/serviceAppWithLogger/plugin.js +8 -0
- package/fixtures/monorepo/serviceAppWithMultiplePlugins/platformatic.service.json +26 -0
- package/fixtures/monorepo/serviceAppWithMultiplePlugins/plugin.js +8 -0
- package/fixtures/monorepo/serviceAppWithMultiplePlugins/plugin2.mjs +5 -0
- package/fixtures/serviceAppThrowsOnStart/platformatic.service.json +13 -0
- package/fixtures/serviceAppThrowsOnStart/plugin.js +6 -0
- package/help/help.txt +5 -0
- package/help/start.txt +5 -0
- package/index.d.ts +13 -0
- package/index.js +33 -0
- package/index.test-d.ts +18 -0
- package/lib/app.js +261 -0
- package/lib/config.js +209 -0
- package/lib/loader.mjs +101 -0
- package/lib/schema.js +89 -0
- package/lib/start.js +77 -0
- package/lib/worker.js +88 -0
- package/package.json +52 -0
- package/runtime.mjs +43 -0
- package/test/app.test.js +245 -0
- package/test/cli/helper.mjs +46 -0
- package/test/cli/start.test.mjs +61 -0
- package/test/cli/validations.test.mjs +52 -0
- package/test/cli/watch.test.mjs +131 -0
- package/test/config.test.js +58 -0
- package/test/schema.test.js +13 -0
- package/test/start.test.js +101 -0
- package/test/worker.test.js +21 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { test } from 'node:test'
|
|
4
|
+
import { join } from 'desm'
|
|
5
|
+
import { execa } from 'execa'
|
|
6
|
+
import { cliPath } from './helper.mjs'
|
|
7
|
+
|
|
8
|
+
const version = JSON.parse(await readFile(join(import.meta.url, '..', '..', 'package.json'))).version
|
|
9
|
+
|
|
10
|
+
test('version', async () => {
|
|
11
|
+
const { stdout } = await execa(process.execPath, [cliPath, '--version'])
|
|
12
|
+
|
|
13
|
+
assert.strictEqual(stdout.trim(), `v${version}`)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test('missing config', async () => {
|
|
17
|
+
await assert.rejects(execa(process.execPath, [cliPath, 'start']))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('no services specified by config', async () => {
|
|
21
|
+
const config = join(import.meta.url, '..', '..', 'fixtures', 'configs', 'no-services.config.json')
|
|
22
|
+
|
|
23
|
+
await assert.rejects(execa(process.execPath, [cliPath, 'start', '--config', config]))
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('no services or autoload specified by config', async () => {
|
|
27
|
+
const config = join(import.meta.url, '..', '..', 'fixtures', 'configs', 'no-sources.config.json')
|
|
28
|
+
|
|
29
|
+
await assert.rejects(execa(process.execPath, [cliPath, 'start', '--config', config]))
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('print validation errors', async () => {
|
|
33
|
+
let error
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const config = join(import.meta.url, '..', '..', 'fixtures', 'configs', 'missing-property.config.json')
|
|
37
|
+
|
|
38
|
+
await execa(process.execPath, [cliPath, 'start', '--config', config])
|
|
39
|
+
} catch (err) {
|
|
40
|
+
error = err
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
assert(error)
|
|
44
|
+
assert.strictEqual(error.exitCode, 1)
|
|
45
|
+
assert.strictEqual(error.stdout, `
|
|
46
|
+
┌─────────┬─────────────┬─────────────────────────────────────────────────────────────────┐
|
|
47
|
+
│ (index) │ path │ message │
|
|
48
|
+
├─────────┼─────────────┼─────────────────────────────────────────────────────────────────┤
|
|
49
|
+
│ 0 │ '/autoload' │ \`must have required property 'path' {"missingProperty":"path"}\` │
|
|
50
|
+
└─────────┴─────────────┴─────────────────────────────────────────────────────────────────┘
|
|
51
|
+
`.trim())
|
|
52
|
+
})
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { cp, writeFile, mkdtemp } from 'node:fs/promises'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { test } from 'node:test'
|
|
6
|
+
import { setTimeout as sleep } from 'node:timers/promises'
|
|
7
|
+
import desm from 'desm'
|
|
8
|
+
import { request } from 'undici'
|
|
9
|
+
import { start } from './helper.mjs'
|
|
10
|
+
const fixturesDir = join(desm(import.meta.url), '..', '..', 'fixtures')
|
|
11
|
+
const undiciPath = join(desm(import.meta.url), '..', '..', 'node_modules', 'undici')
|
|
12
|
+
|
|
13
|
+
function createCjsLoggingPlugin (text, reloaded) {
|
|
14
|
+
return `\
|
|
15
|
+
module.exports = async (app) => {
|
|
16
|
+
if (${reloaded}) {
|
|
17
|
+
app.log.info('RELOADED ' + '${text}')
|
|
18
|
+
}
|
|
19
|
+
app.get('/version', () => '${text}')
|
|
20
|
+
}
|
|
21
|
+
`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function createEsmLoggingPlugin (text, reloaded) {
|
|
25
|
+
return `\
|
|
26
|
+
import fs from 'fs' // No node: scheme. Coverage for the loader.
|
|
27
|
+
import dns from 'node:dns' // With node: scheme. Coverage for the loader.
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await import('./relative.mjs') // Relative path. Coverage for the loader.
|
|
31
|
+
} catch {
|
|
32
|
+
// Ignore err. File does not exist.
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default async function (app) {
|
|
36
|
+
if (${reloaded}) {
|
|
37
|
+
app.log.info('RELOADED ' + '${text}')
|
|
38
|
+
}
|
|
39
|
+
app.get('/version', () => '${text}')
|
|
40
|
+
}
|
|
41
|
+
`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
test('watches CommonJS files', async (t) => {
|
|
45
|
+
const tmpDir = await mkdtemp(join(tmpdir(), 'watch-'))
|
|
46
|
+
t.diagnostic(`using ${tmpDir}`)
|
|
47
|
+
const configFileSrc = join(fixturesDir, 'configs', 'monorepo.json')
|
|
48
|
+
const configFileDst = join(tmpDir, 'configs', 'monorepo.json')
|
|
49
|
+
const appSrc = join(fixturesDir, 'monorepo')
|
|
50
|
+
const appDst = join(tmpDir, 'monorepo')
|
|
51
|
+
const cjsPluginFilePath = join(appDst, 'serviceAppWithLogger', 'plugin.js')
|
|
52
|
+
|
|
53
|
+
await Promise.all([
|
|
54
|
+
cp(configFileSrc, configFileDst),
|
|
55
|
+
cp(appSrc, appDst, { recursive: true })
|
|
56
|
+
])
|
|
57
|
+
|
|
58
|
+
await cp(undiciPath, join(appDst, 'serviceApp', 'node_modules', 'undici'), { recursive: true })
|
|
59
|
+
|
|
60
|
+
await writeFile(cjsPluginFilePath, createCjsLoggingPlugin('v1', false))
|
|
61
|
+
const { child } = await start('-c', configFileDst)
|
|
62
|
+
t.after(() => child.kill('SIGINT'))
|
|
63
|
+
child.stdout.pipe(process.stderr)
|
|
64
|
+
child.stderr.pipe(process.stderr)
|
|
65
|
+
|
|
66
|
+
await writeFile(cjsPluginFilePath, createCjsLoggingPlugin('v2', true))
|
|
67
|
+
|
|
68
|
+
for await (const log of child.ndj) {
|
|
69
|
+
if (log.msg === 'RELOADED v2') {
|
|
70
|
+
break
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('watches ESM files', async (t) => {
|
|
76
|
+
const tmpDir = await mkdtemp(join(tmpdir(), 'watch-'))
|
|
77
|
+
t.diagnostic(`using ${tmpDir}`)
|
|
78
|
+
const configFileSrc = join(fixturesDir, 'configs', 'monorepo.json')
|
|
79
|
+
const configFileDst = join(tmpDir, 'configs', 'monorepo.json')
|
|
80
|
+
const appSrc = join(fixturesDir, 'monorepo')
|
|
81
|
+
const appDst = join(tmpDir, 'monorepo')
|
|
82
|
+
const esmPluginFilePath = join(appDst, 'serviceAppWithMultiplePlugins', 'plugin2.mjs')
|
|
83
|
+
|
|
84
|
+
await Promise.all([
|
|
85
|
+
cp(configFileSrc, configFileDst),
|
|
86
|
+
cp(appSrc, appDst, { recursive: true })
|
|
87
|
+
])
|
|
88
|
+
|
|
89
|
+
await cp(undiciPath, join(appDst, 'serviceApp', 'node_modules', 'undici'), { recursive: true })
|
|
90
|
+
|
|
91
|
+
await writeFile(esmPluginFilePath, createEsmLoggingPlugin('v1', false))
|
|
92
|
+
const { child } = await start('-c', configFileDst)
|
|
93
|
+
t.after(() => child.kill('SIGINT'))
|
|
94
|
+
child.stdout.pipe(process.stderr)
|
|
95
|
+
child.stderr.pipe(process.stderr)
|
|
96
|
+
await writeFile(esmPluginFilePath, createEsmLoggingPlugin('v2', true))
|
|
97
|
+
|
|
98
|
+
for await (const log of child.ndj) {
|
|
99
|
+
if (log.msg === 'RELOADED v2') {
|
|
100
|
+
break
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('should not hot reload files with `--hot-reload false', async (t) => {
|
|
106
|
+
const tmpDir = await mkdtemp(join(tmpdir(), 'watch-'))
|
|
107
|
+
t.diagnostic(`using ${tmpDir}`)
|
|
108
|
+
const configFileSrc = join(fixturesDir, 'configs', 'monorepo.json')
|
|
109
|
+
const configFileDst = join(tmpDir, 'configs', 'monorepo.json')
|
|
110
|
+
const appSrc = join(fixturesDir, 'monorepo')
|
|
111
|
+
const appDst = join(tmpDir, 'monorepo')
|
|
112
|
+
const cjsPluginFilePath = join(appDst, 'serviceApp', 'plugin.js')
|
|
113
|
+
|
|
114
|
+
await Promise.all([
|
|
115
|
+
cp(configFileSrc, configFileDst),
|
|
116
|
+
cp(appSrc, appDst, { recursive: true })
|
|
117
|
+
])
|
|
118
|
+
|
|
119
|
+
await cp(undiciPath, join(appDst, 'serviceApp', 'node_modules', 'undici'), { recursive: true })
|
|
120
|
+
|
|
121
|
+
await writeFile(cjsPluginFilePath, createCjsLoggingPlugin('v1', false))
|
|
122
|
+
const { child, url } = await start('-c', configFileDst, '--hot-reload', 'false')
|
|
123
|
+
t.after(() => child.kill('SIGINT'))
|
|
124
|
+
child.stdout.pipe(process.stderr)
|
|
125
|
+
child.stderr.pipe(process.stderr)
|
|
126
|
+
await writeFile(cjsPluginFilePath, createCjsLoggingPlugin('v2', true))
|
|
127
|
+
await sleep(5000)
|
|
128
|
+
const res = await request(`${url}/version`)
|
|
129
|
+
const version = await res.body.text()
|
|
130
|
+
assert.strictEqual(version, 'v1')
|
|
131
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert')
|
|
4
|
+
const { join } = require('node:path')
|
|
5
|
+
const { test } = require('node:test')
|
|
6
|
+
const { loadConfig } = require('@platformatic/service')
|
|
7
|
+
const { platformaticRuntime } = require('../lib/config')
|
|
8
|
+
const fixturesDir = join(__dirname, '..', 'fixtures')
|
|
9
|
+
|
|
10
|
+
test('throws if no entrypoint is found', async (t) => {
|
|
11
|
+
const configFile = join(fixturesDir, 'configs', 'invalid-entrypoint.json')
|
|
12
|
+
|
|
13
|
+
platformaticRuntime() // Coverage cheat.
|
|
14
|
+
|
|
15
|
+
await assert.rejects(async () => {
|
|
16
|
+
await loadConfig({}, ['-c', configFile], platformaticRuntime)
|
|
17
|
+
}, /invalid entrypoint: 'invalid' does not exist/)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('throws if a config file is not found for an individual service', async (t) => {
|
|
21
|
+
const configFile = join(fixturesDir, 'configs', 'missing-service-config.json')
|
|
22
|
+
|
|
23
|
+
await assert.rejects(async () => {
|
|
24
|
+
await loadConfig({}, ['-c', configFile], platformaticRuntime)
|
|
25
|
+
}, /no config file found for service 'docs'/)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('performs a topological sort on services depending on allowCycles', async (t) => {
|
|
29
|
+
await t.test('does not sort if allowCycles is true', async () => {
|
|
30
|
+
const configFile = join(fixturesDir, 'configs', 'monorepo.json')
|
|
31
|
+
const loaded = await loadConfig({}, ['-c', configFile], platformaticRuntime)
|
|
32
|
+
const services = loaded.configManager.current.services
|
|
33
|
+
|
|
34
|
+
assert.strictEqual(services.length, 3)
|
|
35
|
+
assert.strictEqual(services[0].id, 'serviceApp')
|
|
36
|
+
assert.strictEqual(services[1].id, 'with-logger')
|
|
37
|
+
assert.strictEqual(services[2].id, 'multi-plugin-service')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
await t.test('sorts if allowCycles is false', async () => {
|
|
41
|
+
const configFile = join(fixturesDir, 'configs', 'monorepo-no-cycles.json')
|
|
42
|
+
const loaded = await loadConfig({}, ['-c', configFile], platformaticRuntime)
|
|
43
|
+
const services = loaded.configManager.current.services
|
|
44
|
+
|
|
45
|
+
assert.strictEqual(services.length, 3)
|
|
46
|
+
assert.strictEqual(services[0].id, 'with-logger')
|
|
47
|
+
assert.strictEqual(services[1].id, 'serviceApp')
|
|
48
|
+
assert.strictEqual(services[2].id, 'multi-plugin-service')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
await t.test('throws if a cycle is present when not allowed', async () => {
|
|
52
|
+
const configFile = join(fixturesDir, 'configs', 'monorepo-create-cycle.json')
|
|
53
|
+
|
|
54
|
+
await assert.rejects(async () => {
|
|
55
|
+
await loadConfig({}, ['-c', configFile], platformaticRuntime)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert')
|
|
4
|
+
const { join } = require('node:path')
|
|
5
|
+
const { test } = require('node:test')
|
|
6
|
+
const { schema } = require('../lib/schema')
|
|
7
|
+
|
|
8
|
+
test('schema output', async (t) => {
|
|
9
|
+
const { execa } = await import('execa')
|
|
10
|
+
const { stdout } = await execa(process.execPath, [join(__dirname, '..', 'lib', 'schema.js')])
|
|
11
|
+
|
|
12
|
+
assert.deepStrictEqual(stdout, JSON.stringify(schema, null, 2))
|
|
13
|
+
})
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const assert = require('node:assert')
|
|
3
|
+
const { join } = require('node:path')
|
|
4
|
+
const { test } = require('node:test')
|
|
5
|
+
const { request } = require('undici')
|
|
6
|
+
const { loadConfig } = require('@platformatic/service')
|
|
7
|
+
const { buildServer, platformaticRuntime } = require('..')
|
|
8
|
+
const fixturesDir = join(__dirname, '..', 'fixtures')
|
|
9
|
+
|
|
10
|
+
test('can start applications programmatically from object', async (t) => {
|
|
11
|
+
const configFile = join(fixturesDir, 'configs', 'monorepo.json')
|
|
12
|
+
const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
|
|
13
|
+
const app = await buildServer(config.configManager.current)
|
|
14
|
+
const entryUrl = await app.start()
|
|
15
|
+
|
|
16
|
+
t.after(async () => {
|
|
17
|
+
await app.close()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const res = await request(entryUrl)
|
|
21
|
+
|
|
22
|
+
assert.strictEqual(res.statusCode, 200)
|
|
23
|
+
assert.deepStrictEqual(await res.body.json(), { hello: 'hello123' })
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('can start applications programmatically from string', async (t) => {
|
|
27
|
+
const configFile = join(fixturesDir, 'configs', 'monorepo.json')
|
|
28
|
+
const app = await buildServer(configFile)
|
|
29
|
+
const entryUrl = await app.start()
|
|
30
|
+
|
|
31
|
+
t.after(async () => {
|
|
32
|
+
await app.close()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
// Basic URL on the entrypoint.
|
|
37
|
+
const res = await request(entryUrl)
|
|
38
|
+
|
|
39
|
+
assert.strictEqual(res.statusCode, 200)
|
|
40
|
+
assert.deepStrictEqual(await res.body.json(), { hello: 'hello123' })
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
{
|
|
44
|
+
// URL on the entrypoint that uses internal message passing.
|
|
45
|
+
const res = await request(entryUrl + '/upstream')
|
|
46
|
+
|
|
47
|
+
assert.strictEqual(res.statusCode, 200)
|
|
48
|
+
assert.deepStrictEqual(await res.body.json(), { hello: 'world' })
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('composer', async (t) => {
|
|
53
|
+
const configFile = join(fixturesDir, 'configs', 'monorepo-composer.json')
|
|
54
|
+
const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
|
|
55
|
+
const app = await buildServer(config.configManager.current)
|
|
56
|
+
const entryUrl = await app.start()
|
|
57
|
+
|
|
58
|
+
t.after(async () => {
|
|
59
|
+
await app.close()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
{
|
|
63
|
+
const res = await request(entryUrl)
|
|
64
|
+
|
|
65
|
+
assert.strictEqual(res.statusCode, 200)
|
|
66
|
+
assert.deepStrictEqual(await res.body.json(), { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
const res = await request(entryUrl + '/service-app/')
|
|
71
|
+
|
|
72
|
+
assert.strictEqual(res.statusCode, 200)
|
|
73
|
+
assert.deepStrictEqual(await res.body.json(), { hello: 'hello123' })
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('can restart the runtime apps', async (t) => {
|
|
78
|
+
const configFile = join(fixturesDir, 'configs', 'monorepo.json')
|
|
79
|
+
const app = await buildServer(configFile)
|
|
80
|
+
const entryUrl = await app.start()
|
|
81
|
+
|
|
82
|
+
t.after(async () => {
|
|
83
|
+
await app.close()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
{
|
|
87
|
+
const res = await request(entryUrl + '/upstream')
|
|
88
|
+
|
|
89
|
+
assert.strictEqual(res.statusCode, 200)
|
|
90
|
+
assert.deepStrictEqual(await res.body.json(), { hello: 'world' })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
await app.restart()
|
|
94
|
+
|
|
95
|
+
{
|
|
96
|
+
const res = await request(entryUrl + '/upstream')
|
|
97
|
+
|
|
98
|
+
assert.strictEqual(res.statusCode, 200)
|
|
99
|
+
assert.deepStrictEqual(await res.body.json(), { hello: 'world' })
|
|
100
|
+
}
|
|
101
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert')
|
|
4
|
+
const { once } = require('node:events')
|
|
5
|
+
const { join } = require('node:path')
|
|
6
|
+
const { test } = require('node:test')
|
|
7
|
+
const { Worker } = require('node:worker_threads')
|
|
8
|
+
|
|
9
|
+
test('throws if unknown messages are received', async (t) => {
|
|
10
|
+
const workerFile = join(__dirname, '..', 'lib', 'worker.js')
|
|
11
|
+
const worker = new Worker(workerFile, {
|
|
12
|
+
execArgv: [],
|
|
13
|
+
workerData: { config: { services: [] } }
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const [msg] = await once(worker, 'message')
|
|
17
|
+
assert.strictEqual(msg, 'plt:init')
|
|
18
|
+
worker.postMessage({ msg: 'unknown-message-type' })
|
|
19
|
+
const [err] = await once(worker, 'error')
|
|
20
|
+
assert.strictEqual(err.message, 'unknown message type: \'unknown-message-type\'')
|
|
21
|
+
})
|