From ba37328d4ea95eaf8b3bd6c6cef308f709a5f2ec Mon Sep 17 00:00:00 2001 From: Zennon Gosalvez <1798166+zgosalvez@users.noreply.github.com> Date: Sun, 17 Dec 2023 09:20:14 +0800 Subject: [PATCH] Fixes tests (#137) --- test/fail.test.js | 26 ++++++++++++-------------- test/pass.test.js | 4 ++-- test/stub/unpinned/file.yaml | 5 ----- test/stub/unpinned/file2.yaml | 5 +++++ 4 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 test/stub/unpinned/file2.yaml diff --git a/test/fail.test.js b/test/fail.test.js index bc7116c..3f9c12e 100644 --- a/test/fail.test.js +++ b/test/fail.test.js @@ -12,30 +12,28 @@ jest.afterEach(() => { jest.test('action has empty error', () => { process.env[workflowsPath] = 'test/stub/empty'; + let result; try { - cp.execSync(`node ${ip}`, { env: process.env }).toString(); - - jest.expect(true).toBe(false); + throw cp.execSync(`node ${ip}`, { env: process.env }).toString(); } catch (error) { - const result = error.stdout.toString(); - - jest.expect(result).toContain('Cannot read properties of null (reading \'jobs\')'); - jest.expect(result).not.toContain('No issues were found.'); + result = (error.stdout || error).toString(); } + + jest.expect(result).toContain('Cannot read properties of null (reading \'jobs\')'); + jest.expect(result).not.toContain('No issues were found.'); }); jest.test('action has unpinned error', () => { process.env[workflowsPath] = 'test/stub/unpinned'; + let result; try { - cp.execSync(`node ${ip}`, { env: process.env }).toString(); - - jest.expect(true).toBe(false); + throw cp.execSync(`node ${ip}`, { env: process.env }).toString(); } catch (error) { - const result = error.stdout.toString(); - - jest.expect(result).toContain('actions/checkout@v1 is not pinned to a full length commit SHA.'); - jest.expect(result).not.toContain('No issues were found.'); + result = (error.stdout || error).toString(); } + + jest.expect(result).toContain('actions/checkout@v1 is not pinned to a full length commit SHA.'); + jest.expect(result).not.toContain('No issues were found.'); }); diff --git a/test/pass.test.js b/test/pass.test.js index bd43631..94f799c 100644 --- a/test/pass.test.js +++ b/test/pass.test.js @@ -21,9 +21,9 @@ jest.test('actions pass', () => { let result; try { - result = execSync(`node ${ip}`, { env: process.env }).toString(); + throw execSync(`node ${ip}`, { env: process.env }).toString(); } catch (error) { - throw Error(error.stdout.toString()); + result = (error.stdout || error).toString(); } jest.expect(result).not.toContain('::warning::'); diff --git a/test/stub/unpinned/file.yaml b/test/stub/unpinned/file.yaml index ae1a8a4..164e436 100644 --- a/test/stub/unpinned/file.yaml +++ b/test/stub/unpinned/file.yaml @@ -6,8 +6,3 @@ jobs: steps: - uses: docker://rhysd/actionlint:latest - uses: docker://rhysd/actionlint:1.6.22 - mixedstub: - steps: - - uses: actions/checkout@v1 - - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f - diff --git a/test/stub/unpinned/file2.yaml b/test/stub/unpinned/file2.yaml new file mode 100644 index 0000000..f56ef0c --- /dev/null +++ b/test/stub/unpinned/file2.yaml @@ -0,0 +1,5 @@ +jobs: + mixedstub: + steps: + - uses: actions/checkout@v1 + - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f