diff --git a/packages/devui/package.json b/packages/devui/package.json
index e2cb7548..09373ed9 100755
--- a/packages/devui/package.json
+++ b/packages/devui/package.json
@@ -56,7 +56,7 @@
"eslint-plugin-react": "^4.3.0",
"file-loader": "^1.1.5",
"git-url-parse": "^7.0.1",
- "jest": "^21.2.1",
+ "jest": "^23.6.0",
"jsdom": "^11.3.0",
"node-sass": "^3.13.0",
"postcss-loader": "^2.0.8",
diff --git a/packages/devui/tests/__snapshots__/Select.test.js.snap b/packages/devui/tests/__snapshots__/Select.test.js.snap
index 93312ec9..5b6885bb 100644
--- a/packages/devui/tests/__snapshots__/Select.test.js.snap
+++ b/packages/devui/tests/__snapshots__/Select.test.js.snap
@@ -108,7 +108,7 @@ exports[`Select should select another option 1`] = `
autosize={true}
clearable={false}
menuMaxHeight={200}
- onChange={[Function]}
+ onChange={[MockFunction]}
options={
Array [
Object {
@@ -131,7 +131,7 @@ exports[`Select should select another option 1`] = `
autosize={true}
clearable={false}
menuMaxHeight={200}
- onChange={[Function]}
+ onChange={[MockFunction]}
options={
Array [
Object {
@@ -180,7 +180,7 @@ exports[`Select should select another option 1`] = `
multi={false}
noResultsText="No results found"
onBlurResetsInput={true}
- onChange={[Function]}
+ onChange={[MockFunction]}
onCloseResetsInput={true}
onSelectResetsInput={true}
openOnClick={true}
@@ -357,7 +357,7 @@ exports[`Select shouldn't find any results 1`] = `
autosize={true}
clearable={false}
menuMaxHeight={200}
- onChange={[Function]}
+ onChange={[MockFunction]}
options={
Array [
Object {
@@ -380,7 +380,7 @@ exports[`Select shouldn't find any results 1`] = `
autosize={true}
clearable={false}
menuMaxHeight={200}
- onChange={[Function]}
+ onChange={[MockFunction]}
options={
Array [
Object {
@@ -429,7 +429,7 @@ exports[`Select shouldn't find any results 1`] = `
multi={false}
noResultsText="No results found"
onBlurResetsInput={true}
- onChange={[Function]}
+ onChange={[MockFunction]}
onCloseResetsInput={true}
onSelectResetsInput={true}
openOnClick={true}
diff --git a/packages/map2tree/.eslintrc b/packages/map2tree/.eslintrc
index 90cecc39..317456ec 100755
--- a/packages/map2tree/.eslintrc
+++ b/packages/map2tree/.eslintrc
@@ -3,8 +3,11 @@
"env": {
"browser": true,
"node": true,
- "es6": true
+ "jest": true
+ },
+ "globals": {
+ "test": true,
+ "expect": true
},
-
"parser": "babel-eslint"
}
diff --git a/packages/map2tree/package.json b/packages/map2tree/package.json
index 2dff8dc8..81488f78 100755
--- a/packages/map2tree/package.json
+++ b/packages/map2tree/package.json
@@ -8,7 +8,7 @@
"build": "babel src --out-dir lib",
"build:umd": "webpack src/index.js dist/map2tree.js && NODE_ENV=production webpack src/index.js dist/map2tree.min.js",
"lint": "eslint src test",
- "test": "babel-node test/map2tree.js | tap-diff",
+ "test": "jest",
"check": "npm run lint && npm run test",
"prepare": "npm run build && npm run build:umd",
"prepublishOnly": "npm run check && npm run clean && npm run build && npm run build:umd"
@@ -40,10 +40,8 @@
"babel-preset-stage-0": "^6.3.13",
"eslint": "1.10.3",
"immutable": "3.7.6",
+ "jest": "^23.6.0",
"rimraf": "^2.3.4",
- "tap-diff": "0.1.1",
- "tap-spec": "4.1.1",
- "tape": "4.4.0",
"webpack": "1.12.13"
},
"dependencies": {
diff --git a/packages/map2tree/test/map2tree.js b/packages/map2tree/test/map2tree.spec.js
similarity index 57%
rename from packages/map2tree/test/map2tree.js
rename to packages/map2tree/test/map2tree.spec.js
index aecd86ab..eb9e577e 100755
--- a/packages/map2tree/test/map2tree.js
+++ b/packages/map2tree/test/map2tree.spec.js
@@ -1,17 +1,15 @@
-import test from 'tape';
import map2tree from '../src';
import immutable from 'immutable';
-test('# rootNodeKey', assert => {
+test('# rootNodeKey', () => {
const map = {};
const options = {key: 'foo'};
- assert.equal(map2tree(map, options).name, 'foo');
- assert.end();
+ expect(map2tree(map, options).name).toBe('foo');
});
-test('# shallow map', nest => {
- nest.test('## null', assert => {
+describe('# shallow map', () => {
+ test('## null', () => {
const map = {
a: null
};
@@ -23,12 +21,11 @@ test('# shallow map', nest => {
]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
});
- nest.test('## value', assert => {
+ test('## value', () => {
const map = {
a: 'foo',
b: 'bar'
@@ -42,12 +39,11 @@ test('# shallow map', nest => {
]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
});
- nest.test('## object', assert => {
+ test('## object', () => {
const map = {
a: {aa: 'foo'}
};
@@ -59,12 +55,11 @@ test('# shallow map', nest => {
]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
});
- nest.test('## immutable Map', assert => {
+ test('## immutable Map', () => {
const map = {
a: immutable.fromJS({aa: 'foo', ab: 'bar'})
};
@@ -76,13 +71,12 @@ test('# shallow map', nest => {
]
};
- assert.deepEqual(map2tree(map), expected);
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
})
});
-test('# deep map', nest => {
- nest.test('## null', assert => {
+describe('# deep map', () => {
+ test('## null', () => {
const map = {
a: {aa: null}
};
@@ -102,12 +96,11 @@ test('# deep map', nest => {
]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
});
- nest.test('## object', assert => {
+ test('## object', () => {
const map = {
a: {aa: {aaa: 'foo'}}
};
@@ -129,13 +122,12 @@ test('# deep map', nest => {
]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
});
});
-test('# array map', nest => {
+describe('# array map', () => {
const map = {
a: [
1,
@@ -143,7 +135,7 @@ test('# array map', nest => {
]
};
- nest.test('## push', assert => {
+ test('## push', () => {
const expected = {
name: 'state',
children: [{
@@ -154,12 +146,11 @@ test('# array map', nest => {
}]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
});
- nest.test('## unshift', assert => {
+ test('## unshift', () => {
const options = {pushMethod: 'unshift'};
const expected = {
name: 'state',
@@ -172,12 +163,11 @@ test('# array map', nest => {
}]
};
- assert.deepEqual(map2tree(map, options), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map), options), expected, 'immutable');
- assert.end();
+ expect(map2tree(map, options)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map), options)).toEqual(expected);
});
- nest.test('## null', assert => {
+ test('## null', () => {
const map = {
a: [
null
@@ -194,14 +184,13 @@ test('# array map', nest => {
}]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
})
});
-test('# collection map', nest => {
- nest.test('## value', assert => {
+describe('# collection map', () => {
+ test('## value', () => {
const map = {
a: [
{aa: 1},
@@ -222,12 +211,11 @@ test('# collection map', nest => {
]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
});
- nest.test('## object', assert => {
+ test('## object', () => {
const map = {
a: [
{aa: {aaa: 'foo'}}
@@ -246,8 +234,7 @@ test('# collection map', nest => {
]
};
- assert.deepEqual(map2tree(map), expected);
- assert.deepEqual(map2tree(immutable.fromJS(map)), expected, 'immutable');
- assert.end();
+ expect(map2tree(map)).toEqual(expected);
+ expect(map2tree(immutable.fromJS(map))).toEqual(expected);
})
});
diff --git a/packages/react-json-tree/.eslintrc b/packages/react-json-tree/.eslintrc
index 8f30c735..87372e7e 100644
--- a/packages/react-json-tree/.eslintrc
+++ b/packages/react-json-tree/.eslintrc
@@ -8,7 +8,7 @@
],
"env": {
"browser": true,
- "mocha": true,
+ "jest": true,
"node": true
},
"rules": {
diff --git a/packages/react-json-tree/package.json b/packages/react-json-tree/package.json
index b80a59e6..4b7cd4cd 100644
--- a/packages/react-json-tree/package.json
+++ b/packages/react-json-tree/package.json
@@ -9,14 +9,10 @@
"build:umd": "rimraf ./umd && webpack --progress --config webpack.config.umd.js",
"build:umd:min": "webpack --env.minimize --progress --config webpack.config.umd.js",
"lint": "eslint --max-warnings=0 src test examples/src",
- "test":
- "npm run lint && NODE_ENV=test mocha --compilers js:babel-core/register --recursive",
- "test:watch":
- "NODE_ENV=test mocha --compilers js:babel-core/register --recursive --watch",
- "test:cov":
- "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive",
+ "test": "jest",
"prepare": "npm run build",
- "prepublishOnly": "npm run test && npm run clean && npm run build && npm run build:umd && npm run build:umd:min",
+ "prepublishOnly":
+ "npm run lint && npm run test && npm run clean && npm run build && npm run build:umd && npm run build:umd:min",
"start": "cd examples && npm start",
"precommit": "lint-staged"
},
@@ -64,11 +60,9 @@
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-react": "7.4.0",
"eslint-plugin-standard": "^3.0.1",
- "expect": "^21.2.1",
"husky": "^0.14.3",
- "isparta": "^4.0.0",
+ "jest": "^23.6.0",
"lint-staged": "^4.3.0",
- "mocha": "^4.0.1",
"prettier": "^1.7.4",
"react": "^16.0.0",
"react-dom": "^16.0.0",
diff --git a/packages/react-json-tree/test/index.spec.js b/packages/react-json-tree/test/index.spec.js
index 550e484c..9e21fdb8 100644
--- a/packages/react-json-tree/test/index.spec.js
+++ b/packages/react-json-tree/test/index.spec.js
@@ -1,5 +1,4 @@
import React from 'react';
-import expect from 'expect';
import { createRenderer } from 'react-test-renderer/shallow';
import JSONTree from '../src/index';
diff --git a/packages/react-json-tree/test/objType.spec.js b/packages/react-json-tree/test/objType.spec.js
index 70b19bf5..c8ec51c6 100644
--- a/packages/react-json-tree/test/objType.spec.js
+++ b/packages/react-json-tree/test/objType.spec.js
@@ -1,5 +1,3 @@
-import expect from 'expect';
-
import objType from '../src/objType';
describe('objType', () => {
diff --git a/packages/redux-devtools-cli/package.json b/packages/redux-devtools-cli/package.json
index 067bc6c4..bd9e47e8 100644
--- a/packages/redux-devtools-cli/package.json
+++ b/packages/redux-devtools-cli/package.json
@@ -16,8 +16,7 @@
"scripts": {
"start": "node ./bin/redux-devtools.js",
"start:electron": "node ./bin/redux-devtools.js --open",
- "test": "NODE_ENV=test mocha --recursive",
- "test:watch": "NODE_ENV=test mocha --recursive --watch",
+ "test": "jest",
"prepublishOnly": "npm run test"
},
"repository": {
@@ -58,8 +57,7 @@
"uuid": "^3.0.1"
},
"devDependencies": {
- "expect": "^1.20.2",
- "mocha": "^3.2.0",
+ "jest": "^23.6.0",
"socketcluster-client": "^14.0.0",
"supertest": "^3.0.0"
}
diff --git a/packages/redux-devtools-cli/src/routes.js b/packages/redux-devtools-cli/src/routes.js
index 79724fc6..d2b5ac47 100644
--- a/packages/redux-devtools-cli/src/routes.js
+++ b/packages/redux-devtools-cli/src/routes.js
@@ -12,7 +12,7 @@ function serveUmdModule(name) {
app.use(express.static(require.resolve(name).match(/.*\/(node_modules|packages)\/[^/]+\//)[0] + 'umd'));
}
-function routes(options, store) {
+function routes(options, store, scServer) {
var limit = options.maxRequestBody;
var logHTTPRequests = options.logHTTPRequests;
diff --git a/packages/redux-devtools-cli/src/worker.js b/packages/redux-devtools-cli/src/worker.js
index 791e36df..623a52d4 100644
--- a/packages/redux-devtools-cli/src/worker.js
+++ b/packages/redux-devtools-cli/src/worker.js
@@ -13,7 +13,7 @@ class Worker extends SCWorker {
httpServer.on('request', app);
- app.use(routes(options, store));
+ app.use(routes(options, store, scServer));
scServer.addMiddleware(scServer.MIDDLEWARE_EMIT, function (req, next) {
var channel = req.event;
diff --git a/packages/redux-devtools-cli/test/integration.spec.js b/packages/redux-devtools-cli/test/integration.spec.js
index b5bf18ba..cd201784 100644
--- a/packages/redux-devtools-cli/test/integration.spec.js
+++ b/packages/redux-devtools-cli/test/integration.spec.js
@@ -1,31 +1,30 @@
var childProcess = require('child_process');
var request = require('supertest');
-var expect = require('expect');
var scClient = require('socketcluster-client');
describe('Server', function() {
var scServer;
- this.timeout(5000);
- before(function(done) {
+ beforeAll(function(done) {
scServer = childProcess.fork(__dirname + '/../bin/redux-devtools.js');
setTimeout(done, 2000);
});
- after(function() {
+ afterAll(function() {
if (scServer) {
scServer.kill();
}
});
describe('Express backend', function() {
- it('loads main page', function() {
+ it('loads main page', function(done) {
request('http://localhost:8000')
.get('/')
.expect('Content-Type', /text\/html/)
.expect(200)
.then(function(res) {
expect(res.text).toMatch(/
Redux DevTools<\/title>/);
- })
+ done();
+ });
});
it('resolves an inexistent url', function(done) {
@@ -38,7 +37,7 @@ describe('Server', function() {
describe('Realtime monitoring', function() {
var socket, socket2, channel;
- before(function() {
+ beforeAll(function() {
socket = scClient.connect({ hostname: 'localhost', port: 8000 });
socket.connect();
socket.on('error', function(error) {
@@ -51,14 +50,14 @@ describe('Server', function() {
});
});
- after(function() {
+ afterAll(function() {
socket.disconnect();
socket2.disconnect();
});
it('should connect', function(done) {
socket.on('connect', function(status) {
- expect(status.id).toExist();
+ expect(status.id).toBeTruthy();
done();
});
});
@@ -117,7 +116,7 @@ describe('Server', function() {
preloadedState: '{"todos":[{"text":"Use Redux","completed":false,"id":0}]}',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'
};
- it('should add a report', function() {
+ it('should add a report', function(done) {
request('http://localhost:8000')
.post('/')
.send(report)
@@ -126,11 +125,12 @@ describe('Server', function() {
.expect(200)
.then(function(res) {
id = res.body.id;
- expect(id).toExist();
+ expect(id).toBeTruthy();
+ done();
});
});
- it('should get the report', function() {
+ it('should get the report', function(done) {
request('http://localhost:8000')
.post('/')
.send({
@@ -141,11 +141,12 @@ describe('Server', function() {
.expect('Content-Type', /application\/json/)
.expect(200)
.then(function(res) {
- expect(res.body).toInclude(report);
+ expect.objectContaining(res.body, report);
+ done();
});
});
- it('should list reports', function() {
+ it('should list reports', function(done) {
request('http://localhost:8000')
.post('/')
.send({
@@ -158,13 +159,14 @@ describe('Server', function() {
expect(res.body.length).toBe(1);
expect(res.body[0].id).toBe(id);
expect(res.body[0].title).toBe('Test report');
- expect(res.body[0].added).toExist();
+ expect(res.body[0].added).toBeTruthy();
+ done();
});
});
});
describe('GraphQL backend', function() {
- it('should get the report', function() {
+ it('should get the report', function(done) {
request('http://localhost:8000')
.post('/graphql')
.send({
@@ -176,9 +178,10 @@ describe('Server', function() {
.then(function(res) {
var reports = res.body.data.reports;
expect(reports.length).toBe(1);
- expect(reports[0].id).toExist();
+ expect(reports[0].id).toBeTruthy();
expect(reports[0].title).toBe('Test report');
expect(reports[0].type).toBe('ACTIONS');
+ done();
});
});
});
diff --git a/packages/redux-devtools-core/package.json b/packages/redux-devtools-core/package.json
index 21c83777..9de6458b 100644
--- a/packages/redux-devtools-core/package.json
+++ b/packages/redux-devtools-core/package.json
@@ -11,7 +11,7 @@
"clean": "rimraf lib",
"lint": "eslint src test",
"lint:fix": "eslint src --fix",
- "test": "NODE_ENV=test jest --no-cache",
+ "test": "jest --no-cache",
"prepare": "npm run build && npm run build:umd && npm run build:umd:min",
"prepublishOnly": "eslint ./src/app && npm run test && npm run build && npm run build:umd && npm run build:umd:min"
},
@@ -63,7 +63,7 @@
"file-loader": "^3.0.0",
"html-loader": "^0.4.4",
"html-webpack-plugin": "^3.2.0",
- "jest": "^21.2.1",
+ "jest": "^23.6.0",
"raw-loader": "^1.0.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
diff --git a/packages/redux-devtools-instrument/.eslintrc b/packages/redux-devtools-instrument/.eslintrc
index 47dc0576..4b8bb22e 100644
--- a/packages/redux-devtools-instrument/.eslintrc
+++ b/packages/redux-devtools-instrument/.eslintrc
@@ -2,7 +2,7 @@
"extends": "eslint-config-airbnb",
"env": {
"browser": true,
- "mocha": true,
+ "jest": true,
"node": true
},
"rules": {
diff --git a/packages/redux-devtools-instrument/package.json b/packages/redux-devtools-instrument/package.json
index d290bd59..7b72813f 100644
--- a/packages/redux-devtools-instrument/package.json
+++ b/packages/redux-devtools-instrument/package.json
@@ -7,9 +7,7 @@
"clean": "rimraf lib",
"build": "babel src --out-dir lib",
"lint": "eslint src test",
- "test": "NODE_ENV=test mocha --compilers js:babel-core/register --recursive",
- "test:watch": "NODE_ENV=test mocha --compilers js:babel-core/register --recursive --watch",
- "test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive",
+ "test": "jest",
"prepare": "npm run build",
"prepublishOnly": "npm run lint && npm run test && npm run clean && npm run build"
},
@@ -46,8 +44,7 @@
"eslint-config-airbnb": "0.0.6",
"eslint-plugin-react": "^2.3.0",
"expect": "^1.6.0",
- "isparta": "^3.0.3",
- "mocha": "^2.2.5",
+ "jest": "^23.6.0",
"redux": "^4.0.0",
"rimraf": "^2.3.4",
"rxjs": "^5.0.0-beta.6",
diff --git a/packages/redux-devtools-instrument/test/instrument.spec.js b/packages/redux-devtools-instrument/test/instrument.spec.js
index f1512715..8ace990d 100644
--- a/packages/redux-devtools-instrument/test/instrument.spec.js
+++ b/packages/redux-devtools-instrument/test/instrument.spec.js
@@ -1,4 +1,3 @@
-import expect, { spyOn } from 'expect';
import { createStore, compose } from 'redux';
import instrument, { ActionCreators } from '../src/instrument';
import { Observable } from 'rxjs';
@@ -280,7 +279,7 @@ describe('instrument', () => {
});
it('should catch and record errors', () => {
- let spy = spyOn(console, 'error');
+ let spy = jest.spyOn(console, 'error').mockImplementation(() => {});;
let storeWithBug = createStore(
counterWithBug,
instrument(undefined, { shouldCatchErrors: true })
@@ -297,11 +296,11 @@ describe('instrument', () => {
expect(computedStates[3].error).toMatch(
/Interrupted by an error up the chain/
);
- expect(spy.calls[0].arguments[0].toString()).toMatch(
+ expect(spy.mock.calls[0][0].toString()).toMatch(
/ReferenceError/
);
- spy.restore();
+ spy.mockReset();
});
it('should catch invalid action type', () => {
@@ -453,7 +452,7 @@ describe('instrument', () => {
expect(configuredStore.getState()).toBe(2);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
expect(liftedStoreState.committedState).toBe(undefined);
- expect(liftedStoreState.stagedActionIds).toInclude(1);
+ expect(liftedStoreState.stagedActionIds).toContain(1);
// Trigger auto-commit.
configuredStore.dispatch({ type: 'INCREMENT' });
@@ -461,7 +460,7 @@ describe('instrument', () => {
expect(configuredStore.getState()).toBe(3);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
- expect(liftedStoreState.stagedActionIds).toExclude(1);
+ expect(liftedStoreState.stagedActionIds).not.toContain(1);
expect(liftedStoreState.computedStates[0].state).toBe(1);
expect(liftedStoreState.committedState).toBe(1);
expect(liftedStoreState.currentStateIndex).toBe(2);
@@ -471,13 +470,13 @@ describe('instrument', () => {
configuredStore.dispatch({ type: 'INCREMENT' });
configuredLiftedStore.dispatch(ActionCreators.toggleAction(1));
configuredStore.dispatch({ type: 'INCREMENT' });
- expect(configuredLiftedStore.getState().skippedActionIds).toInclude(1);
+ expect(configuredLiftedStore.getState().skippedActionIds).toContain(1);
configuredStore.dispatch({ type: 'INCREMENT' });
- expect(configuredLiftedStore.getState().skippedActionIds).toExclude(1);
+ expect(configuredLiftedStore.getState().skippedActionIds).not.toContain(1);
});
it('should not auto-commit errors', () => {
- let spy = spyOn(console, 'error');
+ let spy = jest.spyOn(console, 'error');
let storeWithBug = createStore(
counterWithBug,
@@ -491,11 +490,11 @@ describe('instrument', () => {
storeWithBug.dispatch({ type: 'INCREMENT' });
expect(liftedStoreWithBug.getState().stagedActionIds.length).toBe(4);
- spy.restore();
+ spy.mockReset();
});
it('should auto-commit actions after hot reload fixes error', () => {
- let spy = spyOn(console, 'error');
+ let spy = jest.spyOn(console, 'error');
let storeWithBug = createStore(
counterWithBug,
@@ -518,7 +517,7 @@ describe('instrument', () => {
storeWithBug.replaceReducer(counter);
expect(liftedStoreWithBug.getState().stagedActionIds.length).toBe(3);
- spy.restore();
+ spy.mockReset();
});
it('should update currentStateIndex when auto-committing', () => {
@@ -539,7 +538,7 @@ describe('instrument', () => {
});
it('should continue to increment currentStateIndex while error blocks commit', () => {
- let spy = spyOn(console, 'error');
+ let spy = jest.spyOn(console, 'error');
let storeWithBug = createStore(
counterWithBug,
@@ -556,13 +555,13 @@ describe('instrument', () => {
let currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex];
expect(liftedStoreState.currentStateIndex).toBe(4);
expect(currentComputedState.state).toBe(0);
- expect(currentComputedState.error).toExist();
+ expect(currentComputedState.error).toBeTruthy();
- spy.restore();
+ spy.mockReset();
});
it('should adjust currentStateIndex correctly when multiple actions are committed', () => {
- let spy = spyOn(console, 'error');
+ let spy = jest.spyOn(console, 'error');
let storeWithBug = createStore(
counterWithBug,
@@ -582,11 +581,11 @@ describe('instrument', () => {
expect(liftedStoreState.currentStateIndex).toBe(2);
expect(currentComputedState.state).toBe(-4);
- spy.restore();
+ spy.mockReset();
});
it('should not allow currentStateIndex to drop below 0', () => {
- let spy = spyOn(console, 'error');
+ let spy = jest.spyOn(console, 'error');
let storeWithBug = createStore(
counterWithBug,
@@ -607,33 +606,33 @@ describe('instrument', () => {
expect(liftedStoreState.currentStateIndex).toBe(0);
expect(currentComputedState.state).toBe(-2);
- spy.restore();
+ spy.mockReset();
});
it('should use dynamic maxAge', () => {
let max = 3;
- const getMaxAge = expect.createSpy().andCall(() => max);
+ const getMaxAge = jest.fn().mockImplementation(() => max);
store = createStore(counter, instrument(undefined, { maxAge: getMaxAge }));
- expect(getMaxAge.calls.length).toEqual(1);
+ expect(getMaxAge.mock.calls.length).toEqual(1);
store.dispatch({ type: 'INCREMENT' });
- expect(getMaxAge.calls.length).toEqual(2);
+ expect(getMaxAge.mock.calls.length).toEqual(2);
store.dispatch({ type: 'INCREMENT' });
- expect(getMaxAge.calls.length).toEqual(3);
+ expect(getMaxAge.mock.calls.length).toEqual(3);
let liftedStoreState = store.liftedStore.getState();
- expect(getMaxAge.calls[0].arguments[0].type).toInclude('INIT');
- expect(getMaxAge.calls[0].arguments[1]).toBe(undefined);
- expect(getMaxAge.calls[1].arguments[0].type).toBe('PERFORM_ACTION');
- expect(getMaxAge.calls[1].arguments[1].nextActionId).toBe(1);
- expect(getMaxAge.calls[1].arguments[1].stagedActionIds).toEqual([0]);
- expect(getMaxAge.calls[2].arguments[1].nextActionId).toBe(2);
- expect(getMaxAge.calls[2].arguments[1].stagedActionIds).toEqual([0, 1]);
+ expect(getMaxAge.mock.calls[0][0].type).toContain('INIT');
+ expect(getMaxAge.mock.calls[0][1]).toBe(undefined);
+ expect(getMaxAge.mock.calls[1][0].type).toBe('PERFORM_ACTION');
+ expect(getMaxAge.mock.calls[1][1].nextActionId).toBe(1);
+ expect(getMaxAge.mock.calls[1][1].stagedActionIds).toEqual([0]);
+ expect(getMaxAge.mock.calls[2][1].nextActionId).toBe(2);
+ expect(getMaxAge.mock.calls[2][1].stagedActionIds).toEqual([0, 1]);
expect(store.getState()).toBe(2);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
expect(liftedStoreState.committedState).toBe(undefined);
- expect(liftedStoreState.stagedActionIds).toInclude(1);
+ expect(liftedStoreState.stagedActionIds).toContain(1);
// Trigger auto-commit.
store.dispatch({ type: 'INCREMENT' });
@@ -641,7 +640,7 @@ describe('instrument', () => {
expect(store.getState()).toBe(3);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
- expect(liftedStoreState.stagedActionIds).toExclude(1);
+ expect(liftedStoreState.stagedActionIds).not.toContain(1);
expect(liftedStoreState.computedStates[0].state).toBe(1);
expect(liftedStoreState.committedState).toBe(1);
expect(liftedStoreState.currentStateIndex).toBe(2);
@@ -652,7 +651,7 @@ describe('instrument', () => {
expect(store.getState()).toBe(4);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(4);
- expect(liftedStoreState.stagedActionIds).toExclude(1);
+ expect(liftedStoreState.stagedActionIds).not.toContain(1);
expect(liftedStoreState.computedStates[0].state).toBe(1);
expect(liftedStoreState.committedState).toBe(1);
expect(liftedStoreState.currentStateIndex).toBe(3);
@@ -663,7 +662,7 @@ describe('instrument', () => {
expect(store.getState()).toBe(5);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
- expect(liftedStoreState.stagedActionIds).toExclude(1);
+ expect(liftedStoreState.stagedActionIds).not.toContain(1);
expect(liftedStoreState.computedStates[0].state).toBe(3);
expect(liftedStoreState.committedState).toBe(3);
expect(liftedStoreState.currentStateIndex).toBe(2);
@@ -673,7 +672,7 @@ describe('instrument', () => {
expect(store.getState()).toBe(6);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
- expect(liftedStoreState.stagedActionIds).toExclude(1);
+ expect(liftedStoreState.stagedActionIds).not.toContain(1);
expect(liftedStoreState.computedStates[0].state).toBe(4);
expect(liftedStoreState.committedState).toBe(4);
expect(liftedStoreState.currentStateIndex).toBe(2);
@@ -702,18 +701,27 @@ describe('instrument', () => {
});
it('should include stack trace', () => {
- monitoredStore = createStore(counter, instrument(undefined, { trace: true }));
- monitoredLiftedStore = monitoredStore.liftedStore;
- monitoredStore.dispatch({ type: 'INCREMENT' });
+ function fn1() {
+ monitoredStore = createStore(counter, instrument(undefined, { trace: true }));
+ monitoredLiftedStore = monitoredStore.liftedStore;
+ monitoredStore.dispatch({ type: 'INCREMENT' });
- exportedState = monitoredLiftedStore.getState();
- expect(exportedState.actionsById[0].stack).toBe(undefined);
- expect(exportedState.actionsById[1].stack).toBeA('string');
- expect(exportedState.actionsById[1].stack).toMatch(/^Error/);
- expect(exportedState.actionsById[1].stack).toNotMatch(/instrument.js/);
- expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
- expect(exportedState.actionsById[1].stack).toContain('/mocha/');
- expect(exportedState.actionsById[1].stack.split('\n').length).toBe(10 + 1); // +1 is for `Error\n`
+ exportedState = monitoredLiftedStore.getState();
+ expect(exportedState.actionsById[0].stack).toBe(undefined);
+ expect(typeof exportedState.actionsById[1].stack).toBe('string');
+ expect(exportedState.actionsById[1].stack).toMatch(/^Error/);
+ expect(exportedState.actionsById[1].stack).not.toMatch(/instrument.js/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn1\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn2\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn3\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn4\b/);
+ expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
+ expect(exportedState.actionsById[1].stack.split('\n').length).toBe(10 + 1); // +1 is for `Error\n`
+ }
+ function fn2() { return fn1(); }
+ function fn3() { return fn2(); }
+ function fn4() { return fn3(); }
+ fn4();
});
it('should include only 3 frames for stack trace', () => {
@@ -724,11 +732,12 @@ describe('instrument', () => {
exportedState = monitoredLiftedStore.getState();
expect(exportedState.actionsById[0].stack).toBe(undefined);
- expect(exportedState.actionsById[1].stack).toBeA('string');
- expect(exportedState.actionsById[1].stack).toMatch(/at fn1 /);
- expect(exportedState.actionsById[1].stack).toMatch(/at fn2 /);
- expect(exportedState.actionsById[1].stack).toMatch(/at fn3 /);
- expect(exportedState.actionsById[1].stack).toNotMatch(/at fn4 /);
+ expect(typeof exportedState.actionsById[1].stack).toBe('string');
+ expect(exportedState.actionsById[1].stack).toMatch(/\bat dispatch\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn1\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn2\b/);
+ expect(exportedState.actionsById[1].stack).not.toMatch(/\bfn3\b/);
+ expect(exportedState.actionsById[1].stack).not.toMatch(/\bfn4\b/);
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
expect(exportedState.actionsById[1].stack.split('\n').length).toBe(3 + 1);
}
@@ -748,11 +757,12 @@ describe('instrument', () => {
exportedState = monitoredLiftedStore.getState();
expect(exportedState.actionsById[0].stack).toBe(undefined);
- expect(exportedState.actionsById[1].stack).toBeA('string');
- expect(exportedState.actionsById[1].stack).toMatch(/at fn1 /);
- expect(exportedState.actionsById[1].stack).toMatch(/at fn2 /);
- expect(exportedState.actionsById[1].stack).toMatch(/at fn3 /);
- expect(exportedState.actionsById[1].stack).toNotMatch(/at fn4 /);
+ expect(typeof exportedState.actionsById[1].stack).toBe('string');
+ expect(exportedState.actionsById[1].stack).toMatch(/\bat dispatch\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn1\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn2\b/);
+ expect(exportedState.actionsById[1].stack).not.toMatch(/\bfn3\b/);
+ expect(exportedState.actionsById[1].stack).not.toMatch(/\bfn4\b/);
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
expect(exportedState.actionsById[1].stack.split('\n').length).toBe(3 + 1);
}
@@ -773,10 +783,9 @@ describe('instrument', () => {
exportedState = monitoredLiftedStore.getState();
expect(exportedState.actionsById[0].stack).toBe(undefined);
- expect(exportedState.actionsById[1].stack).toBeA('string');
+ expect(typeof exportedState.actionsById[1].stack).toBe('string');
expect(exportedState.actionsById[1].stack).toMatch(/^Error/);
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
- expect(exportedState.actionsById[1].stack).toContain('/mocha/');
expect(exportedState.actionsById[1].stack.split('\n').length).toBe(5 + 1);
});
@@ -791,11 +800,11 @@ describe('instrument', () => {
exportedState = monitoredLiftedStore.getState();
expect(exportedState.actionsById[0].stack).toBe(undefined);
- expect(exportedState.actionsById[1].stack).toBeA('string');
- expect(exportedState.actionsById[1].stack).toMatch(/at fn1 /);
- expect(exportedState.actionsById[1].stack).toMatch(/at fn2 /);
- expect(exportedState.actionsById[1].stack).toMatch(/at fn3 /);
- expect(exportedState.actionsById[1].stack).toMatch(/at fn4 /);
+ expect(typeof exportedState.actionsById[1].stack).toBe('string');
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn1\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn2\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn3\b/);
+ expect(exportedState.actionsById[1].stack).toMatch(/\bfn4\b/);
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
expect(exportedState.actionsById[1].stack.split('\n').length).toBe(10 + 1);
}
@@ -815,11 +824,10 @@ describe('instrument', () => {
exportedState = monitoredLiftedStore.getState();
expect(exportedState.actionsById[0].stack).toBe(undefined);
- expect(exportedState.actionsById[1].stack).toBeA('string');
+ expect(typeof exportedState.actionsById[1].stack).toBe('string');
expect(exportedState.actionsById[1].stack).toMatch(/^Error/);
expect(exportedState.actionsById[1].stack).toContain('instrument.js');
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
- expect(exportedState.actionsById[1].stack).toContain('/mocha/');
expect(exportedState.actionsById[1].stack.split('\n').length).toBe(5 + 3 + 1);
});
@@ -831,11 +839,10 @@ describe('instrument', () => {
exportedState = monitoredLiftedStore.getState();
expect(exportedState.actionsById[0].stack).toBe(undefined);
- expect(exportedState.actionsById[1].stack).toBeA('string');
- expect(exportedState.actionsById[1].stack).toContain('at Object.performAction');
+ expect(typeof exportedState.actionsById[1].stack).toBe('string');
+ expect(exportedState.actionsById[1].stack).toContain('at performAction');
expect(exportedState.actionsById[1].stack).toContain('instrument.js');
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
- expect(exportedState.actionsById[1].stack).toContain('/mocha/');
});
it('should get stack trace inside setTimeout using a function', (done) => {
@@ -848,11 +855,10 @@ describe('instrument', () => {
exportedState = monitoredLiftedStore.getState();
expect(exportedState.actionsById[0].stack).toBe(undefined);
- expect(exportedState.actionsById[1].stack).toBeA('string');
- expect(exportedState.actionsById[1].stack).toContain('at Object.performAction');
+ expect(typeof exportedState.actionsById[1].stack).toBe('string');
+ expect(exportedState.actionsById[1].stack).toContain('at performAction');
expect(exportedState.actionsById[1].stack).toContain('instrument.js');
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
- expect(exportedState.actionsById[1].stack).toContain('/mocha/');
done();
});
});
@@ -917,7 +923,7 @@ describe('instrument', () => {
const oldState = importMonitoredLiftedStore.getState();
expect(oldState.actionsById[0].stack).toBe(undefined);
- expect(oldState.actionsById[1].stack).toBeA('string');
+ expect(typeof oldState.actionsById[1].stack).toBe('string');
importMonitoredLiftedStore.dispatch(ActionCreators.importState(oldState));
expect(importMonitoredLiftedStore.getState()).toEqual(oldState);
@@ -982,7 +988,7 @@ describe('instrument', () => {
importMonitoredLiftedStore.dispatch(ActionCreators.importState(savedActions));
expect(importMonitoredLiftedStore.getState().actionsById[0].stack).toBe(undefined);
- expect(importMonitoredLiftedStore.getState().actionsById[1].stack).toBeA('string');
+ expect(typeof importMonitoredLiftedStore.getState().actionsById[1].stack).toBe('string');
expect(filterStackAndTimestamps(importMonitoredLiftedStore.getState())).toEqual(exportedState);
});
});
diff --git a/packages/redux-devtools/package.json b/packages/redux-devtools/package.json
index 505b5f3d..a081a2c6 100644
--- a/packages/redux-devtools/package.json
+++ b/packages/redux-devtools/package.json
@@ -7,9 +7,7 @@
"clean": "rimraf lib",
"build": "babel src --out-dir lib",
"lint": "eslint src test examples",
- "test": "cross-env NODE_ENV=test mocha --compilers js:babel-core/register --recursive",
- "test:watch": "cross-env NODE_ENV=test mocha --compilers js:babel-core/register --recursive --watch",
- "test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive",
+ "test": "jest",
"prepare": "npm run build",
"prepublishOnly": "npm run lint && npm run test && npm run clean && npm run build"
},
@@ -43,15 +41,10 @@
"babel-preset-es2015-loose": "^6.1.3",
"babel-preset-react": "6.3.13",
"babel-preset-stage-0": "^6.3.13",
- "cross-env": "3.1.3",
"eslint": "^0.23",
"eslint-config-airbnb": "0.0.6",
"eslint-plugin-react": "^2.3.0",
- "expect": "^1.6.0",
- "isparta": "^3.0.3",
- "jsdom": "^6.5.1",
- "mocha": "^2.2.5",
- "mocha-jsdom": "^1.0.0",
+ "jest": "^23.6.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-redux": "^6.0.0",
diff --git a/packages/redux-devtools/test/persistState.spec.js b/packages/redux-devtools/test/persistState.spec.js
index 763b6da7..c7d5f4ad 100644
--- a/packages/redux-devtools/test/persistState.spec.js
+++ b/packages/redux-devtools/test/persistState.spec.js
@@ -1,9 +1,9 @@
-import expect from 'expect';
import { instrument, persistState } from '../src';
import { compose, createStore } from 'redux';
describe('persistState', () => {
let savedLocalStorage = global.localStorage;
+ delete global.localStorage;
beforeEach(() => {
global.localStorage = {
@@ -23,7 +23,7 @@ describe('persistState', () => {
};
});
- after(() => {
+ afterAll(() => {
global.localStorage = savedLocalStorage;
});
@@ -89,29 +89,23 @@ describe('persistState', () => {
});
it('should warn if read from localStorage fails', () => {
- const spy = expect.spyOn(console, 'warn');
+ const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
delete global.localStorage.getItem;
createStore(reducer, compose(instrument(), persistState('id')));
- expect(spy.calls).toContain(
- /Could not read debug session from localStorage/,
- (call, errMsg) => call.arguments[0].match(errMsg)
- );
+ expect(spy.mock.calls[0]).toContain('Could not read debug session from localStorage:');
- spy.restore();
+ spy.mockReset();
});
it('should warn if write to localStorage fails', () => {
- const spy = expect.spyOn(console, 'warn');
+ const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
delete global.localStorage.setItem;
const store = createStore(reducer, compose(instrument(), persistState('id')));
store.dispatch({ type: 'INCREMENT' });
- expect(spy.calls).toContain(
- /Could not write debug session to localStorage/,
- (call, errMsg) => call.arguments[0].match(errMsg)
- );
+ expect(spy.mock.calls[0]).toContain('Could not write debug session to localStorage:');
- spy.restore();
+ spy.mockReset();
});
});