Skip to content

technote-space/github-action-test-helper

Repository files navigation

GitHub Actions Test Helper

npm version CI Status codecov CodeFactor License: MIT

Test helper for GitHub Actions.

Read this in other languages: English, 日本語.

Table of Contents

Details

Usage

  1. Install
    npm i @technote-space/github-action-test-helper
  2. 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/]
    },
  },
});
  1. 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();

Author

GitHub (Technote)
Blog