QML's JS engine does not support ES module export/import syntax. Replace bare export with a CommonJS guard that only runs under Node.js, so the plugin loads in QML while tests still work.
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
import { test } from "node:test"
|
|
import assert from "node:assert"
|
|
import lib from "../tailscalectl/lib.js"
|
|
const { parsePeers, makeExitNodeCommand } = lib
|
|
|
|
test("parsePeers extracts exitNode from ExitNodeOption", () => {
|
|
const peerMap = {
|
|
"peer-1": {
|
|
HostName: "router",
|
|
TailscaleIPs: ["100.64.0.1"],
|
|
Online: true,
|
|
ExitNodeOption: true
|
|
},
|
|
"peer-2": {
|
|
HostName: "laptop",
|
|
TailscaleIPs: ["100.64.0.2"],
|
|
Online: true,
|
|
ExitNodeOption: false
|
|
}
|
|
}
|
|
|
|
const peers = parsePeers(peerMap)
|
|
|
|
assert.strictEqual(peers[0].exitNode, true)
|
|
assert.strictEqual(peers[1].exitNode, false)
|
|
})
|
|
|
|
test("makeExitNodeCommand returns tailscale set command for hostname", () => {
|
|
const cmd = makeExitNodeCommand("router")
|
|
assert.deepStrictEqual(cmd, ["tailscale", "set", "--exit-node=router"])
|
|
})
|
|
|
|
test("makeExitNodeCommand with empty string clears exit node", () => {
|
|
const cmd = makeExitNodeCommand("")
|
|
assert.deepStrictEqual(cmd, ["tailscale", "set", "--exit-node="])
|
|
})
|