generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e9fd12
commit 0003dcf
Showing
9 changed files
with
307 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,4 @@ jobs: | |
- name: Test Local Action | ||
uses: ./ | ||
with: | ||
include: ./fixtures/*.xml | ||
include: ./__tests__/fixtures/*.xml |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/** | ||
* Unit tests for the action's main functionality, src/main.ts | ||
* | ||
* These should be run as if the action was called from a workflow. | ||
* Specifically, the inputs listed in `action.yml` should be set as environment | ||
* variables following the pattern `INPUT_<INPUT_NAME>`. | ||
*/ | ||
|
||
import * as core from '@actions/core' | ||
import * as main from '../src/main' | ||
|
||
// Mock the action's main function | ||
const runMock = jest.spyOn(main, 'run') | ||
|
||
// Mock the GitHub Actions core library | ||
let infoMock: jest.SpyInstance | ||
let errorMock: jest.SpyInstance | ||
let getInputMock: jest.SpyInstance | ||
let setFailedMock: jest.SpyInstance | ||
|
||
describe('action', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
process.env.RUNNER_TEMP = '/tmp' | ||
infoMock = jest.spyOn(core, 'info').mockImplementation() | ||
errorMock = jest.spyOn(core, 'error').mockImplementation() | ||
getInputMock = jest.spyOn(core, 'getInput').mockImplementation() | ||
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() | ||
}) | ||
|
||
it('successfully completes', async () => { | ||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
expect(errorMock).not.toHaveBeenCalled() | ||
expect(setFailedMock).not.toHaveBeenCalled() | ||
expect(infoMock).toHaveBeenLastCalledWith( | ||
'junit-reducer exited successfully' | ||
) | ||
}) | ||
|
||
it('successfully completes with a specific version', async () => { | ||
getInputMock.mockImplementation((name: string): string => { | ||
switch (name) { | ||
case 'version': | ||
return 'v1.2.0' | ||
default: | ||
return '' | ||
} | ||
}) | ||
|
||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
expect(errorMock).not.toHaveBeenCalled() | ||
expect(setFailedMock).not.toHaveBeenCalled() | ||
expect(infoMock).toHaveBeenLastCalledWith( | ||
'junit-reducer exited successfully' | ||
) | ||
}) | ||
|
||
describe('on mock Windows', () => { | ||
beforeEach(() => { | ||
process.env.OVERRIDE_PLATFORM = 'win32' | ||
}) | ||
it('successfully downloads the Windows binary', async () => { | ||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
expect(infoMock).toHaveBeenCalledWith('Windows archive downloaded') | ||
expect(errorMock).toHaveBeenCalledWith( | ||
"Can't install extension on mocked platform" | ||
) | ||
}) | ||
afterEach(() => { | ||
delete process.env.OVERRIDE_PLATFORM | ||
}) | ||
}) | ||
|
||
describe('on mock Mac', () => { | ||
beforeEach(() => { | ||
process.env.OVERRIDE_PLATFORM = 'darwin' | ||
}) | ||
it('successfully downloads the Mac binary', async () => { | ||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
expect(infoMock).toHaveBeenCalledWith('Mac archive downloaded') | ||
expect(errorMock).toHaveBeenCalledWith( | ||
"Can't install extension on mocked platform" | ||
) | ||
}) | ||
afterEach(() => { | ||
delete process.env.OVERRIDE_PLATFORM | ||
}) | ||
}) | ||
|
||
describe('on mock Linux', () => { | ||
beforeEach(() => { | ||
process.env.OVERRIDE_PLATFORM = 'linux' | ||
}) | ||
it('successfully downloads the Linux binary', async () => { | ||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
expect(infoMock).toHaveBeenCalledWith('Linux archive downloaded') | ||
expect(errorMock).toHaveBeenCalledWith( | ||
"Can't install extension on mocked platform" | ||
) | ||
}) | ||
afterEach(() => { | ||
delete process.env.OVERRIDE_PLATFORM | ||
}) | ||
}) | ||
|
||
describe('on any other platform', () => { | ||
beforeEach(() => { | ||
process.env.OVERRIDE_PLATFORM = 'unknown' | ||
}) | ||
it('successfully downloads the Linux binary', async () => { | ||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
expect(infoMock).toHaveBeenCalledWith('Linux archive downloaded') | ||
expect(errorMock).toHaveBeenCalledWith( | ||
"Can't install extension on mocked platform" | ||
) | ||
}) | ||
afterEach(() => { | ||
delete process.env.OVERRIDE_PLATFORM | ||
}) | ||
}) | ||
|
||
it('sets a failed status for invalid version', async () => { | ||
// Set the action's inputs as return values from core.getInput() | ||
getInputMock.mockImplementation((name: string): string => { | ||
switch (name) { | ||
case 'version': | ||
return 'this is not a number' | ||
default: | ||
return '' | ||
} | ||
}) | ||
|
||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
|
||
// Verify that all of the core library functions were called correctly | ||
expect(setFailedMock).toHaveBeenNthCalledWith( | ||
1, | ||
'invalid version string: this is not a number' | ||
) | ||
expect(errorMock).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('sets a failed status for non-zero status code thrown by the binary', async () => { | ||
// Set input variable 'include' to a non-existent file glob | ||
process.env.INPUT_include = 'this-file-does-not-exist.xml' | ||
|
||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
expect(errorMock).not.toHaveBeenCalled() | ||
expect(setFailedMock).toHaveBeenCalled() | ||
}) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites> | ||
<testsuite name="Admin::Jobs::Applications::Actions::CreativeServicesIncBackgroundCheckTest" filepath="test/system/admin/jobs/applications/actions/creative_services_inc_background_check_test.rb" time="49.09959481199999" tests="5" failed="0" errors="0" skipped="0" assertions="17"> | ||
<testcase name="test_should_not_see_Creative_Services_Inc_integration_when_removed" classname="Admin::Jobs::Applications::Actions::CreativeServicesIncBackgroundCheckTest" file="test/system/admin/jobs/applications/actions/creative_services_inc_background_check_test.rb" lineno="53" assertions="1" time="4.922785552499988"></testcase> | ||
<testcase name="test_should_show_each_of_the_different_values_depending_on_which_billing_option_you_select" classname="Admin::Jobs::Applications::Actions::CreativeServicesIncBackgroundCheckTest" file="test/system/admin/jobs/applications/actions/creative_services_inc_background_check_test.rb" lineno="90" assertions="0" time="12.873165432000008"></testcase> | ||
<testcase name="test_should_not_be_able_to_view_a_background_check_without_background_check_viewer_role" classname="Admin::Jobs::Applications::Actions::CreativeServicesIncBackgroundCheckTest" file="test/system/admin/jobs/applications/actions/creative_services_inc_background_check_test.rb" lineno="176" assertions="2" time="4.697016684999994"></testcase> | ||
</testsuite> | ||
</testsuites> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.