|
1 | 1 | import { generateActionMarkdownDocs, Options } from "../src"; |
2 | | -import { readFileSync, writeFileSync } from "fs"; |
| 2 | +import { readFileSync, writeFileSync, copyFileSync, rmSync, unlink } from "fs"; |
| 3 | +import * as path from "path"; |
3 | 4 | import { option } from "yargs"; |
4 | 5 |
|
5 | | -test("With defaults.", async () => { |
6 | | - const markdown = await generateActionMarkdownDocs(); |
7 | | - const expected = <string>( |
8 | | - readFileSync("__tests__/fixtures/default.output", "utf-8") |
9 | | - ); |
| 6 | +const fixtureDir = path.join("__tests__", "fixtures"); |
10 | 7 |
|
11 | | - expect(markdown).toEqual(expected); |
| 8 | +// By default an 'action.yml' is expected at the runtime location. Therefore we copy one during th test. |
| 9 | +beforeAll(() => { |
| 10 | + copyFileSync(path.join(fixtureDir, "action.yml"), "action.yml"); |
12 | 11 | }); |
13 | 12 |
|
14 | | -test("A minimal action definition.", async () => { |
15 | | - const markdown = await generateActionMarkdownDocs({ |
16 | | - actionFile: "__tests__/fixtures/minimal_action.yml", |
| 13 | +afterAll(() => { |
| 14 | + return unlink("action.yml", (err) => { |
| 15 | + if (err) throw err; |
17 | 16 | }); |
18 | | - const expected = <string>( |
19 | | - readFileSync("__tests__/fixtures/minimal_action.output", "utf-8") |
20 | | - ); |
21 | | - |
22 | | - expect(markdown).toEqual(expected); |
23 | 17 | }); |
24 | 18 |
|
25 | | -test("All fields action definition.", async () => { |
26 | | - const markdown = await generateActionMarkdownDocs({ |
27 | | - actionFile: "__tests__/fixtures/all_fields_action.yml", |
| 19 | +describe("Test output", () => { |
| 20 | + test("With defaults.", async () => { |
| 21 | + const markdown = await generateActionMarkdownDocs(); |
| 22 | + const expected = <string>( |
| 23 | + readFileSync(path.join(fixtureDir, "default.output"), "utf-8") |
| 24 | + ); |
| 25 | + |
| 26 | + expect(markdown).toEqual(expected); |
28 | 27 | }); |
29 | | - const expected = <string>( |
30 | | - readFileSync("__tests__/fixtures/all_fields_action.output", "utf-8") |
31 | | - ); |
32 | 28 |
|
33 | | - expect(markdown).toEqual(expected); |
34 | | -}); |
| 29 | + test("A minimal action definition.", async () => { |
| 30 | + const markdown = await generateActionMarkdownDocs({ |
| 31 | + actionFile: path.join(fixtureDir, "minimal_action.yml"), |
| 32 | + }); |
| 33 | + const expected = <string>( |
| 34 | + readFileSync(path.join(fixtureDir, "minimal_action.output"), "utf-8") |
| 35 | + ); |
35 | 36 |
|
36 | | -test("Update empty readme (all fields)", async () => { |
37 | | - await testReadme( |
38 | | - "__tests__/fixtures/all_fields_action.yml", |
39 | | - "__tests__/fixtures/all_fields_readme.input", |
40 | | - "__tests__/fixtures/all_fields_readme.output" |
41 | | - ); |
42 | | -}); |
| 37 | + expect(markdown).toEqual(expected); |
| 38 | + }); |
| 39 | + |
| 40 | + test("All fields action definition.", async () => { |
| 41 | + const markdown = await generateActionMarkdownDocs({ |
| 42 | + actionFile: path.join(fixtureDir, "all_fields_action.yml"), |
| 43 | + }); |
| 44 | + const expected = <string>( |
| 45 | + readFileSync(path.join(fixtureDir, "all_fields_action.output"), "utf-8") |
| 46 | + ); |
43 | 47 |
|
44 | | -test("Update filled readme (all fields)", async () => { |
45 | | - await testReadme( |
46 | | - "__tests__/fixtures/all_fields_action.yml", |
47 | | - "__tests__/fixtures/all_fields_readme_filled.input", |
48 | | - "__tests__/fixtures/all_fields_readme_filled.output" |
49 | | - ); |
| 48 | + expect(markdown).toEqual(expected); |
| 49 | + }); |
50 | 50 | }); |
51 | 51 |
|
52 | | -test("Update readme (all fields) CRLF", async () => { |
53 | | - await testReadme( |
54 | | - "__tests__/fixtures/all_fields_action.yml.crlf", |
55 | | - "__tests__/fixtures/all_fields_readme.input.crlf", |
56 | | - "__tests__/fixtures/all_fields_readme.output.crlf", |
57 | | - { lineBreaks: "CRLF" } |
58 | | - ); |
| 52 | +describe("Test update readme ", () => { |
| 53 | + test("Empty readme (all fields)", async () => { |
| 54 | + await testReadme({ |
| 55 | + actionFile: path.join(fixtureDir, "all_fields_action.yml"), |
| 56 | + originalReadme: path.join(fixtureDir, "all_fields_readme.input"), |
| 57 | + fixtureReadme: path.join(fixtureDir, "all_fields_readme.output"), |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + test("Filled readme (all fields)", async () => { |
| 62 | + await testReadme({ |
| 63 | + actionFile: path.join(fixtureDir, "all_fields_action.yml"), |
| 64 | + originalReadme: path.join(fixtureDir, "all_fields_readme_filled.input"), |
| 65 | + fixtureReadme: path.join(fixtureDir, "all_fields_readme_filled.output"), |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + test("Readme (all fields) with CRLF line breaks", async () => { |
| 70 | + await testReadme( |
| 71 | + { |
| 72 | + actionFile: path.join(fixtureDir, "all_fields_action.yml.crlf"), |
| 73 | + originalReadme: path.join(fixtureDir, "all_fields_readme.input.crlf"), |
| 74 | + fixtureReadme: path.join(fixtureDir, "all_fields_readme.output.crlf"), |
| 75 | + }, |
| 76 | + { lineBreaks: "CRLF" } |
| 77 | + ); |
| 78 | + }); |
59 | 79 | }); |
60 | 80 |
|
| 81 | +interface ReadmeTestFixtures { |
| 82 | + actionFile: string; |
| 83 | + originalReadme: string; |
| 84 | + fixtureReadme: string; |
| 85 | +} |
| 86 | + |
61 | 87 | async function testReadme( |
62 | | - actionFile: string, |
63 | | - originalReadme: string, |
64 | | - fixtureReadme: string, |
| 88 | + files: ReadmeTestFixtures, |
65 | 89 | overwriteOptions?: Options |
66 | 90 | ) { |
67 | | - const expected = <string>readFileSync(fixtureReadme, "utf-8"); |
68 | | - const original = <string>readFileSync(originalReadme, "utf-8"); |
| 91 | + const expected = <string>readFileSync(files.fixtureReadme, "utf-8"); |
| 92 | + const original = <string>readFileSync(files.originalReadme, "utf-8"); |
69 | 93 |
|
70 | 94 | await generateActionMarkdownDocs({ |
71 | | - actionFile: actionFile, |
| 95 | + actionFile: files.actionFile, |
72 | 96 | updateReadme: true, |
73 | | - readmeFile: originalReadme, |
| 97 | + readmeFile: files.originalReadme, |
74 | 98 | ...overwriteOptions, |
75 | 99 | }); |
76 | 100 |
|
77 | | - const updated = <string>readFileSync(originalReadme, "utf-8"); |
| 101 | + const updated = <string>readFileSync(files.originalReadme, "utf-8"); |
78 | 102 |
|
79 | | - writeFileSync(originalReadme, original); |
| 103 | + writeFileSync(files.originalReadme, original); |
80 | 104 | expect(updated).toEqual(expected); |
81 | 105 | } |
0 commit comments