Skip to content

Commit

Permalink
chore(henri): removing unreachable coverage (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
reel committed Nov 10, 2017
1 parent 6b0fa30 commit 0be2fa3
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/config/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const checkPackages = packages => {
i === missing.length - 1 ? `\b\b and '${val}'` : `'${val}',`
)
: missing;

/* istanbul ignore next */
log.fatalError(`Unable to load ${msg.join(' ')} from the current project.
Try installing ${multi ? 'them' : 'it'}:
Expand Down
2 changes: 2 additions & 0 deletions packages/config/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Remove config warning when no file is available
process.env.SUPPRESS_NO_CONFIG_WARNING = true;

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production') {
process.on('unhandledRejection', r => console.log(r));
}
Expand All @@ -9,6 +10,7 @@ const path = require('path');
const config = require('config');
const Log = require('@usehenri/log');

/* istanbul ignore next */
if (!global['henri']) {
global['henri'] = {
_modules: {},
Expand Down
6 changes: 6 additions & 0 deletions packages/config/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ henri.addModule = (name, func, force) => {
}
henri[name] = func;

/* istanbul ignore next */
henri._modules[name] = {
filename: info.getFileName(),
line: info.getLineNumber(),
Expand Down Expand Up @@ -60,10 +61,12 @@ henri.getStatus = key => {
henri.reload = async () => {
const start = process.hrtime();
const loaders = henri._loaders;
/* istanbul ignore next */
Object.keys(require.cache).forEach(function(id) {
delete require.cache[id];
});
try {
/* istanbul ignore next */
if (loaders.length > 0) {
for (let loader of loaders) {
await loader();
Expand All @@ -73,6 +76,7 @@ henri.reload = async () => {
log.space();
log.notify('Hot-reload', 'Server-side hot reload completed..');
} catch (e) {
/* istanbul ignore next */
log.error(e);
}
};
Expand All @@ -81,13 +85,15 @@ henri.stop = async () => {
const start = process.hrtime();
const reapers = henri._unloaders;
try {
/* istanbul ignore next */
if (reapers.length > 0) {
for (let reaper of reapers) {
await reaper();
}
}
log.warn(`server tear down completed in ${getDiff(start)}ms`);
} catch (e) {
/* istanbul ignore next */
log.error(e);
}
};
Expand Down
9 changes: 9 additions & 0 deletions packages/config/tests/register.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ describe('register', () => {
await henri.stop();
expect(unloader).toHaveBeenCalledTimes(3);
});
test('passport message', () => {
henri.log.error = jest.fn();
henri.passport.authenticate();
expect(henri.log.error).toHaveBeenCalledTimes(1);
});
test('setStatus', () => {
henri.setStatus('boo');
expect(henri.getStatus('boo')).toBeFalsy();
});
});
4 changes: 4 additions & 0 deletions packages/log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ class Log {
const color = getColor(options.level);
const dateString = chalk.grey(new Date().toLocaleTimeString());
const title = chalk[color].inverse(` ${options.level.toUpperCase()} `);
/* istanbul ignore next */
const message = chalk[color](options.message ? options.message : '');
/* istanbul ignore next */
const meta = chalk[color](
options.meta && Object.keys(options.meta).length
? '\n\t' + JSON.stringify(options.meta, null, 2)
: ''
);
/* istanbul ignore next */
const fullMsg = `${title} ${message || meta}`;

let space =
Expand Down Expand Up @@ -115,6 +118,7 @@ class Log {
console.log('');
const lines = msg.split('\n');
for (let line of lines) {
/* istanbul ignore next */
if (line.length > 2) {
this.error(line);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/log/tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ describe('log', () => {
// eslint-disable-next-line no-console
expect(console.log).toHaveBeenCalledTimes(2);
expect(henri.log.error).toHaveBeenCalledTimes(1);
expect(() => henri.log.fatalError('o')).toThrow();
expect(henri.log.error).toHaveBeenCalledTimes(1);
});
test('getColor', () => {
const { log: { getColor } } = henri;
Expand Down
9 changes: 6 additions & 3 deletions packages/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function init(reload = false) {
middlewares();

let routes = null;
/* istanbul ignore next */
try {
routes = require(config.has('location.routes')
? path.resolve(config.get('location.routes'))
Expand All @@ -17,6 +18,7 @@ async function init(reload = false) {
log.warn('unable to load routes from filesystem');
routes = {};
}
/* istanbul ignore next */
if (config.has('routes') && Object.keys(config.get('routes')).length > 1) {
routes = Object.assign({}, routes, config.get('routes'));
}
Expand All @@ -36,11 +38,11 @@ async function init(reload = false) {
log.error(`${key} => ${controller}: unknown controller for route `);
}
}

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production') {
henri.router.get('/_routes', (req, res) => res.json(henri._routes));
}

/* istanbul ignore next */
if (view && !reload) {
try {
view.prepare().then(() => {
Expand All @@ -65,7 +67,7 @@ function register(verb, route, controller, fn) {
typeof fn !== 'function' ? ' (unknown controller)' : ' (ok)'
}`;
}

/* istanbul ignore next */
function middlewares(router) {
if (henri._middlewares.length > 0) {
henri._middlewares.map(func => func());
Expand All @@ -81,6 +83,7 @@ function middlewares(router) {
if (req.url.startsWith('/_data/')) {
return res.json(data);
}
/* istanbul ignore next */
return res.format({
html: () => view.render(req, res, route, opts),
json: () => res.json(data),
Expand Down
2 changes: 1 addition & 1 deletion packages/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function start(delay, cb = null) {
})
.on('error', handleError);
}

/* istanbul ignore next */
async function watch() {
const ignored = [
'node_modules/',
Expand Down
5 changes: 3 additions & 2 deletions packages/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ if (henri._user) {

app.use(passport.initialize());
app.use(passport.session());

/* istanbul ignore next */
henri.addMiddleware(() => {
henri.router.post('/login', passport.authenticate('local'), (req, res) =>
res.send('authenticated')
);
});

/* istanbul ignore next */
henri.addMiddleware(() => {
henri.router.get('/logout', function(req, res) {
log.info('Logging out user', req.user);
Expand All @@ -143,6 +143,7 @@ if (henri._user) {

log.info('user module loaded.');
} else {
/* istanbul ignore next */
log.warn('no user model defined; will not load user module');
}

Expand Down

0 comments on commit 0be2fa3

Please sign in to comment.