@twinsearth/dsh-2xray 0.1.0 → 0.2.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/CHANGELOG.md +19 -0
- package/README.md +18 -0
- package/index.js +24 -2
- package/lib/client.js +267 -0
- package/lib/config.js +17 -0
- package/lib/process.js +44 -1
- package/lib/schema.js +85 -0
- package/package.json +11 -3
- package/scripts/release-check.mjs +1 -1
- package/test/client.test.js +56 -0
- package/test/process.test.js +49 -0
- package/tools/jsQR.js +10102 -0
- package/tools/scanner.html +195 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { createLauncher, createLazyLauncher } from '../lib/process.js'
|
|
4
|
+
|
|
5
|
+
const logger = { warn() {} }
|
|
6
|
+
|
|
7
|
+
test('a context that guards service properties never throws at activation', () => {
|
|
8
|
+
const guarded = { get: () => undefined }
|
|
9
|
+
Object.defineProperty(guarded, 'subprocess', {
|
|
10
|
+
get() {
|
|
11
|
+
throw new Error('cannot get property "subprocess" without inject')
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
assert.doesNotThrow(() => createLauncher(guarded, { logger }))
|
|
15
|
+
assert.equal(createLauncher(guarded, { logger }).kind, 'child_process')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('ctx.get is used when it returns the service', () => {
|
|
19
|
+
const service = { spawn() {}, resolveExecutable() {} }
|
|
20
|
+
const ctx = { get: (name) => (name === 'subprocess' ? service : undefined) }
|
|
21
|
+
assert.equal(createLauncher(ctx, { logger }).kind, 'ctx.subprocess')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('a context without ctx.get falls back to child_process', () => {
|
|
25
|
+
assert.equal(createLauncher({}, { logger }).kind, 'child_process')
|
|
26
|
+
assert.equal(createLauncher(undefined, { logger }).kind, 'child_process')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('the lazy launcher resolves at first use, so a later-mounted service is seen', () => {
|
|
30
|
+
let service
|
|
31
|
+
const ctx = { get: () => service }
|
|
32
|
+
const lazy = createLazyLauncher(ctx, { logger })
|
|
33
|
+
service = {
|
|
34
|
+
spawn() {
|
|
35
|
+
return {
|
|
36
|
+
pid: 7,
|
|
37
|
+
done: Promise.resolve({ exitCode: 0, signal: null }),
|
|
38
|
+
terminate: async () => {},
|
|
39
|
+
waitForExit: async () => {},
|
|
40
|
+
collected: {},
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
resolveExecutable() {},
|
|
44
|
+
}
|
|
45
|
+
assert.equal(lazy.kind, 'ctx.subprocess')
|
|
46
|
+
const handle = lazy.spawn({ argv: ['x'], cwd: '.', graceMs: 1, env: {} })
|
|
47
|
+
assert.equal(handle.kind, 'ctx.subprocess')
|
|
48
|
+
assert.equal(handle.pid, 7)
|
|
49
|
+
})
|