Skip to content

Commit 370a19d

Browse files
alexander-heimbuchomnidan
authored andcommitted
chore: introduce vite
1 parent b9c6f83 commit 370a19d

File tree

8 files changed

+4024
-7211
lines changed

8 files changed

+4024
-7211
lines changed

.eslintrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"extends": "standard",
3-
"parser": "babel-eslint",
43
"env": {
54
"browser": true,
6-
"mocha": true,
75
"node": true
86
}
97
}

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false,
4+
"trailingComma": "none"
5+
}

package-lock.json

Lines changed: 3911 additions & 7024 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,23 @@
22
"name": "redux-undo",
33
"version": "1.0.1",
44
"description": "simple undo/redo functionality for redux state containers",
5-
"main": "lib/index.js",
5+
"main": "./dist/redux-undo.umd.js",
66
"typings": "typings.d.ts",
7-
"jspm": {
8-
"main": "src/index.js",
9-
"format": "esm"
10-
},
11-
"nyc": {
12-
"extends": "@istanbuljs/nyc-config-babel",
13-
"include": [
14-
"src/**/*.js"
15-
]
16-
},
17-
"babel": {
18-
"presets": [
19-
"@babel/preset-env"
20-
],
21-
"plugins": [
22-
"@babel/plugin-proposal-object-rest-spread"
23-
],
24-
"env": {
25-
"test": {
26-
"plugins": [
27-
"babel-plugin-istanbul"
28-
]
29-
}
30-
},
31-
"only": [
32-
"src/*",
33-
"test/*",
34-
"webpack.config.babel.js"
35-
]
7+
"exports": {
8+
".": {
9+
"import": "./dist/redux-undo.mjs",
10+
"require": "./dist/redux-undo.umd.js",
11+
"types": "./typings.d.ts"
12+
}
3613
},
3714
"scripts": {
38-
"prebuild": "npm run clean",
39-
"build": "npm-run-all --parallel build:*",
40-
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
41-
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
42-
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack --mode=production",
43-
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --mode=production",
44-
"clean": "npx rimraf lib/ dist/ es/",
45-
"lint": "npx eslint webpack.config.babel.js src test",
46-
"prepublish": "npm-run-all --sequential lint test clean build",
47-
"test": "cross-env NODE_ENV=test nyc mocha --require @babel/register",
15+
"build": "vite build",
16+
"lint": "npx eslint src test",
17+
"test": "vitest run",
4818
"test:bail": "npm run test:watch -- --bail",
49-
"test:cov": "cross-env NODE_ENV=test nyc --reporter=text --reporter=lcov mocha --require @babel/register",
50-
"test:coveralls": "nyc report --reporter=text-lcov | coveralls",
51-
"test:watch": "npm run test -- --watch"
19+
"test:cov": "npm run test -- --coverage",
20+
"test:coveralls": "npm run test -- --coverage && coveralls < coverage/lcov.info",
21+
"test:watch": "vitest"
5222
},
5323
"repository": {
5424
"type": "git",
@@ -68,33 +38,17 @@
6838
},
6939
"homepage": "https://github.com/omnidan/redux-undo",
7040
"devDependencies": {
71-
"@babel/cli": "^7.7.5",
72-
"@babel/core": "^7.7.5",
73-
"@babel/node": "^7.7.4",
74-
"@babel/plugin-proposal-object-rest-spread": "^7.7.4",
75-
"@babel/preset-env": "^7.7.6",
76-
"@babel/register": "^7.7.4",
77-
"@istanbuljs/nyc-config-babel": "^2.1.1",
78-
"babel-eslint": "^10.0.3",
79-
"babel-loader": "^8.0.6",
80-
"babel-plugin-istanbul": "^5.2.0",
81-
"chai": "^4.2.0",
82-
"coveralls": "^3.0.9",
83-
"cross-env": "^6.0.3",
84-
"eslint": "^6.7.2",
85-
"eslint-config-standard": "^14.1.0",
86-
"eslint-plugin-import": "^2.19.1",
87-
"eslint-plugin-node": "^10.0.0",
88-
"eslint-plugin-promise": "^4.2.1",
89-
"eslint-plugin-standard": "^4.0.1",
90-
"expect": "^24.9.0",
91-
"mocha": "^6.2.2",
92-
"mocha-lcov-reporter": "^1.3.0",
41+
"eslint": "^8.43.0",
42+
"eslint-plugin-import": "^2.27.5",
43+
"eslint-plugin-node": "^11.1.0",
44+
"eslint-plugin-promise": "^6.1.1",
45+
"eslint-plugin-standard": "^5.0.0",
9346
"npm-run-all": "^4.1.5",
94-
"nyc": "^14.1.1",
95-
"redux": "^4.0.4",
96-
"rimraf": "^3.0.0",
97-
"webpack": "^4.41.3",
98-
"webpack-cli": "^3.3.10"
47+
"redux": "^4.2.1",
48+
"rimraf": "^5.0.1",
49+
"vite": "^4.3.0",
50+
"vitest": "^0.32.2",
51+
"@vitest/coverage-istanbul": "^0.32.0",
52+
"coveralls": "^3.0.0"
9953
}
10054
}

