"use strict"; // The declarations tracked in dist/: what a TypeScript consumer compiles against. const { test } = require("node:test"); const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); const { ActionMapping, AlexaActions, AlexaStatusMessage, EndpointHealth } = require("../dist/index.js"); const DIST = path.join(__dirname, "..", "dist"); const MODULES = [ "index", "Alex2Node", "Device", "AlexaInterface", "AlexaStatusMessage", "AlexaErrorResponse", "ActionMapping", "DisplayCategory", ]; const declaration = (name) => fs.readFileSync(path.join(DIST, `${name}.d.ts`), "utf8"); test("1.5.2 typings: dist ships declarations, ActionMapping's payload is optional, addHealthProp takes the enum or the string", () => { for (const name of MODULES) assert.ok(fs.existsSync(path.join(DIST, `${name}.d.ts`)), `dist/${name}.d.ts`); // The declaration text itself: a revert in src/ would rebuild narrower types, and the runtime checks below would // not notice. assert.match(declaration("ActionMapping"), /constructor\(actions: AlexaActions\[\], directiveName: string, directivePayload\?: string\);/); assert.match(declaration("AlexaStatusMessage"), /addHealthProp\(health: EndpointHealth \| `\$\{EndpointHealth\}`, uncertaintyInMs\?: number\): this;/); assert.match(declaration("AlexaInterface"), /addSupportedModes\(modes: Array\): void;/); assert.match(declaration("index"), /export type \{ SupportedMode \} from "\.\/AlexaInterface";/); assert.deepEqual(new ActionMapping([AlexaActions.Close], "TurnOn").toJSON(), { "@type": "ActionsToDirective", actions: ["Alexa.Actions.Close"], directive: { name: "TurnOn" }, }); const health = (h) => { const message = new AlexaStatusMessage("ct", "root", "e", null).addHealthProp(h).toJSON(); return message.context.properties[0].value; }; assert.deepEqual(health(EndpointHealth.OK), { value: "OK" }); assert.deepEqual(health("UNREACHABLE"), { value: "UNREACHABLE" }); });