Skip to content

Commit

Permalink
Merge pull request #139 from technote-space/release/next-v0.0.36
Browse files Browse the repository at this point in the history
release: v0.1.0
  • Loading branch information
technote-space authored Mar 3, 2021
2 parents c623ae3 + 67d8b82 commit de4e680
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 366 deletions.
20 changes: 19 additions & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
/* eslint-disable no-magic-numbers */
import {add} from '../src';
import {add, repeat} from '../src';

describe('add', () => {
it('should add number', () => {
expect(add(1, 2)).toBe(3);
});
});

describe('repeat', () => {
it('should not call callback', async() => {
const callback = jest.fn();

await repeat(callback, 0);

expect(callback).not.toBeCalled();
});

it('should call callback 3 times', async() => {
const callback = jest.fn();

await repeat(callback, 3);

expect(callback).toBeCalledTimes(3);
});
});
6 changes: 3 additions & 3 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {setupGlobal} from '@technote-space/github-action-test-helper';

setupGlobal();
jest.mock('./src/constant', () => Object.assign(jest.requireActual('./src/constant'), {
INTERVAL_MS: 0,
}));
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/ts-package-template",
"version": "0.0.36",
"version": "0.1.0",
"description": "Template for npm package.",
"keywords": [
"github",
Expand Down Expand Up @@ -39,15 +39,14 @@
},
"dependencies": {},
"devDependencies": {
"@commitlint/cli": "^12.0.0",
"@commitlint/config-conventional": "^12.0.0",
"@technote-space/github-action-test-helper": "^0.7.3",
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"eslint": "^7.20.0",
"husky": "^5.1.1",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"eslint": "^7.21.0",
"husky": "^5.1.3",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"lint-staged": "^10.5.4",
Expand Down
1 change: 1 addition & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const WAIT_MS = 1000;
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
import {WAIT_MS} from './constant';

export const add = (num1: number, num2: number): number => num1 + num2;

const wait = (): Promise<void> => new Promise(resolve => setTimeout(resolve, WAIT_MS));
export const repeat = (callback: () => void, times: number): Promise<void> => {
return [...Array(times).keys()].reduce(async(prev) => {
await prev;
callback();
await wait();
}, Promise.resolve());
};
Loading

0 comments on commit de4e680

Please sign in to comment.