Skip to content

Commit

Permalink
[Dev Deps] update babel-cli, babel-preset-airbnb, eslint, `esli…
Browse files Browse the repository at this point in the history
…nt-config-airbnb-base`, `mocha`, `mocha-wrap`, `simon`

 - [Tests] return promises in lifecycle tests.
  • Loading branch information
greenkeeper[bot] authored and ljharb committed Jan 13, 2017
1 parent 96f247d commit 5dbddc4
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 84 deletions.
8 changes: 2 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
{
"root": true,
"extends": "airbnb",
"extends": "airbnb-base",
"env": {
"es6": true
},
"ecmaFeatures": {
"modules": true,
"jsx": true
"node": true
},
"rules": {
"no-console": 0,
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@
},
"homepage": "https://github.com/airbnb/hypernova",
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-cli": "^6.18.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-airbnb": "^2.0.0",
"babel-preset-airbnb": "^2.1.1",
"chai": "^3.5.0",
"cheerio": "^0.22.0",
"eslint": "^3.4.0",
"eslint-config-airbnb": "^10.0.1",
"eslint-plugin-import": "^1.14.0",
"eslint-plugin-jsx-a11y": "^2.2.1",
"eslint-plugin-react": "^6.2.0",
"eslint": "^3.13.1",
"eslint-config-airbnb-base": "^11.0.1",
"eslint-plugin-import": "^2.2.0",
"istanbul": "^1.0.0-alpha.2",
"mocha": "^3.0.2",
"mocha-wrap": "^2.0.5",
"mocha": "^3.2.0",
"mocha-wrap": "^2.1.0",
"rimraf": "^2.5.4",
"sinon": "^1.17.5",
"sinon": "^1.17.7",
"sinon-sandbox": "^1.0.2"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Module {
}

if (isNativeModule(filename)) {
// eslint-disable-next-line global-require
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(filename);
}

Expand Down
2 changes: 1 addition & 1 deletion src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function isNotMethod(name) {

function del(obj) {
/* eslint no-param-reassign: 0 */
return key => { delete obj[key]; };
return (key) => { delete obj[key]; };
}

function toFastProperties(obj) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function uuid() {
-1e11
).replace(
/[018]/g,
x => (x ^ Math.random() * 16 >> x / 4).toString(16) // eslint-disable-line no-mixed-operators
x => (x ^ Math.random() * 16 >> x / 4).toString(16), // eslint-disable-line no-mixed-operators, no-bitwise, max-len
);
}

Expand All @@ -42,7 +42,7 @@ function decode(res) {
}

function makeValidDataAttribute(attr, value) {
const encodedAttr = attr.toLowerCase().replace(/[^0-9a-z_\-]/g, '');
const encodedAttr = attr.toLowerCase().replace(/[^0-9a-z_-]/g, '');
const encodedValue = value.replace(/&/g, '&').replace(/"/g, '"');
return `data-${encodedAttr}="${encodedValue}"`;
}
Expand Down
24 changes: 11 additions & 13 deletions src/utils/BatchManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function notFound(name) {
error.stack = [stack[0]]
.concat(
` at YOUR-COMPONENT-DID-NOT-REGISTER_${name}:1:1`,
stack.slice(1)
stack.slice(1),
)
.join('\n');

Expand Down Expand Up @@ -109,24 +109,22 @@ class BatchManager {
* job token passed in).
*/
getRequestContext(plugin, token) {
return Object.assign(
{},
this.baseContext,
this.jobContexts[token],
this.pluginContexts.get(plugin)
);
return {
...this.baseContext,
...this.jobContexts[token],
...this.pluginContexts.get(plugin),
};
}

/**
* Returns a context object scoped to a specific plugin and batch.
*/
getBatchContext(plugin) {
return Object.assign(
{},
this.baseContext,
this.batchContext,
this.pluginContexts.get(plugin)
);
return {
...this.baseContext,
...this.batchContext,
...this.pluginContexts.get(plugin),
};
}

contextFor(plugin, token) {
Expand Down
12 changes: 5 additions & 7 deletions src/utils/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ export function raceTo(promise, ms, msg) {
export function runAppLifecycle(lifecycle, plugins, config, error, ...args) {
try {
const promise = Promise.all(
plugins
.filter(hasMethod(lifecycle))
.map(plugin => plugin[lifecycle](config, error, ...args))
plugins.filter(hasMethod(lifecycle)).map(plugin => plugin[lifecycle](config, error, ...args)),
);

return raceTo(
promise,
MAX_LIFECYCLE_EXECUTION_TIME_IN_MS,
`App lifecycle method ${lifecycle} took too long.`
`App lifecycle method ${lifecycle} took too long.`,
);
} catch (err) {
return Promise.reject(err);
Expand Down Expand Up @@ -90,13 +88,13 @@ export function runLifecycle(lifecycle, plugins, manager, token) {
const promise = Promise.all(
plugins
.filter(hasMethod(lifecycle))
.map(plugin => plugin[lifecycle](manager.contextFor(plugin, token)))
.map(plugin => plugin[lifecycle](manager.contextFor(plugin, token))),
);

return raceTo(
promise,
MAX_LIFECYCLE_EXECUTION_TIME_IN_MS,
`Lifecycle method ${lifecycle} took too long.`
`Lifecycle method ${lifecycle} took too long.`,
);
} catch (err) {
return Promise.reject(err);
Expand Down Expand Up @@ -192,7 +190,7 @@ export function processBatch(jobs, plugins, manager) {

// for each job, processJob
.then(() => Promise.all(
Object.keys(jobs).map(token => processJob(token, plugins, manager))
Object.keys(jobs).map(token => processJob(token, plugins, manager)),
))

// batchEnd
Expand Down
2 changes: 1 addition & 1 deletion src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const initServer = (app, config, callback) => {
}

function close() {
return new Promise(resolve => {
return new Promise((resolve) => {
if (!server) {
resolve();
return;
Expand Down
4 changes: 1 addition & 3 deletions test/createGetComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { createGetComponent } from '../server';

describe('createGetComponent', () => {
const files = {
HypernovaExample: path.resolve(
path.join('test', 'components', 'HypernovaExample.js')
),
HypernovaExample: path.resolve(path.join('test', 'components', 'HypernovaExample.js')),
};

const getComponent = createGetComponent(files);
Expand Down
2 changes: 1 addition & 1 deletion test/escape-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('escaping', () => {
assert.equal(
script1,
script3,
'third toScript after a fromScript call results in the same HTML'
'third toScript after a fromScript call results in the same HTML',
);

assert.isObject(res);
Expand Down
75 changes: 37 additions & 38 deletions test/lifecycle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('lifecycle', () => {
const plugin = mockPlugin();
const config = {};

lifecycle.runAppLifecycle('initialize', [plugin], config)
return lifecycle.runAppLifecycle('initialize', [plugin], config)
.then(() => {
assert.propertyVal(plugin.initialize, 'callCount', 1);
assert.deepEqual(plugin.initialize.args[0][0], config);
Expand All @@ -56,7 +56,7 @@ describe('lifecycle', () => {

plugin.initialize = sinon.stub().returns(promise);

lifecycle.runAppLifecycle('initialize', [plugin], config)
return lifecycle.runAppLifecycle('initialize', [plugin], config)
.then(() => {
assert.propertyVal(plugin.initialize, 'callCount', 1);
assert.deepEqual(plugin.initialize.args[0][0], config);
Expand All @@ -70,7 +70,7 @@ describe('lifecycle', () => {
plugins[0].initialize = sinon.stub().returns(Promise.resolve());
plugins[1].initialize = sinon.stub().returns(Promise.resolve());

lifecycle.runAppLifecycle('initialize', plugins, config)
return lifecycle.runAppLifecycle('initialize', plugins, config)
.then(() => {
assert.equal(plugins[0].initialize.callCount, 1);
assert.deepEqual(plugins[0].initialize.args[0][0], config);
Expand All @@ -87,7 +87,7 @@ describe('lifecycle', () => {
const plugin = mockPlugin();
const manager = batchManagerInstance(jobs, [plugin]);

lifecycle.runLifecycle('jobStart', [plugin], manager, 'foo')
return lifecycle.runLifecycle('jobStart', [plugin], manager, 'foo')
.then(() => {
assert.equal(plugin.jobStart.callCount, 1, 'calls the method passed in');
assert.deepEqual(plugin.jobStart.args[0][0], manager.contextFor(plugin, 'foo'));
Expand All @@ -107,7 +107,7 @@ describe('lifecycle', () => {
});
plugins[0].jobStart = sinon.stub().returns(promise);

lifecycle.runLifecycle('jobStart', plugins, manager, 'foo')
return lifecycle.runLifecycle('jobStart', plugins, manager, 'foo')
.then(() => {
const context = manager.contextFor(plugins[0], 'foo');
assert.equal(plugins[0].jobStart.callCount, 1);
Expand Down Expand Up @@ -188,30 +188,30 @@ describe('lifecycle', () => {
sinon.stub(manager, 'recordError');
});

it('calls lifecycle methods in correct order', () => {
it('calls lifecycle methods in correct order', () => (
lifecycle.processJob('foo', plugins, manager)
.then(() => {
sinon.assert.callOrder(
plugins[0].jobStart,
plugins[1].jobStart,
plugins[2].jobStart,
.then(() => {
sinon.assert.callOrder(
plugins[0].jobStart,
plugins[1].jobStart,
plugins[2].jobStart,

plugins[0].beforeRender,
plugins[1].beforeRender,
plugins[2].beforeRender,
plugins[0].beforeRender,
plugins[1].beforeRender,
plugins[2].beforeRender,

manager.render,
manager.render,

plugins[0].afterRender,
plugins[1].afterRender,
plugins[2].afterRender,
plugins[0].afterRender,
plugins[1].afterRender,
plugins[2].afterRender,

plugins[0].jobEnd,
plugins[1].jobEnd,
plugins[2].jobEnd
);
});
});
plugins[0].jobEnd,
plugins[1].jobEnd,
plugins[2].jobEnd,
);
})
));

it('calls plugin methods with proper arguments', () => {
const contexts = [
Expand All @@ -220,7 +220,7 @@ describe('lifecycle', () => {
manager.contextFor(plugins[2], 'foo'),
];

lifecycle.processJob('foo', plugins, manager)
return lifecycle.processJob('foo', plugins, manager)
.then(() => {
sinon.assert.calledWith(plugins[0].jobStart, contexts[0]);
sinon.assert.calledWith(plugins[1].jobStart, contexts[1]);
Expand All @@ -245,7 +245,7 @@ describe('lifecycle', () => {
it('on an error, fails fast', () => {
plugins[0].beforeRender = sinon.stub().throws();

lifecycle.processJob('foo', plugins, manager)
return lifecycle.processJob('foo', plugins, manager)
.then(() => {
sinon.assert.called(plugins[0].jobStart);
sinon.assert.called(plugins[1].jobStart);
Expand All @@ -260,16 +260,15 @@ describe('lifecycle', () => {
it('on an error, calls manager.recordError', () => {
plugins[0].beforeRender = sinon.stub().throws();

lifecycle.processJob('foo', plugins, manager)
.then(() => {
sinon.assert.called(manager.recordError);
});
return lifecycle.processJob('foo', plugins, manager).then(() => {
sinon.assert.called(manager.recordError);
});
});

it('on an error, calls onError for plugins', () => {
plugins[0].beforeRender = sinon.stub().throws();

lifecycle.processJob('foo', plugins, manager)
return lifecycle.processJob('foo', plugins, manager)
.then(() => {
sinon.assert.called(plugins[0].onError);
sinon.assert.called(plugins[1].onError);
Expand All @@ -290,7 +289,7 @@ describe('lifecycle', () => {
sinon.stub(manager, 'recordError');
});

it('calls lifecycle methods in correct order', () => {
it('calls lifecycle methods in correct order', () => (
lifecycle.processBatch(jobs, plugins, manager)
.then(() => {
sinon.assert.callOrder(
Expand All @@ -304,15 +303,15 @@ describe('lifecycle', () => {

plugins[0].batchEnd,
plugins[1].batchEnd,
plugins[2].batchEnd
plugins[2].batchEnd,
);
});
});
})
));

it('on an error, fails fast', () => {
plugins[0].batchStart = sinon.stub().throws();

lifecycle.processBatch(jobs, plugins, manager)
return lifecycle.processBatch(jobs, plugins, manager)
.then(() => {
sinon.assert.called(plugins[0].batchStart);
sinon.assert.notCalled(manager.render);
Expand All @@ -323,7 +322,7 @@ describe('lifecycle', () => {
it('on an error, calls manager.recordError', () => {
plugins[0].batchStart = sinon.stub().throws();

lifecycle.processBatch(jobs, plugins, manager)
return lifecycle.processBatch(jobs, plugins, manager)
.then(() => {
sinon.assert.called(manager.recordError);
});
Expand All @@ -332,7 +331,7 @@ describe('lifecycle', () => {
it('on an error, calls onError for plugins', () => {
plugins[0].batchStart = sinon.stub().throws();

lifecycle.processBatch(jobs, plugins, manager)
return lifecycle.processBatch(jobs, plugins, manager)
.then(() => {
sinon.assert.called(plugins[0].onError);
sinon.assert.called(plugins[1].onError);
Expand Down
2 changes: 1 addition & 1 deletion test/renderBatch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Response {
return this;
}

end() {}
end() {} // eslint-disable-line class-methods-use-this

getResponse() {
return {
Expand Down

0 comments on commit 5dbddc4

Please sign in to comment.