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
98 lines
3.6 KiB
TypeScript
98 lines
3.6 KiB
TypeScript
import {DescriptionDictionary} from "@actions/expressions";
|
|
import {WorkflowContext} from "../context/workflow-context.js";
|
|
import {getContext, Mode} from "./default.js";
|
|
|
|
describe("getContext", () => {
|
|
const emptyWorkflowContext: WorkflowContext = {
|
|
uri: "test.yaml",
|
|
template: undefined
|
|
};
|
|
|
|
describe("when no contextProviderConfig is provided", () => {
|
|
it("should mark secrets context as incomplete", async () => {
|
|
const result = await getContext(["secrets"], undefined, emptyWorkflowContext, Mode.Validation);
|
|
|
|
const secretsContext = result.get("secrets") as DescriptionDictionary;
|
|
expect(secretsContext).toBeDefined();
|
|
expect(secretsContext.complete).toBe(false);
|
|
});
|
|
|
|
it("should mark vars context as incomplete", async () => {
|
|
const result = await getContext(["vars"], undefined, emptyWorkflowContext, Mode.Validation);
|
|
|
|
const varsContext = result.get("vars") as DescriptionDictionary;
|
|
expect(varsContext).toBeDefined();
|
|
expect(varsContext.complete).toBe(false);
|
|
});
|
|
|
|
it("should not mark other contexts as incomplete", async () => {
|
|
const result = await getContext(["env", "github"], undefined, emptyWorkflowContext, Mode.Validation);
|
|
|
|
const envContext = result.get("env") as DescriptionDictionary;
|
|
const githubContext = result.get("github") as DescriptionDictionary;
|
|
|
|
// These contexts are derived from the workflow file, so they can be complete
|
|
expect(envContext).toBeDefined();
|
|
expect(envContext.complete).toBe(true);
|
|
expect(githubContext).toBeDefined();
|
|
expect(githubContext.complete).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("when contextProviderConfig returns a value", () => {
|
|
it("should use the provided context for secrets", async () => {
|
|
const providedContext = new DescriptionDictionary();
|
|
providedContext.complete = true; // Provider fetched from API, so it's complete
|
|
|
|
const config = {
|
|
getContext: () => Promise.resolve(providedContext)
|
|
};
|
|
|
|
const result = await getContext(["secrets"], config, emptyWorkflowContext, Mode.Validation);
|
|
|
|
const secretsContext = result.get("secrets");
|
|
expect(secretsContext).toBe(providedContext);
|
|
expect((secretsContext as DescriptionDictionary).complete).toBe(true);
|
|
});
|
|
|
|
it("should use the provided context for vars", async () => {
|
|
const providedContext = new DescriptionDictionary();
|
|
providedContext.complete = true;
|
|
|
|
const config = {
|
|
getContext: () => Promise.resolve(providedContext)
|
|
};
|
|
|
|
const result = await getContext(["vars"], config, emptyWorkflowContext, Mode.Validation);
|
|
|
|
const varsContext = result.get("vars");
|
|
expect(varsContext).toBe(providedContext);
|
|
expect((varsContext as DescriptionDictionary).complete).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("when contextProviderConfig returns undefined", () => {
|
|
it("should mark secrets as incomplete", async () => {
|
|
const config = {
|
|
getContext: () => Promise.resolve(undefined)
|
|
};
|
|
|
|
const result = await getContext(["secrets"], config, emptyWorkflowContext, Mode.Validation);
|
|
|
|
const secretsContext = result.get("secrets") as DescriptionDictionary;
|
|
expect(secretsContext.complete).toBe(false);
|
|
});
|
|
|
|
it("should mark vars as incomplete", async () => {
|
|
const config = {
|
|
getContext: () => Promise.resolve(undefined)
|
|
};
|
|
|
|
const result = await getContext(["vars"], config, emptyWorkflowContext, Mode.Validation);
|
|
|
|
const varsContext = result.get("vars") as DescriptionDictionary;
|
|
expect(varsContext.complete).toBe(false);
|
|
});
|
|
});
|
|
});
|