Add tests for validation and completion

This commit is contained in:
Jacob Wallraff
2022-12-20 15:27:34 -08:00
parent 6d699a6d6b
commit fe0af4cc30
2 changed files with 84 additions and 0 deletions
@@ -749,6 +749,57 @@ jobs:
expect(result.map(x => x.label)).toEqual(["container", "services", "status"]);
});
it("job context is suggested within a job output", async () => {
const input = `
on: push
jobs:
test:
runs-on: ubuntu-latest
outputs:
environment: \${{ | }}
steps:
- id: a
run: echo hi
`;
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
expect(result.map(x => x.label)).toEqual([
"env",
"github",
"inputs",
"job",
"needs",
"runner",
"secrets",
"steps",
"vars",
"contains",
"endsWith",
"format",
"fromJson",
"join",
"startsWith",
"toJson",
]);
});
it("step context is suggested within a job output", async () => {
const input = `
on: push
jobs:
test:
runs-on: ubuntu-latest
outputs:
environment: \${{ steps.| }}
steps:
- id: foo
run: echo hi
`;
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
expect(result.map(x => x.label)).toEqual(["foo"]);
});
it("container context is suggested within a job container", async () => {
const input = `
on: push
@@ -190,6 +190,39 @@ jobs:
]);
});
it("reference of invalid step in job outputs", async () => {
const input = `
on: push
jobs:
a:
outputs:
environment: \${{ steps.foo }}
runs-on: ubuntu-latest
steps:
- id: a
run: echo hello a
`;
const result = await validate(createDocument("wf.yaml", input));
expect(result).toEqual([
{
"message": "Context access might be invalid: foo",
"range": {
"end": {
"character": 41,
"line": 5,
},
"start": {
"character": 25,
"line": 5,
},
},
"severity": 2,
},
]);
});
it("invalid reference of generated step name", async () => {
const input = `
on: push