Skip to content

Commit

Permalink
Expand test coverage and CI reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
spautz committed Jun 27, 2020
1 parent cd246e8 commit ab1481e
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 32 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -41,7 +41,8 @@
"dev:all": "yon dev && lerna exec yon dev",
"checkup:all": "yon checkup && lerna exec yon checkup",
"all:all": "yon all && lerna exec yon all",
"ci": "yon run checkup:all && yon run test:report && yon run build:all && yon run build-storybook"
"ci": "yon run checkup:all && yon run test:report:all && yon run build:all && yon run build-storybook",
"test:report:all": "yon run test:report && lerna exec yon test:report"
},
"dependencies": {},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/dev-helpers/package.json
Expand Up @@ -37,6 +37,7 @@
"test": "echo \"@TODO: tests for dev-helpers\"",
"test:clean": "rimraf coverage/",
"test:coverage": "echo \"@TODO: tests for dev-helpers\"",
"test:report": "echo \"@TODO: tests for dev-helpers\"",
"test:watch": "echo \"@TODO: tests for dev-helpers\"",
"types": "tsc --noEmit --p tsconfig.json --jsx react",
"____ HOOKS _________________________________________________________": "",
Expand Down
1 change: 1 addition & 0 deletions packages/react-hibernate/package.json
Expand Up @@ -36,6 +36,7 @@
"test": "echo \"@TODO: tests for react-hibernate\"",
"test:clean": "rimraf coverage/",
"test:coverage": "echo \"@TODO: tests for react-hibernate\"",
"test:report": "echo \"@TODO: tests for react-hibernate\"",
"test:watch": "echo \"@TODO: tests for react-hibernate\"",
"types": "tsc --noEmit --p tsconfig.json --jsx react",
"____ HOOKS _________________________________________________________": "",
Expand Down
1 change: 1 addition & 0 deletions packages/react-pauseable-containers/package.json
Expand Up @@ -37,6 +37,7 @@
"test": "echo \"@TODO: tests for pauseable-containers\"",
"test:clean": "rimraf coverage-local/",
"test:coverage": "echo \"@TODO: tests for pauseable-containers\"",
"test:report": "echo \"@TODO: tests for pauseable-containers\"",
"test:watch": "echo \"@TODO: tests for pauseable-containers\"",
"types": "tsc --noEmit --p tsconfig.json --jsx react",
"____ HOOKS _________________________________________________________": "",
Expand Down
1 change: 1 addition & 0 deletions packages/react-router-hibernate/package.json
Expand Up @@ -36,6 +36,7 @@
"test": "jest",
"test:clean": "rimraf coverage-local/",
"test:coverage": "jest --coverage",
"test:report": "COVERALLS_FLAG_NAME=react-router-hibernate jest --coverage --coverageReporters=text-lcov",
"test:watch": "jest --watch",
"types": "tsc --noEmit --p tsconfig.json --jsx react",
"____ HOOKS _________________________________________________________": "",
Expand Down
1 change: 1 addition & 0 deletions packages/redux-pauseable-store/package.json
Expand Up @@ -37,6 +37,7 @@
"test": "jest",
"test:clean": "rimraf coverage-local/",
"test:coverage": "jest --coverage",
"test:report": "COVERALLS_FLAG_NAME=redux-pauseable-store jest --coverage --coverageReporters=text-lcov | coveralls",
"test:watch": "jest --watch",
"types": "tsc --noEmit --p tsconfig.json --jsx react",
"____ HOOKS _________________________________________________________": "",
Expand Down
4 changes: 2 additions & 2 deletions packages/redux-pauseable-store/src/createPauseableStore.tsx
Expand Up @@ -13,9 +13,9 @@ const createPauseableStore = (
let stateAtPause = isInitiallyPaused ? parentStore.getState() : null;

const dispatch = (action: Action) => {
if (pauseableStore.canDispatch === 'warn') {
if (pauseableStore.isPaused && pauseableStore.canDispatch === 'warn') {
console.warn(
'Something is trying to dispatch an action to a PauseableStore. Set `canDispatch` to true or false to disable this warning.',
'Something is trying to dispatch an action to a paused PauseableStore. Set `canDispatch` to true or false to disable this warning.',
{ action, pauseableStore },
);
}
Expand Down
112 changes: 83 additions & 29 deletions packages/redux-pauseable-store/tests/getState.ts
Expand Up @@ -7,46 +7,100 @@ import { createDevHelperStore, incrementAction } from 'react-hibernate-dev-helpe
import { createPauseableStore } from '../src';

describe('getState', () => {
describe('from parent store', () => {
let parentStore: Store;
beforeEach(() => {
parentStore = createDevHelperStore();
let rootStore: Store;
beforeEach(() => {
rootStore = createDevHelperStore();
});

it('creates a pauseableStore', () => {
const myStore = createPauseableStore(rootStore);

expect(myStore.getState()).toEqual({
count: 0,
});
});

it('updates when not paused', () => {
const myStore = createPauseableStore(rootStore);

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 1,
});

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 2,
});
});

it('does not update when paused', () => {
const myStore = createPauseableStore(rootStore, {
isPaused: true,
});

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 0,
});

it('creates a pauseableStore', () => {
const pauseableStore = createPauseableStore(parentStore);
rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 0,
});
});

it('pauses and then unpauses', () => {
const myStore = createPauseableStore(rootStore);

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 1,
});

myStore.setPaused(true);

rootStore.dispatch(incrementAction());
rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 1,
});

myStore.setPaused(false);

expect(pauseableStore.getState()).toEqual({
count: 0,
});
expect(myStore.getState()).toEqual({
count: 3,
});
});

