Skip to content

Commit

Permalink
chore: introduce vite
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch authored and omnidan committed Jul 17, 2023
1 parent b9c6f83 commit 370a19d
Show file tree
Hide file tree
Showing 8 changed files with 4,024 additions and 7,211 deletions.
2 changes: 0 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"extends": "standard",
"parser": "babel-eslint",
"env": {
"browser": true,
"mocha": true,
"node": true
}
}
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"semi": false,
"trailingComma": "none"
}
10,935 changes: 3,911 additions & 7,024 deletions package-lock.json

Large diffs are not rendered by default.

94 changes: 24 additions & 70 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,23 @@
"name": "redux-undo",
"version": "1.0.1",
"description": "simple undo/redo functionality for redux state containers",
"main": "lib/index.js",
"main": "./dist/redux-undo.umd.js",
"typings": "typings.d.ts",
"jspm": {
"main": "src/index.js",
"format": "esm"
},
"nyc": {
"extends": "@istanbuljs/nyc-config-babel",
"include": [
"src/**/*.js"
]
},
"babel": {
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
],
"env": {
"test": {
"plugins": [
"babel-plugin-istanbul"
]
}
},
"only": [
"src/*",
"test/*",
"webpack.config.babel.js"
]
"exports": {
".": {
"import": "./dist/redux-undo.mjs",
"require": "./dist/redux-undo.umd.js",
"types": "./typings.d.ts"
}
},
"scripts": {
"prebuild": "npm run clean",
"build": "npm-run-all --parallel build:*",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack --mode=production",
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --mode=production",
"clean": "npx rimraf lib/ dist/ es/",
"lint": "npx eslint webpack.config.babel.js src test",
"prepublish": "npm-run-all --sequential lint test clean build",
"test": "cross-env NODE_ENV=test nyc mocha --require @babel/register",
"build": "vite build",
"lint": "npx eslint src test",
"test": "vitest run",
"test:bail": "npm run test:watch -- --bail",
"test:cov": "cross-env NODE_ENV=test nyc --reporter=text --reporter=lcov mocha --require @babel/register",
"test:coveralls": "nyc report --reporter=text-lcov | coveralls",
"test:watch": "npm run test -- --watch"
"test:cov": "npm run test -- --coverage",
"test:coveralls": "npm run test -- --coverage && coveralls < coverage/lcov.info",
"test:watch": "vitest"
},
"repository": {
"type": "git",
Expand All @@ -68,33 +38,17 @@
},
"homepage": "https://github.com/omnidan/redux-undo",
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/node": "^7.7.4",
"@babel/plugin-proposal-object-rest-spread": "^7.7.4",
"@babel/preset-env": "^7.7.6",
"@babel/register": "^7.7.4",
"@istanbuljs/nyc-config-babel": "^2.1.1",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"babel-plugin-istanbul": "^5.2.0",
"chai": "^4.2.0",
"coveralls": "^3.0.9",
"cross-env": "^6.0.3",
"eslint": "^6.7.2",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"expect": "^24.9.0",
"mocha": "^6.2.2",
"mocha-lcov-reporter": "^1.3.0",
"eslint": "^8.43.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^5.0.0",
"npm-run-all": "^4.1.5",
"nyc": "^14.1.1",
"redux": "^4.0.4",
"rimraf": "^3.0.0",
"webpack": "^4.41.3",
"webpack-cli": "^3.3.10"
"redux": "^4.2.1",
"rimraf": "^5.0.1",
"vite": "^4.3.0",
"vitest": "^0.32.2",
"@vitest/coverage-istanbul": "^0.32.0",
"coveralls": "^3.0.0"
}
}
110 changes: 53 additions & 57 deletions test/combineFilters.spec.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
import { expect } from 'chai'
import { expect, describe, it } from 'vitest'
import { combineFilters } from '../src/index'

runTestCombineFilters()

function runTestCombineFilters () {
describe('Combine Filters', () => {
const sample = {
action: { type: 'TEST' },
currentState: 1,
previousHistory: [0, -1]
}

function checkArguments (action, currentState, previousHistory) {
return (
action === sample.action &&
currentState === sample.currentState &&
previousHistory === sample.previousHistory
)
}

function checkArgumentsNot (action, currentState, previousHistory) {
return (
action !== sample.action ||
currentState !== sample.currentState ||
previousHistory !== sample.previousHistory
)
}

function checkStateNot1 (action, state) { return state !== 1 }
function checkStateNot2 (action, state) { return state !== 2 }

function checkIfCalled (action) {
action.hasBeenCalled = true
return true
}

it('should pass its arguments while calling a filter', () => {
expect(combineFilters(checkArguments, checkArguments)(sample.action, sample.currentState, sample.previousHistory))
.to.equal(true)
expect(combineFilters(checkArgumentsNot, checkArguments)(sample.action, sample.currentState, sample.previousHistory))
.to.equal(false)
})
describe('Combine Filters', () => {
const sample = {
action: { type: 'TEST' },
currentState: 1,
previousHistory: [0, -1]
}

function checkArguments (action, currentState, previousHistory) {
return (
action === sample.action &&
currentState === sample.currentState &&
previousHistory === sample.previousHistory
)
}

function checkArgumentsNot (action, currentState, previousHistory) {
return (
action !== sample.action ||
currentState !== sample.currentState ||
previousHistory !== sample.previousHistory
)
}

function checkStateNot1 (action, state) { return state !== 1 }
function checkStateNot2 (action, state) { return state !== 2 }

function checkIfCalled (action) {
action.hasBeenCalled = true
return true
}

it('should pass its arguments while calling a filter', () => {
expect(combineFilters(checkArguments, checkArguments)(sample.action, sample.currentState, sample.previousHistory))
.to.equal(true)
expect(combineFilters(checkArgumentsNot, checkArguments)(sample.action, sample.currentState, sample.previousHistory))
.to.equal(false)
})

it('should return false if any filter does', () => {
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 1)).to.equal(false)
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 2)).to.equal(false)
})
it('should return false if any filter does', () => {
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 1)).to.equal(false)
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 2)).to.equal(false)
})

