Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
test: update the automatic-releases tests to work with the core mock
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinpinto committed Sep 9, 2020
1 parent f4b98c0 commit 5011bef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions __mocks__/@actions/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ module.exports = {
...core,
setSecret: jest.fn(),
exportVariable: jest.fn(),
setOutput: jest.fn(),
setFailed: jest.fn(),
};
24 changes: 14 additions & 10 deletions packages/automatic-releases/__tests__/automaticReleases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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;
Expand All @@ -40,7 +41,6 @@ describe('main handler processing automatic releases', () => {
});

afterEach(() => {
jest.clearAllMocks();
nock.cleanAll();
nock.enableNetConnect();
delete process.env['AUTOMATIC_RELEASES_TAG'];
Expand Down Expand Up @@ -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);
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
});
});
10 changes: 4 additions & 6 deletions packages/automatic-releases/__tests__/taggedReleases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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();
Expand All @@ -38,7 +39,6 @@ describe('main handler processing tagged releases', () => {
});

afterEach(() => {
jest.clearAllMocks();
nock.cleanAll();
nock.enableNetConnect();
delete process.env['AUTOMATIC_RELEASES_TAG'];
Expand Down Expand Up @@ -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);
Expand All @@ -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');
});
});
7 changes: 4 additions & 3 deletions packages/aws-ssm-secrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 5011bef

Please sign in to comment.