test/combineFilters.spec.js

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,60 @@
1-
import { expect } from 'chai'
1+
import { expect, describe, it } from 'vitest'
22
import { combineFilters } from '../src/index'
33

4-
runTestCombineFilters()
5-
6-
function runTestCombineFilters () {
7-
describe('Combine Filters', () => {
8-
const sample = {
9-
action: { type: 'TEST' },
10-
currentState: 1,
11-
previousHistory: [0, -1]
12-
}
13-
14-
function checkArguments (action, currentState, previousHistory) {
15-
return (
16-
action === sample.action &&
17-
currentState === sample.currentState &&
18-
previousHistory === sample.previousHistory
19-
)
20-
}
21-
22-
function checkArgumentsNot (action, currentState, previousHistory) {
23-
return (
24-
action !== sample.action ||
25-
currentState !== sample.currentState ||
26-
previousHistory !== sample.previousHistory
27-
)
28-
}
29-
30-
function checkStateNot1 (action, state) { return state !== 1 }
31-
function checkStateNot2 (action, state) { return state !== 2 }
32-
33-
function checkIfCalled (action) {
34-
action.hasBeenCalled = true
35-
return true
36-
}
37-
38-
it('should pass its arguments while calling a filter', () => {
39-
expect(combineFilters(checkArguments, checkArguments)(sample.action, sample.currentState, sample.previousHistory))
40-
.to.equal(true)
41-
expect(combineFilters(checkArgumentsNot, checkArguments)(sample.action, sample.currentState, sample.previousHistory))
42-
.to.equal(false)
43-
})
4+
describe('Combine Filters', () => {
5+
const sample = {
6+
action: { type: 'TEST' },
7+
currentState: 1,
8+
previousHistory: [0, -1]
9+
}
10+
11+
function checkArguments (action, currentState, previousHistory) {
12+
return (
13+
action === sample.action &&
14+
currentState === sample.currentState &&
15+
previousHistory === sample.previousHistory
16+
)
17+
}
18+
19+
function checkArgumentsNot (action, currentState, previousHistory) {
20+
return (
21+
action !== sample.action ||
22+
currentState !== sample.currentState ||
23+
previousHistory !== sample.previousHistory
24+
)
25+
}
26+
27+
function checkStateNot1 (action, state) { return state !== 1 }
28+
function checkStateNot2 (action, state) { return state !== 2 }
29+
30+
function checkIfCalled (action) {
31+
action.hasBeenCalled = true
32+
return true
33+
}
34+
35+
it('should pass its arguments while calling a filter', () => {
36+
expect(combineFilters(checkArguments, checkArguments)(sample.action, sample.currentState, sample.previousHistory))
37+
.to.equal(true)
38+
expect(combineFilters(checkArgumentsNot, checkArguments)(sample.action, sample.currentState, sample.previousHistory))
39+
.to.equal(false)
40+
})
4441

45-
it('should return false if any filter does', () => {
46-
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 1)).to.equal(false)
47-
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 2)).to.equal(false)
48-
})
42+
it('should return false if any filter does', () => {
43+
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 1)).to.equal(false)
44+
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 2)).to.equal(false)
45+
})
4946

50-
it('should return true if every filter does', () => {
51-
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 3)).to.equal(true)
52-
})
47+
it('should return true if every filter does', () => {
48+
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 3)).to.equal(true)
49+
})
5350

54-
it('should not call remaining filters if one already returned false', () => {
55-
const act = { hasBeenCalled: false }
56-
const combined = combineFilters(checkStateNot1, checkStateNot2, checkIfCalled)
51+
it('should not call remaining filters if one already returned false', () => {
52+
const act = { hasBeenCalled: false }
53+
const combined = combineFilters(checkStateNot1, checkStateNot2, checkIfCalled)
5754

58-
combined(act, 2)
59-
expect(act.hasBeenCalled).to.equal(false)
60-
combined(act, 3)
61-
expect(act.hasBeenCalled).to.equal(true)
62-
})
55+
combined(act, 2)
56+
expect(act.hasBeenCalled).to.equal(false)
57+
combined(act, 3)
58+
expect(act.hasBeenCalled).to.equal(true)
6359
})
64-
}
60+
})

test/index.spec.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect } from 'chai'
1+
import { describe, expect, it, beforeAll } from 'vitest'
22
import { createStore } from 'redux'
33
import undoable, { ActionCreators, ActionTypes, excludeAction, includeAction, isHistory } from '../src/index'
44

@@ -134,7 +134,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
134134
let incrementedState
135135
let store
136136

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

418418
describe('Undo', () => {
419419
let undoState
420-
before('perform an undo action', () => {
420+
beforeAll(() => {
421421
wasCalled = false
422422
undoState = mockUndoableReducer(incrementedState, ActionCreators.undo())
423423
})
@@ -484,7 +484,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
484484
describe('Redo', () => {
485485
let undoState
486486
let redoState
487-
before('perform an undo action then a redo action', () => {
487+
beforeAll(() => {
488488
wasCalled = false
489489
undoState = mockUndoableReducer(incrementedState, ActionCreators.undo())
490490
redoState = mockUndoableReducer(undoState, ActionCreators.redo())
@@ -551,7 +551,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
551551
describe('JumpToPast', () => {
552552
const jumpToPastIndex = 0
553553
let jumpToPastState
554-
before('perform a jumpToPast action', () => {
554+
beforeAll(() => {
555555
jumpToPastState = mockUndoableReducer(incrementedState, ActionCreators.jumpToPast(jumpToPastIndex))
556556
})
557557

@@ -587,7 +587,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
587587
describe('JumpToFuture', () => {
588588
const jumpToFutureIndex = 2
589589
let jumpToFutureState
590-
before('perform a jumpToFuture action', () => {
590+
beforeAll(() => {
591591
jumpToFutureState = mockUndoableReducer(mockInitialState, ActionCreators.jumpToFuture(jumpToFutureIndex))
592592
})
593593

@@ -631,7 +631,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
631631
let jumpToFutureState
632632
let doubleUndoState
633633
let doubleRedoState
634-
before('perform a jump action', () => {
634+
beforeAll(() => {
635635
const doubleIncrementedState = mockUndoableReducer(incrementedState, { type: 'INCREMENT' })
636636
jumpToPastState = mockUndoableReducer(doubleIncrementedState, ActionCreators.jump(jumpStepsToPast))
637637
jumpToFutureState = mockUndoableReducer(mockInitialState, ActionCreators.jump(jumpStepsToFuture))
@@ -669,7 +669,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
669669
describe('Clear History', () => {
670670
let clearedState
671671

672-
before('perform a clearHistory action', () => {
672+
beforeAll(() => {
673673
const clearHistoryType = undoableConfig && undoableConfig.clearHistoryType
674674
const actionType = clearHistoryType && Array.isArray(clearHistoryType) && clearHistoryType.length ? { type: clearHistoryType[0] } : ActionCreators.clearHistory()
675675
clearedState = mockUndoableReducer(incrementedState, actionType)
@@ -684,8 +684,10 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
684684
expect(clearedState.present).to.equal(incrementedState.present)
685685
})
686686
})
687+
688+
if (testConfig && testConfig.checkSlices) {
689+
687690
describe('running getSlices', () => {
688-
if (testConfig && testConfig.checkSlices) {
689691
const initialState = {
690692
normalState: 0,
691693
slice1: 100
@@ -713,7 +715,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
713715
let fifthState
714716
let sixthState
715717
let seventhState
716-
before('run reducer a few times', () => {
718+
beforeAll(() => {
717719
secondState = fullReducer(initialState, { type: 'BOGUS' })
718720
thirdState = fullReducer(secondState, { type: 'INCREMENT' })
719721
fourthState = fullReducer(thirdState, { type: ActionTypes.UNDO })
@@ -745,7 +747,7 @@ function runTests (label, { undoableConfig = {}, initialStoreState, testConfig }
745747
expect(seventhState.normalState.present).to.equal(sixthState.normalState.present - 1)
746748
expect(seventhState.slice1).to.equal(initialState.slice1)
747749
})
748-
}
749-
})
750+
})
751+
}
750752
})
751753
}

vite.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference types="vitest" />
2+
import { defineConfig } from 'vite'
3+
4+
export default defineConfig({
5+
test: {
6+
coverage: {
7+
provider: 'istanbul',
8+
reporter: ['text', 'lcov'],
9+
}
10+
},
11+
build: {
12+
lib: {
13+
entry: './src/index.js',
14+
name: 'ReduxUndo'
15+
}
16+
}
17+
})

0 commit comments

Comments
 (0)