Skip to content
Merged
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/github-action-test-helper",
"version": "0.10.0",
"version": "0.11.0",
"description": "Test helper for GitHub Actions.",
"keywords": [
"github",
Expand Down Expand Up @@ -50,13 +50,13 @@
"@rollup/plugin-typescript": "^9.0.1",
"@sindresorhus/tsconfig": "^3.0.1",
"@types/js-yaml": "^4.0.5",
"@types/node": "^18.8.5",
"@types/node": "^18.11.0",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"@vitest/coverage-c8": "^0.24.3",
"eslint": "^8.25.0",
"eslint-plugin-import": "^2.26.0",
"rollup": "^3.1.0",
"rollup": "^3.2.0",
"typescript": "^4.8.4"
},
"peerDependencies": {
Expand Down
18 changes: 16 additions & 2 deletions src/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-magic-numbers */
import { addPath, exportVariable } from '@actions/core';
import { addPath, exportVariable, setOutput } from '@actions/core';
import { describe, it } from 'vitest';
import { spyOnExportVariable, exportVariableCalledWith, spyOnAddPath, addPathCalledWith } from './command.js';
import { spyOnExportVariable, exportVariableCalledWith, spyOnAddPath, addPathCalledWith, spyOnSetOutput, setOutputCalledWith } from './command.js';

describe('spyOnExportVariable, exportVariableCalledWith', () => {
it('should spy on exportVariable', () => {
Expand All @@ -27,3 +27,17 @@ describe('spyOnAddPath, addPathCalledWith', () => {
addPathCalledWith(spy, ['test-path1', 'test-path2']);
});
});

describe('spyOnSetOutput, setOutputCalledWith', () => {
it('should spy on setOutput', () => {
const spy = spyOnSetOutput();

setOutput('test-name1', 'test-value1');
setOutput('test-name2', ['test-value2-1', 'test-value2-2']);

setOutputCalledWith(spy, [
{ name: 'test-name1', value: 'test-value1' },
{ name: 'test-name2', value: ['test-value2-1', 'test-value2-2'] },
]);
});
});
10 changes: 10 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ export const addPathCalledWith = (spyOnMock: SpyInstance, paths: string[]): void
expect(spyOnMock.mock.calls[index]![0]).toBe(path);
});
};

export const spyOnSetOutput = (): SpyInstance => vi.spyOn(core, 'setOutput').mockReturnValue();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const setOutputCalledWith = (spyOnMock: SpyInstance, pairs: { name: string, value: any }[]): void => {
expect(spyOnMock).toBeCalledTimes(pairs.length);
pairs.forEach(({ name, value }, index) => {
expect(spyOnMock.mock.calls[index]![0]).toBe(name);
expect(spyOnMock.mock.calls[index]![1]).toEqual(value);
});
};
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==

"@types/node@*", "@types/node@^18.8.5":
version "18.8.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.8.5.tgz#6a31f820c1077c3f8ce44f9e203e68a176e8f59e"
integrity sha512-Bq7G3AErwe5A/Zki5fdD3O6+0zDChhg671NfPjtIcbtzDNZTv4NPKMRFr7gtYPG7y+B8uTiNK4Ngd9T0FTar6Q==
"@types/node@*", "@types/node@^18.11.0":
version "18.11.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.0.tgz#f38c7139247a1d619f6cc6f27b072606af7c289d"
integrity sha512-IOXCvVRToe7e0ny7HpT/X9Rb2RYtElG1a+VshjwT00HxrM2dWBApHQoqsI6WiY7Q03vdf2bCrIGzVrkF/5t10w==

"@typescript-eslint/eslint-plugin@^5.40.0":
version "5.40.0"
Expand Down Expand Up @@ -1683,10 +1683,10 @@ rimraf@^3.0.2:
dependencies:
glob "^7.1.3"

rollup@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-3.1.0.tgz#1310c764ee3187cd39d936c85107f4bfb0cae3d7"
integrity sha512-GEvr+COcXicr4nuih6mpt2Eydq5lZ72z0RrKx1H4/Q2ouT34OHrIIJ9OUj2sZqUhq7QL8Hp8Q8BoWbjL/6ccRQ==
rollup@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-3.2.0.tgz#a6f44074418e55217967c8eca622f9638d396388"
integrity sha512-0ZkFPyBNvx717KvC700NoxUD31aEEX675u6INJVAmBgKtQuCL8jmmJCj1b9B/qDSnILAvASVKa7UpGS+FLN6AQ==
optionalDependencies:
fsevents "~2.3.2"

Expand Down