Skip to content

Commit

Permalink
fix tests, clarify api for plugin authors
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonpecora committed Oct 2, 2017
1 parent 65d308b commit 9cd30be
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/component-data/actions.test.js
Expand Up @@ -64,7 +64,7 @@ describe('component-data actions', () => {
it('reverts components with model.js if model.js errors', () => {
model.save.returns(Promise.reject(new Error('nope')));
return fn(store, { uri, data, prevData }).catch(() => {
expect(console.error).to.have.been.calledWith('Error saving component (foo): nope');
expect(loggerStub.error.called).to.equal(true);
});
});

Expand All @@ -83,7 +83,7 @@ describe('component-data actions', () => {
model.render.returns(Promise.resolve(data));
return fn(store, { uri, data, prevData }).catch(() => {
expect(queue.add).to.have.been.calledWith(api.save, [uri, data, false], 'save');
expect(console.error).to.have.been.calledWith('Error saving component (foo): nope');
expect(loggerStub.error.called).to.equal(true);
});
});

Expand Down
2 changes: 1 addition & 1 deletion lib/component-data/reactive-render.test.js
Expand Up @@ -22,7 +22,7 @@ describe('reactive render', () => {
const weirdNode = document.createComment('hi mom');

fn('foo', weirdNode);
expect(console.error).to.have.been.calledWith('Unknown node type (8) for "foo"');
expect(loggerStub.error.called).to.equal(true);
});

it('updates body components when passed element', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/decorators/select.test.js
Expand Up @@ -37,7 +37,7 @@ describe('select', () => {
components.getData.returns({ fooProp: { [refProp]: '/components/foo' } });
components.getSchema.returns({});
fn('/components/foo', '/components/bar');
expect(console.warn).to.have.been.calledWith('bar has no field for fooProp in its schema, but has foo in its data');
expect(loggerStub.warn.called).to.equal(true);
});

it('returns path for component in list', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/forms/behaviors.test.js
Expand Up @@ -69,7 +69,7 @@ describe('behaviors', () => {

it('warns if behavior slot not found in definition', () => {
fn('foo');
expect(console.warn).to.have.been.calledWith('Behavior "foo" has no slot specified. Make sure you add it!');
expect(loggerStub.warn.called).to.equal(true);
});

it('adds behavior slot from definition', () => {
Expand All @@ -78,7 +78,7 @@ describe('behaviors', () => {

it('omits missing behaviors', () => {
expect(fn('baz')).to.eql([]);
expect(console.warn).to.have.been.calledWith('Behavior "baz" not found. Make sure you add it!');
expect(loggerStub.warn.called).to.equal(true);
});

it('converts behavior names that match native tags', () => {
Expand All @@ -87,7 +87,7 @@ describe('behaviors', () => {

it('converts behaviors name BEFORE omitting', () => {
expect(fn('textarea')).to.eql([]);
expect(console.warn).to.have.been.calledWith('Behavior "input-textarea" not found. Make sure you add it!');
expect(loggerStub.warn.called).to.equal(true);
});
});
});
4 changes: 2 additions & 2 deletions lib/utils/api.js
Expand Up @@ -11,7 +11,7 @@ import * as urls from './urls';
import getAvailableComponents from './available-components';
import * as local from './local';
import * as validationHelpers from '../validators/helpers';
import * as log from './log';
import logger from './log';

// these utilities are exported so 3rd party plugins/validators/behaviors/panes can access them.
// note: the store is passed into those things automatically, so don't export it here
Expand All @@ -29,7 +29,7 @@ const api = {
getAvailableComponents,
local,
validationHelpers,
log,
logger, // plugin authors, please instantiate a logger from this (passing in the filename / plugin used)
version: process.env.KILN_VERSION
};

Expand Down
19 changes: 16 additions & 3 deletions test/setup.js
Expand Up @@ -2,6 +2,7 @@ import _ from 'lodash';
import Vue from 'vue';
import Vuex from 'vuex';
import { beforeEachHooks, afterEachHooks, mount } from 'vue-unit/src';
import * as logger from '../lib/utils/log'; // allow us to stub the default

const testsContext = require.context('../', true, /^\.\/(lib|behaviors)\/.*?\.test\.js$/);

Expand All @@ -16,11 +17,23 @@ window.renderWithArgs = (Component, props, state) => {
return mount(Component, { props, store: _.assign({}, defaultStore, { state }) });
};

// stub logger
window.loggerStub = {
info: sinon.spy(),
trace: sinon.spy(),
debug: sinon.spy(),
warn: sinon.spy(),
error: sinon.spy()
};

sinon.stub(logger, 'default', () => {
// return the same instances of our logging spies every time
// we create a new logger
return window.loggerStub;
});

window.beforeEachHooks = beforeEachHooks;
window.afterEachHooks = afterEachHooks;

// don't write to console
sinon.stub(console);

// run all tests
testsContext.keys().forEach(testsContext);

0 comments on commit 9cd30be

Please sign in to comment.