Skip to content

Commit 9da9e98

Browse files
committed
Fix jest
1 parent 61e3bd6 commit 9da9e98

File tree

3 files changed

+16
-35
lines changed

3 files changed

+16
-35
lines changed

__tests__/main.test.js

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const core = require('@actions/core');
55
const main = require('../src/main');
66

77
// Mock the GitHub Actions core library
8-
const debugMock = jest.spyOn(core, 'debug').mockImplementation();
8+
// const debugMock = jest.spyOn(core, 'debug').mockImplementation();
99
const getInputMock = jest.spyOn(core, 'getInput').mockImplementation();
1010
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation();
1111
const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation();
@@ -25,64 +25,41 @@ describe('action', () => {
2525
// Set the action's inputs as return values from core.getInput()
2626
getInputMock.mockImplementation(name => {
2727
switch (name) {
28-
case 'milliseconds':
29-
return '500';
28+
case 'sapi':
29+
return 'cli,fpm';
3030
default:
3131
return '';
3232
}
3333
});
3434

3535
await main.run();
3636
expect(runMock).toHaveReturned();
37-
38-
// Verify that all of the core library functions were called correctly
39-
expect(debugMock).toHaveBeenNthCalledWith(
40-
1,
41-
'Waiting 500 milliseconds ...'
42-
);
43-
expect(debugMock).toHaveBeenNthCalledWith(
44-
2,
45-
expect.stringMatching(timeRegex)
46-
);
47-
expect(debugMock).toHaveBeenNthCalledWith(
48-
3,
49-
expect.stringMatching(timeRegex)
50-
);
51-
expect(setOutputMock).toHaveBeenNthCalledWith(
52-
1,
53-
'time',
54-
expect.stringMatching(timeRegex)
55-
);
37+
expect(setOutputMock).toHaveBeenNthCalledWith(1, 'sapi', 'cli,fpm');
5638
});
5739

58-
it('sets a failed status', async () => {
40+
it('sets the wrong sapi name', async () => {
5941
// Set the action's inputs as return values from core.getInput()
6042
getInputMock.mockImplementation(name => {
6143
switch (name) {
62-
case 'milliseconds':
63-
return 'this is not a number';
44+
case 'sapi':
45+
return 'foo';
6446
default:
6547
return '';
6648
}
6749
});
6850

6951
await main.run();
7052
expect(runMock).toHaveReturned();
71-
72-
// Verify that all of the core library functions were called correctly
73-
expect(setFailedMock).toHaveBeenNthCalledWith(
74-
1,
75-
'milliseconds not a number'
76-
);
53+
expect(setFailedMock).toHaveBeenNthCalledWith(1, 'Invalid sapi');
7754
});
7855

7956
it('fails if no input is provided', async () => {
8057
// Set the action's inputs as return values from core.getInput()
8158
getInputMock.mockImplementation(name => {
8259
switch (name) {
83-
case 'milliseconds':
60+
case 'sapi':
8461
throw new Error(
85-
'Input required and not supplied: milliseconds'
62+
'Need to input a valid sapi: cli, fpm, micro, embed'
8663
);
8764
default:
8865
return '';
@@ -95,7 +72,7 @@ describe('action', () => {
9572
// Verify that all of the core library functions were called correctly
9673
expect(setFailedMock).toHaveBeenNthCalledWith(
9774
1,
98-
'Input required and not supplied: milliseconds'
75+
'Need to input a valid sapi: cli, fpm, micro, embed'
9976
);
10077
});
10178
});

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ inputs:
2727
sapi:
2828
description: 'PHP SAPI'
2929
required: true
30-
default: 'cli'
30+
default: 'cli,micro'
3131

3232
# Define your outputs here.
3333
outputs:

src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const core = require('@actions/core');
77
async function run() {
88
try {
99
const ms = core.getInput('sapi', { required: true });
10+
// only accepts cli,fpm,micro,embed for now
11+
if (!['cli', 'fpm', 'micro', 'embed'].includes(ms)) {
12+
core.setFailed('Invalid sapi');
13+
}
1014

1115
core.setOutput('sapi', ms);
1216
core.debug(`Sapi: ${ms}`);

0 commit comments

Comments
 (0)