Commit 6910da22 authored by Benjamin Chodoroff's avatar Benjamin Chodoroff
Browse files

Revert "Merge pull request #2274 from steemit/revert-2235"

closes #2203

This reverts commit 1c145127, reversing
changes made to a665b02e.

stick with it

fix mocha syntax in updated htmlready test

peg versions

set root dir, avoid testing transpiled code in lib
parent 85096655
......@@ -9,10 +9,7 @@
"main": "index.js",
"scripts": {
"build": "NODE_ENV=production webpack --config ./webpack/prod.config.js; rm -rf ./lib; babel src --out-dir lib -Dq",
"mocha": "NODE_ENV=test mocha ./mocha.setup.js",
"test": "npm run mocha -- src/app/**/*.test.js src/shared/**/*.test.js",
"test:watch:all": "npm test -- --watch --watch-extensions jsx",
"test:watch": "npm run mocha -- --watch --watch-extensions jsx",
"test": "jest",
"eslint": "LIST=`git diff-index --name-only HEAD | grep .*\\.js | grep -v json`; if [ \"$LIST\" ]; then eslint $LIST; fi",
"fmt": "prettier --config .prettierrc --write 'src/**/*.js*'",
"precommit": "lint-staged",
......@@ -21,7 +18,7 @@
"webpush": "node ./scripts/webpush_notify.js",
"checktranslations": "node scripts/check_translations.js",
"storybook": "start-storybook -p 9001 -c .storybook",
"storybook-build": "build-storybook -c .storybook -o docs"
"storybook-build": "build-storybook -c .storybook -o docs"
},
"author": "Steemit, Inc.",
"license": "MIT",
......@@ -31,7 +28,7 @@
"assert": "^1.3.0",
"autoprefixer-loader": "^3.2.0",
"babel-cli": "^6.22.2",
"babel-core": "^6.20.0",
"babel-core": "6.26.0",
"babel-eslint": "^6.0.4",
"babel-loader": "^7.1.2",
"babel-plugin-react-intl": "^2.2.0",
......@@ -98,12 +95,12 @@
"picturefill": "^3.0.2",
"purest": "^2.0.1",
"raw-loader": "^0.5.1",
"react": "15.4.2",
"react": "15.6.2",
"react-ab-test": "^1.7.0",
"react-addons-pure-render-mixin": "15.4.2",
"react-autocomplete": "^1.7.2",
"react-copy-to-clipboard": "^4.2.3",
"react-dom": "15.4.2",
"react-dom": "15.6.2",
"react-dropzone": "^3.7.3",
"react-foundation-components": "git+https://github.com/valzav/react-foundation-components.git#d14362c7c8eee946a4acc3b18d70271d5a82813e",
"react-highcharts": "^8.3.3",
......@@ -154,14 +151,12 @@
"devDependencies": {
"@storybook/addon-knobs": "^3.2.17",
"@storybook/react": "^3.2.16",
"babel-jest": "22.0.6",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"chai": "^3.5.0",
"chai-immutable": "^1.5.3",
"co-mocha": "^1.1.2",
"co-supertest": "0.0.10",
"dev-ip": "^1.0.1",
"dirty-chai": "^1.2.2",
"enzyme": "^2.1.0",
"enzyme": "3.3.0",
"enzyme-adapter-react-15": "1.0.5",
"escope": "^3.6.0",
"eslint": "^4.7.0",
"eslint-config-airbnb": "^15.1.0",
......@@ -171,19 +166,20 @@
"eslint-plugin-react": "^7.4.0",
"extract-text-webpack-plugin": "^3.0.0",
"husky": "^0.14.3",
"jest": "22.0.6",
"jsdom": "^9.8.0",
"koa-webpack-dev-middleware": "^1.1.0",
"koa-webpack-hot-middleware": "^1.0.3",
"lint-staged": "^6.0.0",
"mocha": "^2.4.5",
"node-watch": "^0.5.5",
"prettier": "1.8.2",
"react-addons-perf": "15.4.2",
"react-addons-test-utils": "15.4.2",
"react-test-renderer": "15.6.2",
"react-transform-catch-errors": "^1.0.1",
"react-transform-hmr": "^1.0.4",
"regenerator-runtime": "0.11.1",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"supertest": "^1.2.0",
"webpack-bundle-analyzer": "^2.9.0"
},
......@@ -199,5 +195,14 @@
"prettier --write",
"git add"
]
},
"jest": {
"rootDir": "src",
"modulePaths": [
"<rootDir>/"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js"
}
}
}
module.exports = 'test-file-stub';
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, date } from '@storybook/addon-knobs';
import { IntlProvider } from 'react-intl';
import TimeAgoWrapper from './';
storiesOf('Elements', module)
.addDecorator(withKnobs)
.add('TimeAgoWrapper', () => (
<IntlProvider locale="en">
<TimeAgoWrapper date={date('date', new Date('1 Jul 2016'))} />
</IntlProvider>
));
/*global describe, it, before, beforeEach, after, afterEach */
import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import { configure, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
import { _Header_ } from './Header';
configure({ adapter: new Adapter() });
describe('Header', () => {
it('contains class .header', () => {
expect(shallow(<_Header_ />).is('.Header')).to.equal(true);
expect(
shallow(<_Header_ location={{ pathname: 'whatever' }} />).is(
'.Header'
)
).toBe(true);
});
});
import chai, { expect } from 'chai';
import chaiImmutable from 'chai-immutable';
import { Map, OrderedMap, getIn } from 'immutable';
import reducer, {
......@@ -16,8 +13,6 @@ import reducer, {
toggleBlogmode,
} from './AppReducer';
chai.use(chaiImmutable);
const mockPayloads = {
addNotification: {
key: 'testKey',
......@@ -63,32 +58,32 @@ const mockNotification = OrderedMap({
describe('App reducer', () => {
it('should provide a nice initial state', () => {
const initial = reducer();
expect(initial).to.equal(defaultState);
expect(initial).toBe(defaultState);
});
it('should return correct state for a LOCATION_CHANGE action', () => {
const initial = reducer();
const actual = reducer(initial, mockActions['LOCATION_CHANGE']);
const out = actual.get('location');
expect(out.pathname).to.eql(
expect(out.pathname).toEqual(
mockActions['LOCATION_CHANGE'].payload.pathname
);
});
it('should return correct state for a STEEM_API_ERROR action', () => {
const initial = reducer();
const out = reducer(initial, steemApiError());
expect(out).to.eql(initial);
expect(out).toEqual(initial);
});
it('should return correct state for a FETCH_DATA_BEGIN action', () => {
const initial = reducer();
const actual = reducer(initial, fetchDataBegin());
const out = actual.get('loading');
expect(out).to.eql(true);
expect(out).toEqual(true);
});
it('should return correct state for a FETCH_DATA_END action', () => {
const initial = reducer();
const actual = reducer(initial, fetchDataEnd());
const out = actual.get('loading');
expect(out).to.eql(false);
expect(out).toEqual(false);
});
it('should return correct state for a ADD_NOTIFICATION action', () => {
const initial = reducer();
......@@ -97,7 +92,7 @@ describe('App reducer', () => {
addNotification(mockPayloads.addNotification)
);
const out = actual.getIn(['notifications', key]);
expect(out).to.eql(mockNotification.get(key));
expect(out).toEqual(mockNotification.get(key));
});
it('should return correct state for a REMOVE_NOTIFICATION action', () => {
const initial = reducer();
......@@ -111,7 +106,7 @@ describe('App reducer', () => {
);
const out = actual.get('notifications');
const expected = OrderedMap();
expect(out).to.eql(expected);
expect(out).toEqual(expected);
});
it('should return correct state for a UPDATE_NOTIFICOUNTERS action with a follow in payload', () => {
const initial = reducer();
......@@ -121,7 +116,7 @@ describe('App reducer', () => {
);
let out = actual.get('notificounters');
let expected = Map({ follow: 0, total: 1 });
expect(out).to.eql(expected);
expect(out).toEqual(expected);
});
it('should return correct state for a UPDATE_NOTIFICOUNTERS action with no follow in payload', () => {
const initial = reducer();
......@@ -131,7 +126,7 @@ describe('App reducer', () => {
);
const out = actual.get('notificounters');
const expected = Map({ follow: 0, total: 2 });
expect(out).to.eql(expected);
expect(out).toEqual(expected);
});
it('should return correct state for a SET_USER_PREFERENCES action', () => {
const initial = reducer();
......@@ -141,20 +136,20 @@ describe('App reducer', () => {
);
let out = actual.get('user_preferences');
let expected = Map({ cat: 'mymy', dog: 'polly' });
expect(out).to.eql(expected);
expect(out).toEqual(expected);
});
it('should return correct state for a TOGGLE_NIGHTMODE action', () => {
const initial = reducer();
const before = initial.getIn(['user_preferences', 'nightmode']);
let actual = reducer(initial, toggleNightmode());
const after = actual.getIn(['user_preferences', 'nightmode']);
expect(after).to.eql(!before);
expect(after).toEqual(!before);
});
it('should return correct state for a TOGGLE_BLOGMODE action', () => {
const initial = reducer();
const before = initial.getIn(['user_preferences', 'blogmode']);
let actual = reducer(initial, toggleBlogmode());
const after = actual.getIn(['user_preferences', 'blogmode']);
expect(after).to.eql(!before);
expect(after).toEqual(!before);
});
});
/*global describe, it, before, beforeEach, after, afterEach */
import chai, { expect } from 'chai';
import dirtyChai from 'dirty-chai';
import sinon from 'sinon';
import { call, put } from 'redux-saga/effects';
import { fetchState } from './FetchDataSaga';
chai.use(dirtyChai);
const action = {
payload: {
pathname: '/recent',
search: '',
action: 'PUSH',
},
};
describe('sagas', () => {
// not maintained
// it('should fetch state and submit RECEIVE_STATE action', () => {
// const url = '/recent';
// const db_api = Apis.instance().db_api;
// const expectedCallResult = call([db_api, db_api.exec], 'get_state', [url]);
// const generator = fetchState(action);
// const callResult = generator.next().value;
// expect(
// callResult.CALL.args
// ).to.be.eql(expectedCallResult.CALL.args);
//
// const expectedPutResult = put({type: 'global/RECEIVE_STATE', payload: undefined});
// const putResult = generator.next().value;
// expect(
// putResult
// ).to.be.eql(expectedPutResult);
// });
//
// it('should try to fetch state and submit STEEM_API_ERROR if failed', () => {
// const generator = fetchState(action);
// expect(generator.next().value).to.be.ok();
// const result = generator.throw({message: 'test error'}).value;
// const expectedPutResult = put({type: 'global/STEEM_API_ERROR', error: 'test error'});
// expect(
// result
// ).to.be.eql(expectedPutResult);
// });
//
// it('should try to fetch state and submit STEEM_API_ERROR if failed', () => {
// const pop_action = {payload: {...action.payload, action: 'POP'}};
// const generator = fetchState(pop_action);
// const result = generator.next().value;
// expect(result).to.be.null();
// });
});
import chai, { expect } from 'chai';
import chaiImmutable from 'chai-immutable';
import { Map } from 'immutable';
import reducer, {
......@@ -8,8 +5,6 @@ import reducer, {
toggleOpenOrdersSort,
} from './MarketReducer';
chai.use(chaiImmutable);
const someOpenOrders = [
{
id: 1127826,
......@@ -92,7 +87,7 @@ describe('market reducer', () => {
it('should provide a nice initial state', () => {
const initial = reducer();
expect(initial.get('open_orders_sort')).to.equal(
expect(initial.get('open_orders_sort')).toEqual(
Map({
column: 'created',
dataType: 'string',
......@@ -100,7 +95,7 @@ describe('market reducer', () => {
})
);
expect(initial.get('status')).to.deep.equal({});
expect(initial.get('status')).toEqual({});
});
it('should receive open orders', () => {
......@@ -110,13 +105,13 @@ describe('market reducer', () => {
const orders = withOrders.get('open_orders');
expect(orders[0].price).to.equal(0.666);
expect(orders[0].sbd).to.equal('1.998 SBD');
expect(orders[1].type).to.equal('ask');
expect(orders[2].price).to.equal(0.651);
expect(orders[2].sbd).to.equal('1.953 SBD');
expect(orders[3].type).to.equal('bid');
expect(orders[3].type).to.equal('bid');
expect(orders[0].price).toBe(0.666);
expect(orders[0].sbd).toBe('1.998 SBD');
expect(orders[1].type).toBe('ask');
expect(orders[2].price).toBe(0.651);
expect(orders[2].sbd).toBe('1.953 SBD');
expect(orders[3].type).toBe('bid');
expect(orders[3].type).toBe('bid');
});
it('should sort open orders', () => {
......@@ -136,7 +131,7 @@ describe('market reducer', () => {
const orders = byPriceAsc.get('open_orders');
expect(orders[0].price).to.equal(0.507);
expect(orders[4].price).to.equal(0.666);
expect(orders[0].price).toBe(0.507);
expect(orders[4].price).toBe(0.666);
});
});
import chai, { expect } from 'chai';
import chaiImmutable from 'chai-immutable';
import { Map } from 'immutable';
import reducer from './OffchainReducer';
chai.use(chaiImmutable);
const mockAction = {
type: 'user/SAVE_LOGIN_CONFIRM',
};
......@@ -15,13 +11,13 @@ describe('offchain reducer', () => {
it('should provide a nice initial state, with any payload', () => {
const initial = reducer();
const expected = Map({ user: Map({}) });
expect(initial).to.eql(expected);
expect(initial).toEqual(expected);
const withPayload = reducer(initial, mockActionWithPayload);
expect(withPayload).to.eql(expected);
expect(withPayload).toEqual(expected);
});
it('should return an account of null when action has no payload', () => {
const initial = reducer();
const account = reducer(initial, mockAction);
expect(account).to.eql(Map({ user: Map({}), account: null }));
expect(account).toEqual(Map({ user: Map({}), account: null }));
});
});
/* global describe, it, before, beforeEach, after, afterEach */
import chai, { expect } from 'chai';
import { call, select } from 'redux-saga/effects';
import { api } from '@steemit/steem-js';
import {
......@@ -41,13 +40,13 @@ describe('TransactionSaga', () => {
describe('createPatch', () => {
it('should return undefined if empty arguments are passed', () => {
const actual = createPatch('', '');
expect(actual).to.eql(undefined);
expect(actual).toEqual(undefined);
});
it('should return the patch that reconciles two different strings', () => {
const testString =
'there is something interesting going on here that I do not fully understand it is seemingly complex but it is actually quite simple';
const actual = createPatch(testString, testString + 'ILU');
expect(actual).to.eql(
expect(actual).toEqual(
'@@ -120,12 +120,15 @@\n quite simple\n+ILU\n'
);
});
......@@ -61,7 +60,7 @@ describe('TransactionSaga', () => {
'@@redux-saga/IO': true,
TAKE: 'transaction/BROADCAST_OPERATION',
};
expect(actual).to.eql(expected);
expect(actual).toEqual(expected);
});
});
......@@ -73,7 +72,7 @@ describe('TransactionSaga', () => {
'@@redux-saga/IO': true,
TAKE: 'transaction/UPDATE_AUTHORITIES',
};
expect(actual).to.eql(expected);
expect(actual).toEqual(expected);
});
});
......@@ -85,7 +84,7 @@ describe('TransactionSaga', () => {
'@@redux-saga/IO': true,
TAKE: 'transaction/UPDATE_META',
};
expect(actual).to.eql(expected);
expect(actual).toEqual(expected);
});
});
......@@ -101,12 +100,12 @@ describe('TransactionSaga', () => {
const expected = select(state =>
state.user.getIn(['current', 'private_keys', 'memo_private'])
);
expect(actual).to.have.all.keys('@@redux-saga/IO', 'SELECT');
expect(Object.keys(actual)).toEqual(['@@redux-saga/IO', 'SELECT']);
});
it('should return the operation unchanged if it has no memo attribute', () => {
let gen = preBroadcast_transfer(arg);
const actual = gen.next().value;
expect(actual).to.eql(operationSansMemo);
expect(actual).toEqual(operationSansMemo);
});
});
......@@ -124,11 +123,11 @@ describe('TransactionSaga', () => {
operation.author,
operation.title
);
expect(actual).to.eql(mockCall);
expect(actual).toEqual(mockCall);
});
it('should return a string containing the transformed data from the api', () => {
const permlink = gen.next({ body: 'test' }).value;
expect(permlink).to.contain('test'); // TODO: cannot deep equal due to date stamp at runtime.
expect(permlink.indexOf('test')).toEqual(7); // TODO: cannot deep equal due to date stamp at runtime.
});
it('should generate own permlink, independent of api if title is empty', () => {
const gen2 = createPermlink(
......@@ -138,9 +137,13 @@ describe('TransactionSaga', () => {
operation.parent_permlink
);
const actual = gen2.next().value;
expect(actual).to.contain(
`re-${operation.parent_author}-${operation.parent_permlink}-`
); // TODO: cannot deep equal due to random hash at runtime.
expect(
actual.indexOf(
`re-${operation.parent_author}-${
operation.parent_permlink
}-`
)
).toEqual(0); // TODO: cannot deep equal due to random hash at runtime.
});
});
......@@ -155,8 +158,12 @@ describe('TransactionSaga', () => {
operation.parent_permlink
).value;
const actual = permlink.next().value;
const expected = call([api, api.getContentAsync], operation.author, operation.title);
expect(expected).to.eql(actual);
const expected = call(
[api, api.getContentAsync],
operation.author,
operation.title
);
expect(expected).toEqual(actual);
});
it('should return the comment options array.', () => {
let actual = gen.next('mock-permlink-123').value;
......@@ -175,39 +182,57 @@ describe('TransactionSaga', () => {
memo: operation.memo,
permlink: 'mock-permlink-123',
json_metadata: JSON.stringify(operation.json_metadata),
title: new Buffer((operation.title || '').trim(), 'utf-8'),
title: new Buffer(
(operation.title || '').trim(),
'utf-8'
),
body: new Buffer(operation.body, 'utf-8'), // TODO: new Buffer is deprecated, prefer Buffer.from()
},
],
];
expect(actual).to.eql(expected);
expect(actual).toEqual(expected);
});
it('should return a patch as body value if patch is smaller than body.', () => {
const originalBod = operation.body + 'minor difference';
operation.__config.originalBody = originalBod;
gen = preBroadcast_comment({ operation, username });
gen.next(operation.title, operation.author, operation.parent_author, operation.parent_permlink);
gen.next(
operation.title,
operation.author,
operation.parent_author,
operation.parent_permlink
);
const actual = gen.next('mock-permlink-123').value;
const expected = Buffer.from(
createPatch(originalBod, operation.body),
'utf-8'
);
expect(actual[0][1].body).to.eql(expected);
expect(actual[0][1].body).toEqual(expected);
});
it('should return body as body value if patch is larger than body.', () => {
const originalBod = 'major difference';
operation.__config.originalBody = originalBod;
gen = preBroadcast_comment({ operation, username });
gen.next(operation.title, operation.author, operation.parent_author, operation.parent_permlink);
gen.next(
operation.title,
operation.author,
operation.parent_author,
operation.parent_permlink
);
const actual = gen.next('mock-permlink-123').value;
const expected = Buffer.from(operation.body, 'utf-8');
expect(actual[0][1].body).to.eql(expected, 'utf-8');
expect(actual[0][1].body).toEqual(expected, 'utf-8');
});
it('should include comment_options and autoVote if specified.', () => {
operation.__config.comment_options = true;
operation.__config.autoVote = true;
gen = preBroadcast_comment({ operation, username });
gen.next(operation.title, operation.author, operation.parent_author, operation.parent_permlink);
gen.next(
operation.title,
operation.author,
operation.parent_author,
operation.parent_permlink
);
const actual = gen.next('mock-permlink-123').value;
const expectedCommentOptions = [
'comment_options',
......@@ -230,8 +255,8 @@ describe('TransactionSaga', () => {
weight: 10000,
},
];
expect(actual[1]).to.eql(expectedCommentOptions);
expect(actual[2]).to.eql(expectedAutoVoteOptions);
expect(actual[1]).toEqual(expectedCommentOptions);
expect(actual[2]).toEqual(expectedAutoVoteOptions);
});
});
});
......@@ -26,6 +26,7 @@
"max_virtual_bandwidth": "2203586534107862357",
"current_reserve_ratio": 1945
},
"status": {},
"tag_idx": {
"trending": [],