From 5011bef7b40a1a729ada535086e59ddcc0c5032d Mon Sep 17 00:00:00 2001 From: Marvin Pinto Date: Wed, 9 Sep 2020 17:10:45 -0400 Subject: [PATCH] test: update the automatic-releases tests to work with the core mock --- __mocks__/@actions/core.js | 2 ++ .../__tests__/automaticReleases.test.ts | 24 +++++++++++-------- .../__tests__/taggedReleases.test.ts | 10 ++++---- packages/aws-ssm-secrets/README.md | 7 +++--- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/__mocks__/@actions/core.js b/__mocks__/@actions/core.js index e358bf04..c01a149c 100644 --- a/__mocks__/@actions/core.js +++ b/__mocks__/@actions/core.js @@ -4,4 +4,6 @@ module.exports = { ...core, setSecret: jest.fn(), exportVariable: jest.fn(), + setOutput: jest.fn(), + setFailed: jest.fn(), }; diff --git a/packages/automatic-releases/__tests__/automaticReleases.test.ts b/packages/automatic-releases/__tests__/automaticReleases.test.ts index 896b9885..2599ca88 100644 --- a/packages/automatic-releases/__tests__/automaticReleases.test.ts +++ b/packages/automatic-releases/__tests__/automaticReleases.test.ts @@ -4,6 +4,7 @@ import nock from 'nock'; import fs from 'fs'; import {uploadReleaseArtifacts} from '../src/uploadReleaseArtifacts'; import {main} from '../src/main'; +import * as core from '@actions/core'; jest.mock('../src/uploadReleaseArtifacts'); @@ -18,7 +19,7 @@ describe('main handler processing automatic releases', () => { const testInputFiles = 'file1.txt\nfile2.txt\n*.jar\n\n'; beforeEach(() => { - jest.resetModules(); + jest.clearAllMocks(); nock.disableNetConnect(); process.env['INPUT_REPO_TOKEN'] = testGhToken; process.env['INPUT_AUTOMATIC_RELEASE_TAG'] = testInputAutomaticReleaseTag; @@ -40,7 +41,6 @@ describe('main handler processing automatic releases', () => { }); afterEach(() => { - jest.clearAllMocks(); nock.cleanAll(); nock.enableNetConnect(); delete process.env['AUTOMATIC_RELEASES_TAG']; @@ -106,9 +106,6 @@ describe('main handler processing automatic releases', () => { upload_url: releaseUploadUrl, // eslint-disable-line @typescript-eslint/camelcase }); - // Output env variable should be empty - expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined(); - await main(); expect(createRef.isDone()).toBe(true); @@ -125,7 +122,12 @@ describe('main handler processing automatic releases', () => { expect(uploadReleaseArtifacts.mock.calls[0][2]).toEqual([]); // Should populate the output env variable - expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe(testInputAutomaticReleaseTag); + expect(core.exportVariable).toHaveBeenCalledTimes(1); + expect(core.exportVariable).toHaveBeenCalledWith('AUTOMATIC_RELEASES_TAG', testInputAutomaticReleaseTag); + + // Should output the releasetag + expect(core.setOutput).toHaveBeenCalledTimes(1); + expect(core.setOutput).toHaveBeenCalledWith('automatic_releases_tag', testInputAutomaticReleaseTag); }); it('should update an existing release tag', async () => { @@ -197,9 +199,6 @@ describe('main handler processing automatic releases', () => { upload_url: releaseUploadUrl, // eslint-disable-line @typescript-eslint/camelcase }); - // Output env variable should be empty - expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined(); - await main(); expect(createRef.isDone()).toBe(true); @@ -216,6 +215,11 @@ describe('main handler processing automatic releases', () => { expect(uploadReleaseArtifacts.mock.calls[0][2]).toEqual(['file1.txt', 'file2.txt', '*.jar']); // Should populate the output env variable - expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe(testInputAutomaticReleaseTag); + expect(core.exportVariable).toHaveBeenCalledTimes(1); + expect(core.exportVariable).toHaveBeenCalledWith('AUTOMATIC_RELEASES_TAG', testInputAutomaticReleaseTag); + + // Should output the releasetag + expect(core.setOutput).toHaveBeenCalledTimes(1); + expect(core.setOutput).toHaveBeenCalledWith('automatic_releases_tag', testInputAutomaticReleaseTag); }); }); diff --git a/packages/automatic-releases/__tests__/taggedReleases.test.ts b/packages/automatic-releases/__tests__/taggedReleases.test.ts index 9bda0d10..d2953b25 100644 --- a/packages/automatic-releases/__tests__/taggedReleases.test.ts +++ b/packages/automatic-releases/__tests__/taggedReleases.test.ts @@ -6,6 +6,7 @@ import nock from 'nock'; import fs from 'fs'; import {uploadReleaseArtifacts} from '../src/uploadReleaseArtifacts'; import {main} from '../src/main'; +import * as core from '@actions/core'; jest.mock('../src/uploadReleaseArtifacts'); @@ -18,7 +19,7 @@ describe('main handler processing tagged releases', () => { const testInputFiles = 'file1.txt\nfile2.txt\n*.jar\n\n'; beforeEach(() => { - jest.resetModules(); + jest.clearAllMocks(); nock.disableNetConnect(); process.env['INPUT_REPO_TOKEN'] = testGhToken; process.env['INPUT_DRAFT'] = testInputDraft.toString(); @@ -38,7 +39,6 @@ describe('main handler processing tagged releases', () => { }); afterEach(() => { - jest.clearAllMocks(); nock.cleanAll(); nock.enableNetConnect(); delete process.env['AUTOMATIC_RELEASES_TAG']; @@ -118,9 +118,6 @@ describe('main handler processing tagged releases', () => { upload_url: releaseUploadUrl, }); - // Output env variable should be empty - expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined(); - await main(); expect(getCommitsSinceRelease.isDone()).toBe(true); @@ -133,6 +130,7 @@ describe('main handler processing tagged releases', () => { expect(uploadReleaseArtifacts.mock.calls[0][2]).toEqual(['file1.txt', 'file2.txt', '*.jar']); // Should populate the output env variable - expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe('v0.0.1'); + expect(core.exportVariable).toHaveBeenCalledTimes(1); + expect(core.exportVariable).toHaveBeenCalledWith('AUTOMATIC_RELEASES_TAG', 'v0.0.1'); }); }); diff --git a/packages/aws-ssm-secrets/README.md b/packages/aws-ssm-secrets/README.md index eac3d06b..1c4dfe1c 100644 --- a/packages/aws-ssm-secrets/README.md +++ b/packages/aws-ssm-secrets/README.md @@ -62,9 +62,10 @@ jobs: ## Supported Parameters -| Parameter | Description | Default | -| ---------------- | -------------------------------------------------------------------------------------------------------- | ------- | -| `parameters`\*\* | A mapped object consisting of an environment variable (to set), and its corresponding AWS SSM parameter. | `null` | +| Parameter | Description | Default | +| ----------------------- | -------------------------------------------------------------------- | ------- | +| `ssm_parameter`\*\* | The AWS SSM parameter key to look up. | `null` | +| `env_variable_name`\*\* | The corresponding environment variable name to assign the secret to. | `null` | ### Notes: