Skip to content

Commit

Permalink
Merge pull request #3 from burtek/jest-runner-eslint
Browse files Browse the repository at this point in the history
jest-runner-eslint & auto-changelog
  • Loading branch information
burtek committed Nov 14, 2021
2 parents 5b1cfca + 8f1f9ec commit ea538df
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ jobs:
- name: 'Publish package'
run: yarn publish --tag latest --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
with:
files: junit.xml
- name: 'Build'
run: yarn build
run: yarn build
2 changes: 1 addition & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
"MD048 ": {
"style": "backtick"
}
}
}
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v1.0.2](https://github.com/burtek/react-utils/compare/v1.0.1...v1.0.2)

> 12 November 2021
- build and publish changes [`4aad176`](https://github.com/burtek/react-utils/commit/4aad176988330819dc90d6792dc610802d55b5fe)
- repo in package.json [`9ecb938`](https://github.com/burtek/react-utils/commit/9ecb938343227c0a7d4d1a3414dfaf2412a0b0aa)

#### [v1.0.1](https://github.com/burtek/react-utils/compare/v1.0.0...v1.0.1)

> 12 November 2021
#### v1.0.0

> 12 November 2021
- Initial release [`733cea8`](https://github.com/burtek/react-utils/commit/733cea8924d171871e5b1a54d0ed9109ff8d6b5f)
25 changes: 21 additions & 4 deletions jest-ci.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const config = {
module.exports = {
ci: true,
reporters: ["default", "jest-junit"]
projects: [
{
displayName: 'test',
preset: 'ts-jest',
testEnvironment: 'jest-environment-jsdom'
},
{
displayName: 'lint',
runner: 'jest-runner-eslint',
testMatch: [
'<rootDir>/src/**/*.js',
'<rootDir>/src/**/*.jsx',
'<rootDir>/src/**/*.ts',
'<rootDir>/src/**/*.tsx'
]
}
],
collectCoverage: true,
coverageProvider: 'v8',
reporters: ['default', 'jest-junit']
};

module.exports = Object.assign({}, require('./jest-coverage.config.js'), config);
6 changes: 3 additions & 3 deletions jest-coverage.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const config = {
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jest-environment-jsdom',
collectCoverage: true,
coverageProvider: 'v8'
};

module.exports = Object.assign({}, require('./jest.config.js'), config);
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
"react": ">=16.8.0"
},
"devDependencies": {
"@dtrw/eslint-config": "^1.2.3",
"@dtrw/eslint-config": "^1.3.2",
"@rollup/plugin-commonjs": "^21.0.1",
"@testing-library/react": "^12.1.2",
"@testing-library/react-hooks": "^7.0.2",
"@types/jest": "^27.0.2",
"@types/react": "^17.0.34",
"@types/rollup-plugin-peer-deps-external": "^2.2.1",
"auto-changelog": "^2.3.0",
"eslint": "^8.2.0",
"jest": "^27.3.1",
"jest-junit": "^13.0.0",
"jest-runner-eslint": "^1.0.0",
"react": "^17.0.2",
"react-test-renderer": "^17.0.2",
"rollup": "^2.60.0",
Expand All @@ -37,7 +39,8 @@
"test": "jest",
"test:ci": "jest --config jest-ci.config.js",
"test:coverage": "jest --config jest-coverage.config.js",
"test:watch": "jest --watch"
"test:watch": "jest --watch",
"version": "auto-changelog -p && git add CHANGELOG.md"
},
"repository": {
"url": "https://github.com/burtek/react-utils"
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useArray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ describe('useArray', () => {
expect(() => {
const { result } = renderHook(() => useArray(input as any));
return result.current;
}).toThrowError(/^useArray requires array, got/);
}).toThrow(/^useArray requires array, got/);
});

it('should return reference to input on first and next render', () => {
const { rerender, result } = renderHook(() => useArray(initialArray));

expect(result.current).toBe(initialArray);

rerender();

expect(result.current).toBe(initialArray);
});

Expand Down
9 changes: 6 additions & 3 deletions src/hooks/useObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ describe('useObject', () => {
expect(() => {
const { result } = renderHook(() => useObject(input as any));
return result.current;
}).toThrowError(/^useObject requires an object/);
}).toThrow(/^useObject requires an object/);
});

it('should throw if input is array', () => {
expect(() => {
const { result } = renderHook(() => useObject([]));
return result.current;
}).toThrowError(/^Use useArray for arrays/);
}).toThrow(/^Use useArray for arrays/);
});

it('should return same instance on first and next render', () => {
const { rerender, result } = renderHook(() => useObject(instance1));

expect(result.current).toBe(instance1);

rerender();

expect(result.current).toBe(instance1);
});

Expand All @@ -48,7 +51,7 @@ describe('useObject', () => {
object = instance2;
rerender();

expect(comp).toBeCalledWith(instance1, instance2);
expect(comp).toHaveBeenCalledWith(instance1, instance2);
expect(result.current).toBe(instance2);
});

Expand Down
8 changes: 6 additions & 2 deletions src/hooks/usePrevious.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('usePrevious', () => {
it('should return undefined on first render', () => {
const { result } = renderHook(() => usePrevious(123));

expect(result.current).toBe(undefined);
expect(result.current).toBeUndefined();
});

it('should return given value on next render', () => {
Expand All @@ -25,17 +25,21 @@ describe('usePrevious', () => {
let value: typeof value1 | typeof value2 | typeof value3 = value1;

const { rerender, result } = renderHook(() => usePrevious(value));
expect(result.current).toBe(undefined);

expect(result.current).toBeUndefined();

value = value2;
rerender();

expect(result.current).toBe(value1);

value = value3;
rerender();

expect(result.current).toBe(value2);

rerender();

expect(result.current).toBe(value3);
});
});
5 changes: 5 additions & 0 deletions src/hooks/useToggle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ describe('useToggle', () => {
const [, toggle] = result.current;
toggle();
});

expect(result.current[0]).toBe(!initial);

act(() => {
const [, toggle] = result.current;
toggle();
});

expect(result.current[0]).toBe(initial);
});

Expand All @@ -48,12 +50,14 @@ describe('useToggle', () => {
const [, , setState] = result.current;
setState(target);
});

expect(result.current[0]).toBe(target);

act(() => {
const [, toggle] = result.current;
toggle();
});

expect(result.current[0]).toBe(!target);
});

Expand All @@ -65,6 +69,7 @@ describe('useToggle', () => {
setState(false);
toggle();
});

expect(result.current[0]).toBe(true);
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"rootDir": "./",
"resolveJsonModule": true
}
}
}
Loading

0 comments on commit ea538df

Please sign in to comment.