GitHub Actions Test Helper
Test helper for GitHub Actions.
Read this in other languages: English, 日本語.
Table of Contents
Usage
- Install
npm i @technote-space/github-action-test-helper
- Setup Vitest
/// <reference types="vitest" />
import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig({
test: {
setupFiles: './src/setup.ts',
clearMocks: true,
mockReset: true,
restoreMocks: true,
coverage: {
reporter: ['html', 'lcov'],
},
deps: {
// The following setting is required
inline: [/github-action-test-helper/]
},
},
});
- Use
import {
getContext,
generateContext,
encodeContent,
getConfigFixture,
getApiFixture,
disableNetConnect,
testEnv,
testChildProcess,
setChildProcessParams,
testFs,
spyOnStdout,
stdoutCalledWith,
stdoutContains,
stdoutNotContains,
spyOnExec,
execCalledWith,
execContains,
execNotContains,
testProperties,
setupGlobal,
getOctokit,
} from '@technote-space/github-action-test-helper';
import nock from 'nock';
getContext({});
generateContext({});
encodeContent('content');
getConfigFixture('rootDir', 'fileName');
getApiFixture('rootDir', 'name');
disableNetConnect(nock);
testEnv();
testChildProcess();
setChildProcessParams({stdout: 'test-stdout', stderr: 'test-stderr', error: new Error('test-error')});
testFs();
const stdoutSpy = spyOnStdout();
stdoutCalledWith(stdoutSpy, []);
stdoutContains(stdoutSpy, []);
stdoutNotContains(stdoutSpy, []);
const execSpy = spyOnExec();
execCalledWith(execSpy, []);
execContains(execSpy, []);
execNotContains(execSpy, []);
testProperties({}, {});
setupGlobal();
getOctokit();