Skip to content

Commit 53bb3af

Browse files
committed
test: modernize prepare-dynamic-steps tests to use node:test
(cherry picked from commit 8b89dd8)
1 parent 3d05fad commit 53bb3af

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

.github/actions/prepare-dynamic-steps/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
'use strict';
22

3-
process.on('unhandledRejection', (err) => {
3+
const Assert = require('node:assert');
4+
const Fs = require('node:fs');
5+
const Os = require('node:os');
6+
const Path = require('node:path');
7+
const { describe, it, beforeEach } = require('node:test');
48

5-
throw err;
6-
});
7-
8-
9-
const Assert = require('assert');
10-
const Fs = require('fs');
11-
const Path = require('path');
129
const PrepareDynamicStepsAction = require('..');
1310

1411

@@ -20,34 +17,36 @@ runs:
2017
- run: echo ohai again
2118
`;
2219

23-
24-
exports.main = function () {
20+
describe('PrepareDynamicStepsAction', () => {
2521

2622
const originalEnv = { ...process.env };
2723

28-
const tmpFolder = Path.join(__dirname, '.tmp', `${Date.now()}`);
24+
let tmpFolder;
25+
26+
beforeEach(() => {
2927

30-
try {
28+
tmpFolder = Fs.mkdtempSync(`${Os.tmpdir()}${Path.sep}prepare-dynamic-steps-action-test-`);
3129

3230
Fs.mkdirSync(tmpFolder, { recursive: true });
3331
process.chdir(tmpFolder);
32+
});
33+
34+
it('creates a file when INPUT_STEPS contains valid yaml', () => {
3435

3536
process.env = { ...originalEnv, INPUT_PATH: 'test1', INPUT_STEPS: '- run: echo ohai\n- run: echo ohai again' };
3637
PrepareDynamicStepsAction.main();
3738
Assert.strictEqual(Fs.readFileSync(Path.join(tmpFolder, '.github', 'tmp', 'test1', 'action.yaml')).toString().trim(), expectedResult1.trim());
39+
});
40+
41+
it('throws when INPUT_STEPS contains invalid yaml', () => {
3842

3943
process.env = { ...originalEnv, INPUT_PATH: 'test2', INPUT_STEPS: '- item\n-invalid' };
4044
Assert.throws(() => PrepareDynamicStepsAction.main(), { message: 'Invalid `steps` - unable to parse YAML.' });
45+
});
46+
47+
it('throws when INPUT_STEPS does not contain an array', () => {
4148

4249
process.env = { ...originalEnv, INPUT_PATH: 'test3', INPUT_STEPS: 'not an array' };
4350
Assert.throws(() => PrepareDynamicStepsAction.main(), { message: 'Invalid `steps` - not an array.' });
44-
}
45-
finally {
46-
Fs.rmSync(Path.join(__dirname, '.tmp'), { recursive: true });
47-
}
48-
};
49-
50-
51-
if (require.main === module) {
52-
exports.main();
53-
}
51+
});
52+
});

0 commit comments

Comments
 (0)