it('updates when not paused', () => {
const pauseableStore = createPauseableStore(parentStore);
it('unpauses and then repauses', () => {
const myStore = createPauseableStore(rootStore, {
isPaused: true,
});

parentStore.dispatch(incrementAction());
expect(pauseableStore.getState()).toEqual({
count: 1,
});
rootStore.dispatch(incrementAction());
rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 0,
});

myStore.setPaused(false);

parentStore.dispatch(incrementAction());
expect(pauseableStore.getState()).toEqual({
count: 2,
});
expect(myStore.getState()).toEqual({
count: 2,
});

it('does not update when paused', () => {
const pauseableStore = createPauseableStore(parentStore, { isPaused: true });
rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 3,
});

parentStore.dispatch(incrementAction());
expect(pauseableStore.getState()).toEqual({
count: 0,
});
myStore.setPaused(true);

parentStore.dispatch(incrementAction());
expect(pauseableStore.getState()).toEqual({
count: 0,
});
rootStore.dispatch(incrementAction());
rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 3,
});
});
});
189 changes: 189 additions & 0 deletions packages/redux-pauseable-store/tests/getStateMultiple.ts
@@ -0,0 +1,189 @@
/* eslint-env jest */
// import '@testing-library/jest-dom/extend-expect';
import { Store } from 'redux';

import { createDevHelperStore, incrementAction } from 'react-hibernate-dev-helpers';

import { createPauseableStore, PauseableStoreInstance } from '../src';

describe('getState with a chain of multiple parent stores', () => {
let rootStore: Store;
let grandparentStore: PauseableStoreInstance;
let parentStore: PauseableStoreInstance;
beforeEach(() => {
rootStore = createDevHelperStore();
grandparentStore = createPauseableStore(rootStore);
parentStore = createPauseableStore(grandparentStore);
});

it('creates a pauseableStore', () => {
const myStore = createPauseableStore(parentStore);

expect(myStore.getState()).toEqual({
count: 0,
});
});

it('updates when not paused', () => {
const myStore = createPauseableStore(parentStore);

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 1,
});

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 2,
});
});

it('does not update when paused', () => {
const myStore = createPauseableStore(rootStore, {
isPaused: true,
});

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 0,
});

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 0,
});
});

it('stops updates at grandparent when grandparent paused', () => {
const myStore = createPauseableStore(parentStore);

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 1,
});

grandparentStore.setPaused(true);

rootStore.dispatch(incrementAction());
rootStore.dispatch(incrementAction());

expect(rootStore.getState()).toEqual({
count: 3,
});
expect(grandparentStore.getState()).toEqual({
count: 1,
});
expect(parentStore.getState()).toEqual({
count: 1,
});
expect(myStore.getState()).toEqual({
count: 1,
});
});

it('stops updates at parent when parent paused', () => {
const myStore = createPauseableStore(parentStore);

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 1,
});

parentStore.setPaused(true);

rootStore.dispatch(incrementAction());
rootStore.dispatch(incrementAction());

expect(rootStore.getState()).toEqual({
count: 3,
});
expect(grandparentStore.getState()).toEqual({
count: 3,
});
expect(parentStore.getState()).toEqual({
count: 1,
});
expect(myStore.getState()).toEqual({
count: 1,
});
});

it('receives latest state properly when ancestors pause and unpause', () => {
const myStore = createPauseableStore(parentStore);

rootStore.dispatch(incrementAction());
expect(myStore.getState()).toEqual({
count: 1,
});

parentStore.setPaused(true);
rootStore.dispatch(incrementAction());

expect(rootStore.getState()).toEqual({
count: 2,
});
expect(grandparentStore.getState()).toEqual({
count: 2,
});
expect(parentStore.getState()).toEqual({
count: 1,
});
expect(myStore.getState()).toEqual({
count: 1,
});

grandparentStore.setPaused(true);
rootStore.dispatch(incrementAction());

expect(rootStore.getState()).toEqual({
count: 3,
});
expect(grandparentStore.getState()).toEqual({
count: 2,
});
expect(parentStore.getState()).toEqual({
count: 1,
});
expect(myStore.getState()).toEqual({
count: 1,
});

parentStore.setPaused(false);
rootStore.dispatch(incrementAction());

expect(rootStore.getState()).toEqual({
count: 4,
});
expect(grandparentStore.getState()).toEqual({
count: 2,
});
expect(parentStore.getState()).toEqual({
count: 2,
});
expect(myStore.getState()).toEqual({
count: 2,
});

myStore.setPaused(true);
grandparentStore.setPaused(false);
rootStore.dispatch(incrementAction());

expect(rootStore.getState()).toEqual({
count: 5,
});
expect(grandparentStore.getState()).toEqual({
count: 5,
});
expect(parentStore.getState()).toEqual({
count: 5,
});
expect(myStore.getState()).toEqual({
count: 2,
});

myStore.setPaused(false);
expect(myStore.getState()).toEqual({
count: 5,
});
});
});

0 comments on commit ab1481e

Please sign in to comment.