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';
const proxyquire = require('proxyquire');
const util = require('../../../shared/test/util');
const fakeSettingsFrom = sinon.stub();
const configFrom = proxyquire(
'../index',
util.noCallThru({
'./settings': fakeSettingsFrom,
})
);
const configFrom = require('../index');
describe('annotator.config.index', function() {
beforeEach('reset fakeSettingsFrom', function() {
fakeSettingsFrom.reset();
fakeSettingsFrom.returns({
let fakeSettingsFrom;
beforeEach(() => {
fakeSettingsFrom = sinon.stub().returns({
hostPageSetting: sinon.stub(),
});
configFrom.$imports.$mock({
'./settings': fakeSettingsFrom,
});
});
afterEach(() => {
configFrom.$imports.$restore();
});
it('gets the configuration settings', function() {
......
'use strict';
const proxyquire = require('proxyquire');
const util = require('../../../shared/test/util');
const settingsFrom = require('../settings');
const fakeConfigFuncSettingsFrom = sinon.stub();
const fakeIsBrowserExtension = sinon.stub();
const fakeSharedSettings = {};
describe('annotator.config.settingsFrom', function() {
let fakeConfigFuncSettingsFrom;
let fakeIsBrowserExtension;
let fakeSharedSettings;
beforeEach(() => {
fakeConfigFuncSettingsFrom = sinon.stub().returns({});
fakeIsBrowserExtension = sinon.stub().returns(false);
fakeSharedSettings = {
jsonConfigsFrom: sinon.stub().returns({}),
};
const settingsFrom = proxyquire(
'../settings',
util.noCallThru({
settingsFrom.$imports.$mock({
'./config-func-settings-from': fakeConfigFuncSettingsFrom,
'./is-browser-extension': fakeIsBrowserExtension,
'../../shared/settings': fakeSharedSettings,
})
);
describe('annotator.config.settingsFrom', function() {
beforeEach('reset fakeConfigFuncSettingsFrom', function() {
fakeConfigFuncSettingsFrom.reset();
fakeConfigFuncSettingsFrom.returns({});
});
beforeEach('reset fakeIsBrowserExtension', function() {
fakeIsBrowserExtension.reset();
fakeIsBrowserExtension.returns(false);
});
beforeEach('reset fakeSharedSettings', function() {
fakeSharedSettings.jsonConfigsFrom = sinon.stub().returns({});
afterEach(() => {
settingsFrom.$imports.$restore();
});
describe('#sidebarAppUrl', function() {
......
'use strict';
const proxyquire = require('proxyquire');
const boot = require('../boot');
function assetUrl(url) {
return `https://marginal.ly/client/build/${url}`;
}
describe('bootstrap', function() {
let boot;
let fakePolyfills;
let iframe;
......@@ -19,12 +18,13 @@ describe('bootstrap', function() {
requiredPolyfillSets: sinon.stub().returns([]),
};
boot = proxyquire('../boot', {
boot.$imports.$mock({
'../shared/polyfills': fakePolyfills,
});
});
afterEach(function() {
boot.$imports.$restore();
iframe.remove();
});
......
'use strict';
const angular = require('angular');
const proxyquire = require('proxyquire');
const immutable = require('seamless-immutable');
const annotationFixtures = require('../../test/annotation-fixtures');
......@@ -9,6 +8,8 @@ const events = require('../../events');
const uiConstants = require('../../ui-constants');
const util = require('../../../shared/test/util');
const rootThreadFactory = require('../root-thread');
const unroll = util.unroll;
const fixtures = immutable({
......@@ -84,12 +85,7 @@ describe('rootThread', function() {
.value('drafts', fakeDrafts)
.value('searchFilter', fakeSearchFilter)
.value('viewFilter', fakeViewFilter)
.service(
'rootThread',
proxyquire('../root-thread', {
'../build-thread': util.noCallThru(fakeBuildThread),
})
);
.service('rootThread', rootThreadFactory);
angular.mock.module('app');
......@@ -99,6 +95,16 @@ describe('rootThread', function() {
});
});
beforeEach(() => {
rootThreadFactory.$imports.$mock({
'../build-thread': fakeBuildThread,
});
});
afterEach(() => {
rootThreadFactory.$imports.$restore();
});
describe('#thread', function() {
it('returns the result of buildThread()', function() {
assert.equal(rootThread.thread(fakeStore.state), fixtures.emptyThread);
......
'use strict';
const EventEmitter = require('tiny-emitter');
const proxyquire = require('proxyquire');
const events = require('../../events');
const unroll = require('../../../shared/test/util').unroll;
const Streamer = require('../streamer');
const fixtures = {
createNotification: {
type: 'annotation-notification',
......@@ -82,7 +83,6 @@ describe('Streamer', function() {
let fakeSession;
let fakeSettings;
let activeStreamer;
let Streamer;
function createDefaultStreamer() {
activeStreamer = new Streamer(
......@@ -143,12 +143,13 @@ describe('Streamer', function() {
websocketUrl: 'ws://example.com/ws',
};
Streamer = proxyquire('../streamer', {
Streamer.$imports.$mock({
'../websocket': FakeSocket,
});
});
afterEach(function() {
Streamer.$imports.$restore();
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