656a821a94
Migrate expressions, workflow-parser, and languageservice packages to use proper ESM imports with .js extensions that work with node16 moduleResolution. Changes: - Update tsconfig.build.json in each package to use module: node16 and moduleResolution: node16 - Add .js extensions to all relative import paths (Option B approach) - Fix yaml internal type imports in workflow-parser by defining local types - Add skipLibCheck to handle @types/node compatibility issues - Add TypeScript 5.8.3 override in root package.json - Add ESM migration plan documentation The languageserver package is deferred due to test hang issues that need further investigation. Related #154 - Upgrade moduleResolution from node to node16 or nodenext Related #110 - Published ESM code has imports without file extensions Related #64 - expressions: ERR_MODULE_NOT_FOUND attempting to run example Related #146 - Can not import @actions/workflow-parser Test results: - expressions: 1068 tests passed - workflow-parser: 292 tests passed - languageservice: 452 tests passed * docs: update ESM migration plan with findings - Update languageserver blocker: vscode-languageserver v8.0.2 lacks ESM exports (not a test hang issue) - Document that Option B (manual .js extensions) was chosen over Option A due to ts-jest compatibility issues - Add workaround for yaml package internal types (LinePos, NodeBase) - Update migration status table with accurate reason for deferral - Add skipLibCheck note for @types/node compatibility
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import {TemplateValidationError} from "./templates/template-validation-error.js";
|
|
import {nullTrace} from "./test-utils/null-trace.js";
|
|
import {parseWorkflow} from "./workflows/workflow-parser.js";
|
|
|
|
describe("parseWorkflow", () => {
|
|
it("parses valid workflow", () => {
|
|
const result = parseWorkflow(
|
|
{
|
|
name: "test.yaml",
|
|
content: "on: push\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - run: echo 'hello'"
|
|
},
|
|
nullTrace
|
|
);
|
|
|
|
expect(result.context.errors.getErrors()).toHaveLength(0);
|
|
});
|
|
|
|
it("contains range for error", () => {
|
|
const result = parseWorkflow(
|
|
{
|
|
name: "test.yaml",
|
|
content: "on: push\njobs:\n build:\n steps:\n - run: echo 'hello'"
|
|
},
|
|
nullTrace
|
|
);
|
|
|
|
expect(result.context.errors.getErrors()).toEqual([
|
|
new TemplateValidationError("Required property is missing: runs-on", "test.yaml (Line: 4, Col: 5)", undefined, {
|
|
start: {line: 4, column: 5},
|
|
end: {line: 5, column: 24}
|
|
})
|
|
]);
|
|
});
|
|
|
|
it("error range for expression is constrained to scalar node", () => {
|
|
const result = parseWorkflow(
|
|
{
|
|
name: "test.yaml",
|
|
content: `on: push
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: \${{ github.event = 12 }}
|
|
run: echo 'hello'`
|
|
},
|
|
nullTrace
|
|
);
|
|
|
|
expect(result.context.errors.getErrors()).toEqual([
|
|
new TemplateValidationError(
|
|
"Unexpected symbol: '='. Located at position 14 within expression: github.event = 12",
|
|
"test.yaml (Line: 6, Col: 13)",
|
|
undefined,
|
|
{
|
|
start: {line: 6, column: 13},
|
|
end: {line: 6, column: 37}
|
|
}
|
|
)
|
|
]);
|
|
});
|
|
|
|
it("tokens contain descriptions", () => {
|
|
const result = parseWorkflow(
|
|
{
|
|
name: "test.yaml",
|
|
content:
|
|
"on: push\nname: hello\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - run: echo 'hello'"
|
|
},
|
|
nullTrace
|
|
);
|
|
|
|
expect(result.context.errors.getErrors()).toHaveLength(0);
|
|
expect(result.value).not.toBeUndefined();
|
|
const root = result.value!.assertMapping("root"); // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
expect(root.description).toBe("Workflow file with strict validation");
|
|
for (const pair of root) {
|
|
const key = pair.key.assertString("key").value;
|
|
switch (key) {
|
|
case "name": {
|
|
const nameKey = pair.key.assertString("name");
|
|
expect(nameKey.definition).not.toBeUndefined();
|
|
expect(nameKey.description).toContain("The name of the workflow");
|
|
break;
|
|
}
|
|
case "on": {
|
|
const onKey = pair.key.assertString("on");
|
|
const onValue = pair.value.assertString("push");
|
|
expect(onKey.definition).not.toBeUndefined();
|
|
expect(onKey.description).toContain("The GitHub event that triggers the workflow.");
|
|
expect(onValue.definition).not.toBeUndefined();
|
|
expect(onValue.description).toBe("Runs your workflow when you push a commit or tag.");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|