Commit acd16de3 authored by Robert Knight's avatar Robert Knight

Convert remaining uses of proxyquire in tests for non-CoffeeScript modules

Convert remaining uses of proxyquire to babel-plugin-mockable-imports,
except for modules written in CoffeeScript, as the Babel plugin needs an
update to support the way groups of `<var> = require(<module>)`
statements get compiled.
parent c4c5b043
'use strict'; 'use strict';
const proxyquire = require('proxyquire'); const configFrom = require('../index');
const util = require('../../../shared/test/util');
const fakeSettingsFrom = sinon.stub();
const configFrom = proxyquire(
'../index',
util.noCallThru({
'./settings': fakeSettingsFrom,
})
);
describe('annotator.config.index', function() { describe('annotator.config.index', function() {
beforeEach('reset fakeSettingsFrom', function() { let fakeSettingsFrom;
fakeSettingsFrom.reset();
fakeSettingsFrom.returns({ beforeEach(() => {
fakeSettingsFrom = sinon.stub().returns({
hostPageSetting: sinon.stub(), hostPageSetting: sinon.stub(),
}); });
configFrom.$imports.$mock({
'./settings': fakeSettingsFrom,
});
});
afterEach(() => {
configFrom.$imports.$restore();
}); });
it('gets the configuration settings', function() { it('gets the configuration settings', function() {
......
'use strict'; 'use strict';
const proxyquire = require('proxyquire'); const settingsFrom = require('../settings');
const util = require('../../../shared/test/util');
const fakeConfigFuncSettingsFrom = sinon.stub();
const fakeIsBrowserExtension = sinon.stub();
const fakeSharedSettings = {};
const settingsFrom = proxyquire(
'../settings',
util.noCallThru({
'./config-func-settings-from': fakeConfigFuncSettingsFrom,
'./is-browser-extension': fakeIsBrowserExtension,
'../../shared/settings': fakeSharedSettings,
})
);
describe('annotator.config.settingsFrom', function() { describe('annotator.config.settingsFrom', function() {
beforeEach('reset fakeConfigFuncSettingsFrom', function() { let fakeConfigFuncSettingsFrom;
fakeConfigFuncSettingsFrom.reset(); let fakeIsBrowserExtension;
fakeConfigFuncSettingsFrom.returns({}); let fakeSharedSettings;
});
beforeEach(() => {
fakeConfigFuncSettingsFrom = sinon.stub().returns({});
fakeIsBrowserExtension = sinon.stub().returns(false);
fakeSharedSettings = {
jsonConfigsFrom: sinon.stub().returns({}),
};
beforeEach('reset fakeIsBrowserExtension', function() { settingsFrom.$imports.$mock({
fakeIsBrowserExtension.reset(); './config-func-settings-from': fakeConfigFuncSettingsFrom,
fakeIsBrowserExtension.returns(false); './is-browser-extension': fakeIsBrowserExtension,
'../../shared/settings': fakeSharedSettings,
});
}); });
beforeEach('reset fakeSharedSettings', function() { afterEach(() => {
fakeSharedSettings.jsonConfigsFrom = sinon.stub().returns({}); settingsFrom.$imports.$restore();
}); });
describe('#sidebarAppUrl', function() { describe('#sidebarAppUrl', function() {
......
'use strict'; 'use strict';
const proxyquire = require('proxyquire'); const boot = require('../boot');
function assetUrl(url) { function assetUrl(url) {
return `https://marginal.ly/client/build/${url}`; return `https://marginal.ly/client/build/${url}`;
} }
describe('bootstrap', function() { describe('bootstrap', function() {
let boot;
let fakePolyfills; let fakePolyfills;
let iframe; let iframe;
...@@ -19,12 +18,13 @@ describe('bootstrap', function() { ...@@ -19,12 +18,13 @@ describe('bootstrap', function() {
requiredPolyfillSets: sinon.stub().returns([]), requiredPolyfillSets: sinon.stub().returns([]),
}; };
boot = proxyquire('../boot', { boot.$imports.$mock({
'../shared/polyfills': fakePolyfills, '../shared/polyfills': fakePolyfills,
}); });
}); });
afterEach(function() { afterEach(function() {
boot.$imports.$restore();
iframe.remove(); iframe.remove();
}); });
......
'use strict'; 'use strict';
const angular = require('angular'); const angular = require('angular');
const proxyquire = require('proxyquire');
const immutable = require('seamless-immutable'); const immutable = require('seamless-immutable');
const annotationFixtures = require('../../test/annotation-fixtures'); const annotationFixtures = require('../../test/annotation-fixtures');
...@@ -9,6 +8,8 @@ const events = require('../../events'); ...@@ -9,6 +8,8 @@ const events = require('../../events');
const uiConstants = require('../../ui-constants'); const uiConstants = require('../../ui-constants');
const util = require('../../../shared/test/util'); const util = require('../../../shared/test/util');
const rootThreadFactory = require('../root-thread');
const unroll = util.unroll; const unroll = util.unroll;
const fixtures = immutable({ const fixtures = immutable({
...@@ -84,12 +85,7 @@ describe('rootThread', function() { ...@@ -84,12 +85,7 @@ describe('rootThread', function() {
.value('drafts', fakeDrafts) .value('drafts', fakeDrafts)
.value('searchFilter', fakeSearchFilter) .value('searchFilter', fakeSearchFilter)
.value('viewFilter', fakeViewFilter) .value('viewFilter', fakeViewFilter)
.service( .service('rootThread', rootThreadFactory);
'rootThread',
proxyquire('../root-thread', {
'../build-thread': util.noCallThru(fakeBuildThread),
})
);
angular.mock.module('app'); angular.mock.module('app');
...@@ -99,6 +95,16 @@ describe('rootThread', function() { ...@@ -99,6 +95,16 @@ describe('rootThread', function() {
}); });
}); });
beforeEach(() => {
rootThreadFactory.$imports.$mock({
'../build-thread': fakeBuildThread,
});
});
afterEach(() => {
rootThreadFactory.$imports.$restore();
});
describe('#thread', function() { describe('#thread', function() {
it('returns the result of buildThread()', function() { it('returns the result of buildThread()', function() {
assert.equal(rootThread.thread(fakeStore.state), fixtures.emptyThread); assert.equal(rootThread.thread(fakeStore.state), fixtures.emptyThread);
......
'use strict'; 'use strict';
const EventEmitter = require('tiny-emitter'); const EventEmitter = require('tiny-emitter');
const proxyquire = require('proxyquire');
const events = require('../../events'); const events = require('../../events');
const unroll = require('../../../shared/test/util').unroll; const unroll = require('../../../shared/test/util').unroll;
const Streamer = require('../streamer');
const fixtures = { const fixtures = {
createNotification: { createNotification: {
type: 'annotation-notification', type: 'annotation-notification',
...@@ -82,7 +83,6 @@ describe('Streamer', function() { ...@@ -82,7 +83,6 @@ describe('Streamer', function() {
let fakeSession; let fakeSession;
let fakeSettings; let fakeSettings;
let activeStreamer; let activeStreamer;
let Streamer;
function createDefaultStreamer() { function createDefaultStreamer() {
activeStreamer = new Streamer( activeStreamer = new Streamer(
...@@ -143,12 +143,13 @@ describe('Streamer', function() { ...@@ -143,12 +143,13 @@ describe('Streamer', function() {
websocketUrl: 'ws://example.com/ws', websocketUrl: 'ws://example.com/ws',
}; };
Streamer = proxyquire('../streamer', { Streamer.$imports.$mock({
'../websocket': FakeSocket, '../websocket': FakeSocket,
}); });
}); });
afterEach(function() { afterEach(function() {
Streamer.$imports.$restore();
activeStreamer = null; activeStreamer = null;
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment