-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
7 changed files
with
293 additions
and
124 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
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,83 @@ | ||
import * as core from '@actions/core' | ||
import { OmitOption, getInputs } from '../src/inputs' | ||
|
||
jest.mock('@actions/core') | ||
|
||
const mockGetInput = core.getInput as jest.MockedFunction<typeof core.getInput> | ||
const mockGetBooleanInput = core.getBooleanInput as jest.MockedFunction< | ||
typeof core.getBooleanInput | ||
> | ||
|
||
const mockInput = (name: string, value: string) => { | ||
mockGetInput.mockImplementation((n: string) => (n === name ? value : '')) | ||
} | ||
|
||
describe('renderer', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('uses default values', () => { | ||
mockGetInput.mockReturnValue('') | ||
const inputs = getInputs() | ||
|
||
expect(inputs).toEqual({ | ||
moduleDirectory: '.', | ||
testArguments: ['./...'], | ||
fromJSONFile: null, | ||
omit: new Set(), | ||
}) | ||
}) | ||
|
||
it('parses moduleDirectory', () => { | ||
mockInput('moduleDirectory', 'foo') | ||
const inputs = getInputs() | ||
|
||
expect(inputs.moduleDirectory).toEqual('foo') | ||
}) | ||
|
||
it('parses testArguments', () => { | ||
mockInput('testArguments', 'foo bar') | ||
const inputs = getInputs() | ||
|
||
expect(inputs.testArguments).toEqual(['foo', 'bar']) | ||
}) | ||
|
||
it('parses fromJSONFile', () => { | ||
mockInput('fromJSONFile', 'foo.json') | ||
const inputs = getInputs() | ||
|
||
expect(inputs.fromJSONFile).toEqual('foo.json') | ||
}) | ||
|
||
it('parses omit', () => { | ||
mockInput( | ||
'omit', | ||
[...Object.values(OmitOption), 'foo', 'bar', 'baz'].join('\n') | ||
) | ||
const inputs = getInputs() | ||
|
||
expect(inputs.omit).toEqual(new Set(Object.values(OmitOption))) | ||
}) | ||
|
||
it('supports deprecated inputs', () => { | ||
mockGetInput.mockImplementation((name: string) => { | ||
switch (name) { | ||
case 'omitUntestedPackages': | ||
case 'omitSuccessfulPackages': | ||
case 'omitPie': | ||
return 'true' | ||
default: | ||
return '' | ||
} | ||
}) | ||
|
||
mockGetBooleanInput.mockReturnValue(true) | ||
|
||
const inputs = getInputs() | ||
expect(inputs.omit).toEqual( | ||
new Set([OmitOption.Skipped, OmitOption.Successful, OmitOption.Pie]) | ||
) | ||
expect(core.warning).toHaveBeenCalled() | ||
}) | ||
}) |
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
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
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,112 @@ | ||
import * as core from '@actions/core' | ||
|
||
export interface Inputs { | ||
moduleDirectory: string | ||
testArguments: string[] | ||
fromJSONFile: string | null | ||
omit: Set<OmitOption> | ||
} | ||
|
||
export enum OmitOption { | ||
// Omit untested packages from the summary | ||
Skipped = 'skipped', | ||
// Omit successful packages from the summary | ||
Successful = 'successful', | ||
// Omit the pie chart from the summary | ||
Pie = 'pie', | ||
// Omit the package test output | ||
PackageOutput = 'pkg-output', | ||
// Omit the package test list | ||
PackageTests = 'pkg-tests', | ||
// Omit stderr | ||
Stderr = 'stderr', | ||
} | ||
|
||
export const defaultInputs = (): Inputs => ({ | ||
moduleDirectory: '.', | ||
testArguments: ['./...'], | ||
fromJSONFile: null, | ||
omit: new Set(), | ||
}) | ||
|
||
/** | ||
* Parses the action inputs from the environment | ||
* @returns the parsed inputs | ||
*/ | ||
export function getInputs(): Inputs { | ||
const inputs = defaultInputs() | ||
|
||
getDeprecatedOmitInputs().forEach(option => { | ||
inputs.omit.add(option) | ||
}) | ||
|
||
const moduleDirectory = core.getInput('moduleDirectory') | ||
if (moduleDirectory) { | ||
inputs.moduleDirectory = moduleDirectory | ||
} | ||
|
||
const testArguments = core.getInput('testArguments') | ||
if (testArguments) { | ||
inputs.testArguments = testArguments.split(/\s/).filter(arg => arg.length) | ||
} | ||
|
||
const fromJSONFile = core.getInput('fromJSONFile') | ||
if (fromJSONFile) { | ||
inputs.fromJSONFile = fromJSONFile | ||
} | ||
|
||
const omit = core.getInput('omit') | ||
if (omit) { | ||
omit | ||
.split(/\s/) | ||
.filter(option => | ||
Object.values(OmitOption).includes(option as OmitOption) | ||
) | ||
.forEach(option => inputs.omit.add(option as OmitOption)) | ||
} | ||
|
||
return inputs | ||
} | ||
|
||
/** | ||
* Parses the deprecated omit inputs | ||
* @returns the parsed omit options | ||
*/ | ||
function getDeprecatedOmitInputs(): OmitOption[] { | ||
const omitOptions: OmitOption[] = [] | ||
const usedDeprecated: string[] = [] | ||
|
||
const omitUntestedPackages = core.getInput('omitUntestedPackages') | ||
if (omitUntestedPackages) { | ||
usedDeprecated.push('omitUntestedPackages') | ||
if (core.getBooleanInput('omitUntestedPackages')) { | ||
omitOptions.push(OmitOption.Skipped) | ||
} | ||
} | ||
|
||
const omitSuccessfulPackages = core.getInput('omitSuccessfulPackages') | ||
if (omitSuccessfulPackages) { | ||
usedDeprecated.push('omitSuccessfulPackages') | ||
if (core.getBooleanInput('omitSuccessfulPackages')) { | ||
omitOptions.push(OmitOption.Successful) | ||
} | ||
} | ||
|
||
const omitPie = core.getInput('omitPie') | ||
if (omitPie) { | ||
usedDeprecated.push('omitPie') | ||
if (core.getBooleanInput('omitPie')) { | ||
omitOptions.push(OmitOption.Pie) | ||
} | ||
} | ||
|
||
if (usedDeprecated.length > 0) { | ||
core.warning( | ||
`The following inputs are deprecated and will be removed in the next major version: ${Array.from( | ||
usedDeprecated | ||
).join(', ')}. Please use the \`omit\` input instead.` | ||
) | ||
} | ||
|
||
return omitOptions | ||
} |
Oops, something went wrong.