-
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.
Merge pull request #4 from particle-iot/feature/test-action-func
Add tests to main action method
- Loading branch information
Showing
4 changed files
with
199 additions
and
121 deletions.
There are no files selected for viewing
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,70 @@ | ||
describe('compileAction', () => { | ||
|
||
afterEach(() => { | ||
jest.resetModules(); | ||
}); | ||
|
||
it('should use compile locally with docker by default', async () => { | ||
const dockerCheckMock = jest.fn(); | ||
const dockerBuildpackCompileMock = jest.fn(); | ||
jest.mock('./docker', () => ({ | ||
dockerCheck: dockerCheckMock, | ||
dockerBuildpackCompile: dockerBuildpackCompileMock | ||
})); | ||
const { compileAction } = await import('./action'); | ||
await compileAction(); | ||
expect(dockerCheckMock).toHaveBeenCalled(); | ||
expect(dockerBuildpackCompileMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should use compile in the cloud if access token is provided', async () => { | ||
// mock particle-access-token input | ||
jest.mock('@actions/core', () => ({ | ||
getInput: jest.fn().mockImplementation((name: string) => { | ||
if (name === 'particle-access-token') { | ||
return 'test-token'; | ||
} | ||
return ''; | ||
}), | ||
setFailed: jest.fn(), | ||
info: jest.fn(), | ||
setOutput: jest.fn() | ||
})); | ||
|
||
const particleCloudCompileMock = jest.fn().mockResolvedValue('test-binary-id'); | ||
const particleDownloadBinaryMock = jest.fn().mockResolvedValue('test-path'); | ||
jest.mock('./particle-api', () => ({ | ||
particleCloudCompile: particleCloudCompileMock, | ||
particleDownloadBinary: particleDownloadBinaryMock | ||
})); | ||
const { compileAction } = await import('./action'); | ||
await compileAction(); | ||
expect(particleCloudCompileMock).toHaveBeenCalled(); | ||
expect(particleDownloadBinaryMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw an error if cloud compilation fails', async () => { | ||
// mock particle-access-token input | ||
const setFailedMock = jest.fn(); | ||
jest.mock('@actions/core', () => ({ | ||
getInput: jest.fn().mockImplementation((name: string) => { | ||
if (name === 'particle-access-token') { | ||
return 'test-token'; | ||
} | ||
return ''; | ||
}), | ||
setFailed: setFailedMock, | ||
info: jest.fn(), | ||
setOutput: jest.fn() | ||
})); | ||
|
||
const particleCloudCompileMock = jest.fn().mockResolvedValue(null); | ||
jest.mock('./particle-api', () => ({ | ||
particleCloudCompile: particleCloudCompileMock | ||
})); | ||
const { compileAction } = await import('./action'); | ||
await compileAction(); | ||
expect(setFailedMock).toHaveBeenCalled(); | ||
expect(setFailedMock).toHaveBeenCalledWith('Failed to compile code in cloud'); | ||
}); | ||
}); |
Oops, something went wrong.