Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ jobs:
node-version: 12
- run: yarn install
- run: yarn lint
- run: yarn build
- run: yarn test
28 changes: 26 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,35 @@ test('wait 500 ms', async () => {
});

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
test('test runs', async () => {
process.env['INPUT_MILLISECONDS'] = '500';
const ip = path.join(__dirname, '..', 'lib', 'main.js');
const options: cp.ExecSyncOptions = {
env: process.env,
};
console.log(cp.execSync(`node ${ip}`, options).toString());

const result = await new Promise<{stdout: string, stderr: string, err: cp.ExecException|null}>((resolve) => {
// cp.execSync will throw an error if the command returns a non-zeo
// status, which may or may no happen depending on the environment
// this test is run (i.e. locally vs on a GitHub Action).
cp.exec(`node ${ip}`, options, (err, stdout, stderr) => {
resolve({
stdout,
stderr,
err,
});
});
});
// The error returned locally is different from the error we get when running in an action.
// However, both will be prefixed with `::error::` by the @actions/core library.
expect(result.stdout).toContain('::error::');
expect(result.stderr).toContain('');

// Depending on whether we run locally or on a GitHub action we get
// different results.
if (result.err) {
console.log('An error was returned by lib/main.js:', result.err);
} else {
console.log(`No error returned by lib/main.js`)
}
});
Loading