Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
67ecd180
Unverified
Commit
67ecd180
authored
May 01, 2019
by
Robert Knight
Committed by
GitHub
May 01, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1085 from hypothesis/mockable-imports-part-2
Convert mocking to mockable-imports (2/4)
parents
3cdeb195
12e0ddc5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
80 additions
and
106 deletions
+80
-106
index-test.js
src/annotator/config/test/index-test.js
+13
-14
settings-test.js
src/annotator/config/test/settings-test.js
+18
-24
boot-test.js
src/boot/test/boot-test.js
+3
-3
util.js
src/shared/test/util.js
+0
-23
annotation-header-test.js
src/sidebar/components/test/annotation-header-test.js
+6
-4
annotation-test.js
src/sidebar/components/test/annotation-test.js
+10
-13
sidebar-content-test.js
src/sidebar/components/test/sidebar-content-test.js
+13
-15
root-thread-test.js
src/sidebar/services/test/root-thread-test.js
+13
-7
streamer-test.js
src/sidebar/services/test/streamer-test.js
+4
-3
No files found.
src/annotator/config/test/index-test.js
View file @
67ecd180
'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
()
{
...
...
src/annotator/config/test/settings-test.js
View file @
67ecd180
'use strict'
;
const
proxyquire
=
require
(
'proxyquire'
);
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
,
})
);
const
settingsFrom
=
require
(
'../settings'
);
describe
(
'annotator.config.settingsFrom'
,
function
()
{
beforeEach
(
'reset fakeConfigFuncSettingsFrom'
,
function
()
{
fakeConfigFuncSettingsFrom
.
reset
();
fakeConfigFuncSettingsFrom
.
returns
({});
});
let
fakeConfigFuncSettingsFrom
;
let
fakeIsBrowserExtension
;
let
fakeSharedSettings
;
beforeEach
(()
=>
{
fakeConfigFuncSettingsFrom
=
sinon
.
stub
().
returns
({});
fakeIsBrowserExtension
=
sinon
.
stub
().
returns
(
false
);
fakeSharedSettings
=
{
jsonConfigsFrom
:
sinon
.
stub
().
returns
({}),
};
beforeEach
(
'reset fakeIsBrowserExtension'
,
function
()
{
fakeIsBrowserExtension
.
reset
();
fakeIsBrowserExtension
.
returns
(
false
);
settingsFrom
.
$imports
.
$mock
({
'./config-func-settings-from'
:
fakeConfigFuncSettingsFrom
,
'./is-browser-extension'
:
fakeIsBrowserExtension
,
'../../shared/settings'
:
fakeSharedSettings
,
});
});
beforeEach
(
'reset fakeSharedSettings'
,
function
()
{
fakeSharedSettings
.
jsonConfigsFrom
=
sinon
.
stub
().
returns
({}
);
afterEach
(()
=>
{
settingsFrom
.
$imports
.
$restore
(
);
});
describe
(
'#sidebarAppUrl'
,
function
()
{
...
...
src/boot/test/boot-test.js
View file @
67ecd180
'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
();
});
...
...
src/shared/test/util.js
View file @
67ecd180
'use strict'
;
/**
* Utility function for use with 'proxyquire' that prevents calls to
* stubs 'calling through' to the _original_ dependency if a particular
* function or property is not set on a stub, which is proxyquire's default
* but usually undesired behavior.
*
* See https://github.com/thlorenz/proxyquireify#nocallthru
*
* Usage:
* var moduleUnderTest = proxyquire('./module-under-test', noCallThru({
* './dependency-foo': fakeFoo,
* }));
*
* @param {Object} stubs - A map of dependency paths to stubs, or a single
* stub.
*/
function
noCallThru
(
stubs
)
{
// This function is trivial but serves as documentation for why
// '@noCallThru' is used.
return
Object
.
assign
(
stubs
,
{
'@noCallThru'
:
true
});
}
/**
* Helper for writing parameterized tests.
*
...
...
@@ -79,6 +57,5 @@ function unroll(description, testFn, fixtures) {
}
module
.
exports
=
{
noCallThru
:
noCallThru
,
unroll
:
unroll
,
};
src/sidebar/components/test/annotation-header-test.js
View file @
67ecd180
'use strict'
;
const
angular
=
require
(
'angular'
);
const
proxyquire
=
require
(
'proxyquire'
);
const
fixtures
=
require
(
'../../test/annotation-fixtures'
);
const
annotationHeader
=
require
(
'../annotation-header'
);
const
fakeDocumentMeta
=
{
domain
:
'docs.io'
,
...
...
@@ -27,7 +27,7 @@ describe('sidebar.components.annotation-header', function() {
});
beforeEach
(
'Import and register the annotationHeader component'
,
function
()
{
const
annotationHeader
=
proxyquire
(
'../annotation-header'
,
{
annotationHeader
.
$imports
.
$mock
(
{
'../annotation-metadata'
:
{
// eslint-disable-next-line no-unused-vars
domainAndTitle
:
function
(
ann
)
{
...
...
@@ -35,12 +35,14 @@ describe('sidebar.components.annotation-header', function() {
},
},
'../util/account-id'
:
fakeAccountID
,
'@noCallThru'
:
true
,
});
angular
.
module
(
'app'
,
[]).
component
(
'annotationHeader'
,
annotationHeader
);
});
afterEach
(()
=>
{
annotationHeader
.
$imports
.
$restore
();
});
beforeEach
(
'Initialize and register fake AngularJS dependencies'
,
function
()
{
fakeFeatures
=
{
flagEnabled
:
sinon
.
stub
().
returns
(
false
),
...
...
src/sidebar/components/test/annotation-test.js
View file @
67ecd180
'use strict'
;
const
angular
=
require
(
'angular'
);
const
proxyquire
=
require
(
'proxyquire'
);
const
events
=
require
(
'../../events'
);
const
fixtures
=
require
(
'../../test/annotation-fixtures'
);
const
testUtil
=
require
(
'../../../shared/test/util'
);
const
util
=
require
(
'../../directive/test/util'
);
const
annotationComponent
=
require
(
'../annotation'
);
const
inject
=
angular
.
mock
.
inject
;
const
unroll
=
testUtil
.
unroll
;
...
...
@@ -100,9 +101,6 @@ describe('annotation', function() {
let
$scope
;
let
$timeout
;
let
$window
;
// Unfortunately fakeAccountID needs to be initialised here because it
// gets passed into proxyquire() _before_ the beforeEach() that initializes
// the rest of the fakes runs.
const
fakeAccountID
=
{
isThirdPartyUser
:
sinon
.
stub
(),
};
...
...
@@ -120,16 +118,15 @@ describe('annotation', function() {
let
fakeStreamer
;
let
sandbox
;
/**
* Returns the annotation directive with helpers stubbed out.
*/
function
annotationComponent
()
{
return
proxyquire
(
'../annotation'
,
{
angular
:
testUtil
.
noCallThru
(
angular
),
beforeEach
(()
=>
{
annotationComponent
.
$imports
.
$mock
({
'../util/account-id'
:
fakeAccountID
,
'@noCallThru'
:
true
,
});
}
});
afterEach
(()
=>
{
annotationComponent
.
$imports
.
$restore
();
});
function
createDirective
(
annotation
)
{
annotation
=
annotation
||
fixtures
.
defaultAnnotation
();
...
...
@@ -153,7 +150,7 @@ describe('annotation', function() {
before
(
function
()
{
angular
.
module
(
'h'
,
[])
.
component
(
'annotation'
,
annotationComponent
()
)
.
component
(
'annotation'
,
annotationComponent
)
.
component
(
'annotationActionButton'
,
{
bindings
:
{
icon
:
'<'
,
...
...
src/sidebar/components/test/sidebar-content-test.js
View file @
67ecd180
'use strict'
;
const
angular
=
require
(
'angular'
);
const
proxyquire
=
require
(
'proxyquire'
);
const
EventEmitter
=
require
(
'tiny-emitter'
);
const
events
=
require
(
'../../events'
);
const
noCallThru
=
require
(
'../../../shared/test/util'
).
noCallThru
;
const
sidebarContent
=
require
(
'../sidebar-content'
)
;
const
uiConstants
=
require
(
'../../ui-constants'
);
let
searchClients
;
...
...
@@ -64,21 +63,12 @@ describe('sidebar.components.sidebar-content', function() {
angular
.
module
(
'h'
,
[])
.
service
(
'store'
,
require
(
'../../store'
))
.
component
(
'sidebarContent'
,
proxyquire
(
'../sidebar-content'
,
noCallThru
({
angular
:
angular
,
'../search-client'
:
FakeSearchClient
,
})
)
);
.
component
(
'sidebarContent'
,
sidebarContent
);
});
beforeEach
(
angular
.
mock
.
module
(
'h'
));
beforeEach
(
beforeEach
(
()
=>
{
angular
.
mock
.
module
(
function
(
$provide
)
{
searchClients
=
[];
sandbox
=
sinon
.
sandbox
.
create
();
...
...
@@ -142,8 +132,16 @@ describe('sidebar.components.sidebar-content', function() {
$provide
.
value
(
'streamFilter'
,
fakeStreamFilter
);
$provide
.
value
(
'groups'
,
fakeGroups
);
$provide
.
value
(
'settings'
,
fakeSettings
);
})
);
});
sidebarContent
.
$imports
.
$mock
({
'../search-client'
:
FakeSearchClient
,
});
});
afterEach
(()
=>
{
sidebarContent
.
$imports
.
$restore
();
});
function
setFrames
(
frames
)
{
frames
.
forEach
(
function
(
frame
)
{
...
...
src/sidebar/services/test/root-thread-test.js
View file @
67ecd180
'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
);
...
...
src/sidebar/services/test/streamer-test.js
View file @
67ecd180
'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
;
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment