Skip to content

Commit

Permalink
Convert mocking from proxyquire to mockable-imports
Browse files Browse the repository at this point in the history
Convert proxyquire mocking of several CoffeeScript modules.
  • Loading branch information
robertknight committed Apr 23, 2019
1 parent 644754a commit 1b2eb05
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
8 changes: 3 additions & 5 deletions src/annotator/plugin/test/cross-frame-test.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
proxyquire = require('proxyquire')

Plugin = require('../../plugin')
CrossFrame = null
CrossFrame = require('../cross-frame')

describe 'CrossFrame', ->
fakeDiscovery = null
Expand Down Expand Up @@ -41,16 +39,16 @@ describe 'CrossFrame', ->
proxyDiscovery = sandbox.stub().returns(fakeDiscovery)
proxyBridge = sandbox.stub().returns(fakeBridge)

CrossFrame = proxyquire('../cross-frame', {
CrossFrame.$imports.$mock({
'../plugin': Plugin,
'../annotation-sync': proxyAnnotationSync,
'../../shared/bridge': proxyBridge,
'../../shared/discovery': proxyDiscovery
})


afterEach ->
sandbox.restore()
CrossFrame.$imports.$restore()

describe 'CrossFrame constructor', ->
it 'instantiates the Discovery component', ->
Expand Down
3 changes: 1 addition & 2 deletions src/annotator/test/host-test.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
proxyquire = require('proxyquire')
Host = proxyquire('../host', {})
Host = require('../host')

describe 'Host', ->
sandbox = sinon.sandbox.create()
Expand Down
6 changes: 4 additions & 2 deletions src/annotator/test/integration/multi-frame-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const proxyquire = require('proxyquire');
const isLoaded = require('../../util/frame-util').isLoaded;

const FRAME_DEBOUNCE_WAIT = require('../../frame-observer').DEBOUNCE_WAIT + 10;
const CrossFrame = require('../../plugin/cross-frame');

describe('CrossFrame multi-frame scenario', function() {
let fakeAnnotationSync;
Expand All @@ -30,7 +30,7 @@ describe('CrossFrame multi-frame scenario', function() {
proxyAnnotationSync = sandbox.stub().returns(fakeAnnotationSync);
proxyBridge = sandbox.stub().returns(fakeBridge);

const CrossFrame = proxyquire('../../plugin/cross-frame', {
CrossFrame.$imports.$mock({
'../annotation-sync': proxyAnnotationSync,
'../../shared/bridge': proxyBridge,
});
Expand All @@ -53,6 +53,8 @@ describe('CrossFrame multi-frame scenario', function() {
sandbox.restore();
crossFrame.destroy();
container.parentNode.removeChild(container);

CrossFrame.$imports.$restore();
});

it('detects frames on page', function() {
Expand Down
15 changes: 9 additions & 6 deletions src/annotator/test/sidebar-test.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
events = require('../../shared/bridge-events')

proxyquire = require('proxyquire')

rafStub = (fn) ->
fn()

Sidebar = proxyquire('../sidebar', { raf: rafStub })
Sidebar = require('../sidebar')

DEFAULT_WIDTH = 350
DEFAULT_HEIGHT = 600
Expand All @@ -17,6 +12,14 @@ describe 'Sidebar', ->
fakeCrossFrame = null
sidebarConfig = {pluginClasses: {}}

before ->
rafStub = (fn) ->
fn()
Sidebar.$imports.$mock({ raf: rafStub })

after ->
Sidebar.$imports.$restore()

createSidebar = (config={}) ->
config = Object.assign({}, sidebarConfig, config)
element = document.createElement('div')
Expand Down

0 comments on commit 1b2eb05

Please sign in to comment.