Files
pipelines/web/test/stageDefinition.test.mjs
T

24 lines
1.1 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { stageSource } from "../src/stageDefinition.js";
test("source slices preserve authored CRLF, whitespace, custom blocks and shorthand", () => {
const first = " # stage one\r\n\r\n```custom\r\nhello\r\n```\r\n```edges\r\nsuccess -> #\r\n```\r\n\r\n";
const last = "# stage two\r\n```prompt\r\nlast\r\n```";
assert.equal(stageSource(first + last, "one"), first);
assert.equal(stageSource(first + last, "two"), last);
});
test("stage-like lines inside blocks do not terminate or create source ranges", () => {
const source = "# stage one\n```prompt\n# stage two\n```js\ntext\n```\n\n";
assert.equal(stageSource(source + "# stage two\n", "one"), source);
assert.equal(stageSource(source, "two"), null);
});
test("missing source, absent stages and terminals never produce guessed definitions", () => {
for (const source of [undefined, null, "", "# stage one\n"]) {
assert.equal(stageSource(source, "missing"), null);
assert.equal(stageSource(source, "#success"), null);
}
});