Skip to content

Commit

Permalink
Failing test for broken d.ts file
Browse files Browse the repository at this point in the history
Ref #1
  • Loading branch information
tswaters committed Feb 24, 2019
1 parent be91f35 commit 3bf3193
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 4 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"prepublishOnly": "npm run lint && npm test && npm run build",
"pretest": "rimraf coverage .nyc_output",
"test": "nyc --reporter=text --reporter=html mocha --opts mocha.opts",
"test": "tsc && nyc --reporter=text --reporter=html mocha --opts mocha.opts",
"lint": "eslint src test",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"prebuild": "rimraf lib",
Expand Down Expand Up @@ -42,13 +42,15 @@
"@babel/plugin-proposal-object-rest-spread": "^7.3.2",
"@babel/preset-env": "^7.3.1",
"@babel/register": "^7.0.0",
"@types/node": "^11.9.5",
"coveralls": "^3.0.3",
"eslint": "^5.14.1",
"mocha": "^6.0.1",
"nyc": "^13.3.0",
"redux": "^4.0.1",
"reselect": "^4.0.0",
"rimraf": "^2.6.3",
"sinon": "^7.2.4"
"sinon": "^7.2.4",
"typescript": "^3.3.3333"
}
}
4 changes: 2 additions & 2 deletions test/fixtures/redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const getWidgets = createSelector(state => state.widgets, widgets => widg
export default (state = defaultState, action) => {
switch (action.type) {
case ADD_ITEM:
return {...state, items: state.items.concat({id: action.id, name: action.name})}
return {...state, items: [...state.items, {id: action.id, name: action.name}]}
case REMOVE_ITEM:
return {...state, items: state.items.filter(i => i.id !== action.id)}
case ADD_WIDGET:
return {...state, widgets: state.widgets.concat({id: action.id, name: action.name})}
return {...state, widgets: [...state.widgets, {id: action.id, name: action.name}]}
case REMOVE_WIDGET:
return {...state, widgets: state.widgets.filter(i => i.id !== action.id)}
default:
Expand Down
65 changes: 65 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

import {ok} from 'assert'
import {createSelector} from 'reselect'
import { createStore, Store } from 'redux';
import subscribe from '../lib/index'

type Item = {id: Number, name: String}
type Widget = {widget_id: Number, widget_name: String}

const ADD_ITEM = 'ADD_ITEM'
type ADD_ITEM = typeof ADD_ITEM
type addItemAction = {type: ADD_ITEM, id: Number, name: String}
const addItem = (name: String): addItemAction => ({type: ADD_ITEM, id: item_id++, name})

const REMOVE_ITEM = 'REMOVE_ITEM'
type REMOVE_ITEM = typeof REMOVE_ITEM
type removeItemAction = {type: REMOVE_ITEM, id: Number}
const removeItem = (id: Number): removeItemAction => ({type: REMOVE_ITEM, id})

type StoreActions = addItemAction | removeItemAction

type StoreState = {
items: Item[],
}

let item_id = 0

const defaultState = {
items: []
}

const reducer = (state: StoreState = defaultState, action: StoreActions) => {
switch (action.type) {
case ADD_ITEM:
return {...state, items: [...state.items, {id: action.id, name: action.name}]}
case REMOVE_ITEM:
return {...state, items: state.items.filter(i => i.id !== action.id)}
default:
return state
}
}


const store: Store<StoreState, StoreActions> = createStore(reducer)

const getItems = createSelector((state: StoreState) => state.items, items => items)

const hasItem = createSelector(getItems, items => items.length > 0)

const firstItemId = createSelector(getItems, items => items[0].id)

const transformToWidget = createSelector(getItems, items => items.map(item => ({widget_id: item.id, widget_name: item.name})))

subscribe(store, getItems, (res: Item[]) => ok(res))

subscribe(store, hasItem, (res: boolean) => ok(res))

subscribe(store, firstItemId, (res: Number) => ok(res))

subscribe(store, transformToWidget, (res: Widget[]) => ok(res))

store.dispatch(addItem('item #1'))
store.dispatch(addItem('item #2'))
store.dispatch(removeItem(0))

25 changes: 25 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"noEmit": true,
"locale": "en-ca",
"target": "es6",
"declaration": false,
"strictNullChecks": true,
"noImplicitUseStrict": false,
"allowUnreachableCode": false,
"noUnusedLocals": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"module": "commonjs",
"lib": [
"es2015",
"es2017",
"dom"
]
},
"files": ["test/test.ts"],
"exclude": [
"node_modules",
"dist"
]
}

0 comments on commit 3bf3193

Please sign in to comment.