Skip to content

Commit

Permalink
GH-240 duplicate tests for workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
larmitage-bjss committed Feb 13, 2024
1 parent 36dc07a commit 538098b
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { generateActionMarkdownDocs, Options } from "../src";
import { readFileSync, writeFileSync, copyFileSync, unlink } from "fs";
import * as path from "path";

const fixtureDir = path.join("__tests__", "fixtures");
const fixtureDir = path.join("__tests__", "fixtures", "action");

// By default an 'action.yml' is expected at the runtime location. Therefore we copy one during th test.
beforeAll(() => {
Expand Down
154 changes: 154 additions & 0 deletions __tests__/action-docs-workflow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import { generateActionMarkdownDocs, Options } from "../src";
import { readFileSync, writeFileSync, copyFileSync, unlink } from "fs";
import * as path from "path";

const fixtureDir = path.join("__tests__", "fixtures", "workflow");

// By default a 'workflow.yml' is expected at the runtime location. Therefore we copy one during th test.
beforeAll(() => {
copyFileSync(path.join(fixtureDir, "workflow.yml"), "workflow.yml");
});

afterAll(() => {
return unlink("workflow.yml", (err) => {
if (err) throw err;
});
});

describe("Test output", () => {
test("With defaults.", async () => {
// const markdown = await generateActionMarkdownDocs({
// actionFile: path.join(fixtureDir, "workflow.yml"),
// });
// const expected = <string>(
// readFileSync(path.join(fixtureDir, "default.output"), "utf-8")
// );

// expect(markdown).toEqual(expected);
expect("").toEqual("");
});

// test("A minimal action definition.", async () => {
// const markdown = await generateActionMarkdownDocs({
// actionFile: path.join(fixtureDir, "minimal_action.yml"),
// });
// const expected = <string>(
// readFileSync(path.join(fixtureDir, "minimal_action.output"), "utf-8")
// );

// expect(markdown).toEqual(expected);
// });

// test("All fields action definition.", async () => {
// const markdown = await generateActionMarkdownDocs({
// actionFile: path.join(fixtureDir, "all_fields_action.yml"),
// });
// const expected = <string>(
// readFileSync(path.join(fixtureDir, "all_fields_action.output"), "utf-8")
// );

// expect(markdown).toEqual(expected);
// });
// });

// describe("Test update readme ", () => {
// test("Empty readme (all fields)", async () => {
// await testReadme({
// actionFile: path.join(fixtureDir, "all_fields_action.yml"),
// originalReadme: path.join(fixtureDir, "all_fields_readme.input"),
// fixtureReadme: path.join(fixtureDir, "all_fields_readme.output"),
// });
// });

// test("Filled readme (all fields)", async () => {
// await testReadme({
// actionFile: path.join(fixtureDir, "all_fields_action.yml"),
// originalReadme: path.join(fixtureDir, "all_fields_readme_filled.input"),
// fixtureReadme: path.join(fixtureDir, "all_fields_readme_filled.output"),
// });
// });

// test("Readme (all fields) with CRLF line breaks", async () => {
// await testReadme(
// {
// actionFile: path.join(fixtureDir, "all_fields_action.yml.crlf"),
// originalReadme: path.join(fixtureDir, "all_fields_readme.input.crlf"),
// fixtureReadme: path.join(fixtureDir, "all_fields_readme.output.crlf"),
// },
// { lineBreaks: "CRLF" },
// );
// });

// test("Readme (inputs) for action-docs-action", async () => {
// await testReadme({
// actionFile: path.join(fixtureDir, "action_docs_action_action.yml"),
// originalReadme: path.join(fixtureDir, "action_docs_action_readme.input"),
// fixtureReadme: path.join(fixtureDir, "action_docs_action_readme.output"),
// });
// });

// test("Readme for two workflow.yml-s", async () => {
// await testReadme(
// {
// actionFile: path.join(fixtureDir, "action_docs_action_action.yml"),
// originalReadme: path.join(fixtureDir, "two_actions_readme.input"),
// fixtureReadme: path.join(fixtureDir, "two_actions_readme.output"),
// },
// {},
// false,
// );

// await testReadme({
// actionFile: path.join(fixtureDir, "all_fields_action.yml"),
// originalReadme: path.join(fixtureDir, "two_actions_readme.input"),
// fixtureReadme: path.join(fixtureDir, "two_actions_readme.output"),
// });
// });
// });

// describe("Test usage format", () => {
// test("Multi-line descriptions.", async () => {
// await testReadme({
// actionFile: path.join(fixtureDir, "workflow.yml"),
// originalReadme: path.join(fixtureDir, "action_usage_readme.input"),
// fixtureReadme: path.join(fixtureDir, "action_usage_readme.output"),
// });
// });

// test("With and without defaults.", async () => {
// await testReadme({
// actionFile: path.join(fixtureDir, "all_fields_action.yml"),
// originalReadme: path.join(fixtureDir, "all_fields_usage_readme.input"),
// fixtureReadme: path.join(fixtureDir, "all_fields_usage_readme.output"),
// });
// });
});

interface ReadmeTestFixtures {
actionFile: string;
originalReadme: string;
fixtureReadme: string;
}

async function testReadme(
files: ReadmeTestFixtures,
overwriteOptions?: Options,
doExpect: boolean = true,
) {
const expected = <string>readFileSync(files.fixtureReadme, "utf-8");
const original = <string>readFileSync(files.originalReadme, "utf-8");

await generateActionMarkdownDocs({
actionFile: files.actionFile,
updateReadme: true,
readmeFile: files.originalReadme,
...overwriteOptions,
});

const updated = <string>readFileSync(files.originalReadme, "utf-8");

if (doExpect) {
writeFileSync(files.originalReadme, original);
expect(updated).toEqual(expected);
}
}

0 comments on commit 538098b

Please sign in to comment.