it('should return true if every filter does', () => {
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 3)).to.equal(true)
})
it('should return true if every filter does', () => {
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 3)).to.equal(true)
})

it('should not call remaining filters if one already returned false', () => {
const act = { hasBeenCalled: false }
const combined = combineFilters(checkStateNot1, checkStateNot2, checkIfCalled)
it('should not call remaining filters if one already returned false', () => {
const act = { hasBeenCalled: false }
const combined = combineFilters(checkStateNot1, checkStateNot2, checkIfCalled)

combined(act, 2)
expect(act.hasBeenCalled).to.equal(false)
combined(act, 3)
expect(act.hasBeenCalled).to.equal(true)
})
combined(act, 2)
expect(act.hasBeenCalled).to.equal(false)
combined(act, 3)
expect(act.hasBeenCalled).to.equal(true)
})
}
})
26 changes: 14 additions & 12 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai'
import { describe, expect, it, beforeAll } from 'vitest'
import { createStore } from 'redux'
import undoable, { ActionCreators, ActionTypes, excludeAction, includeAction, isHistory } from '../src/index'

Expand Down Expand Up @@ -134,7 +134,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
let incrementedState
let store

before('setup mock reducers and states', () => {
beforeAll(() => {
// undoableConfig.debug = true
mockUndoableReducer = undoable(countReducer, undoableConfig)
store = createStore(mockUndoableReducer, initialStoreState)
Expand Down Expand Up @@ -417,7 +417,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }

describe('Undo', () => {
let undoState
before('perform an undo action', () => {
beforeAll(() => {
wasCalled = false
undoState = mockUndoableReducer(incrementedState, ActionCreators.undo())
})
Expand Down Expand Up @@ -484,7 +484,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
describe('Redo', () => {
let undoState
let redoState
before('perform an undo action then a redo action', () => {
beforeAll(() => {
wasCalled = false
undoState = mockUndoableReducer(incrementedState, ActionCreators.undo())
redoState = mockUndoableReducer(undoState, ActionCreators.redo())
Expand Down Expand Up @@ -551,7 +551,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
describe('JumpToPast', () => {
const jumpToPastIndex = 0
let jumpToPastState
before('perform a jumpToPast action', () => {
beforeAll(() => {
jumpToPastState = mockUndoableReducer(incrementedState, ActionCreators.jumpToPast(jumpToPastIndex))
})

Expand Down Expand Up @@ -587,7 +587,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
describe('JumpToFuture', () => {
const jumpToFutureIndex = 2
let jumpToFutureState
before('perform a jumpToFuture action', () => {
beforeAll(() => {
jumpToFutureState = mockUndoableReducer(mockInitialState, ActionCreators.jumpToFuture(jumpToFutureIndex))
})

Expand Down Expand Up @@ -631,7 +631,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
let jumpToFutureState
let doubleUndoState
let doubleRedoState
before('perform a jump action', () => {
beforeAll(() => {
const doubleIncrementedState = mockUndoableReducer(incrementedState, { type: 'INCREMENT' })
jumpToPastState = mockUndoableReducer(doubleIncrementedState, ActionCreators.jump(jumpStepsToPast))
jumpToFutureState = mockUndoableReducer(mockInitialState, ActionCreators.jump(jumpStepsToFuture))
Expand Down Expand Up @@ -669,7 +669,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
describe('Clear History', () => {
let clearedState

before('perform a clearHistory action', () => {
beforeAll(() => {
const clearHistoryType = undoableConfig && undoableConfig.clearHistoryType
const actionType = clearHistoryType && Array.isArray(clearHistoryType) && clearHistoryType.length ? { type: clearHistoryType[0] } : ActionCreators.clearHistory()
clearedState = mockUndoableReducer(incrementedState, actionType)
Expand All @@ -684,8 +684,10 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
expect(clearedState.present).to.equal(incrementedState.present)
})
})

if (testConfig && testConfig.checkSlices) {

describe('running getSlices', () => {
if (testConfig && testConfig.checkSlices) {
const initialState = {
normalState: 0,
slice1: 100
Expand Down Expand Up @@ -713,7 +715,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
let fifthState
let sixthState
let seventhState
before('run reducer a few times', () => {
beforeAll(() => {
secondState = fullReducer(initialState, { type: 'BOGUS' })
thirdState = fullReducer(secondState, { type: 'INCREMENT' })
fourthState = fullReducer(thirdState, { type: ActionTypes.UNDO })
Expand Down Expand Up @@ -745,7 +747,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
expect(seventhState.normalState.present).to.equal(sixthState.normalState.present - 1)
expect(seventhState.slice1).to.equal(initialState.slice1)
})
}
})
})
}
})
}
17 changes: 17 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite'

export default defineConfig({
test: {
coverage: {
provider: 'istanbul',
reporter: ['text', 'lcov'],
}
},
build: {
lib: {
entry: './src/index.js',
name: 'ReduxUndo'
}
}
})
Loading

0 comments on commit 370a19d

Please sign in to comment.