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
d8efffcf
Unverified
Commit
d8efffcf
authored
Jul 03, 2019
by
Robert Knight
Committed by
GitHub
Jul 03, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1220 from hypothesis/call-end-once
Only emit end if searchClient is done searching
parents
5a8e6bec
0f8cdf18
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
21 deletions
+27
-21
search-client.js
src/sidebar/search-client.js
+0
-5
search-client-test.js
src/sidebar/test/search-client-test.js
+27
-16
No files found.
src/sidebar/search-client.js
View file @
d8efffcf
...
...
@@ -74,11 +74,6 @@ class SearchClient extends EventEmitter {
return
;
}
self
.
emit
(
'error'
,
err
);
})
.
then
(
function
()
{
if
(
self
.
_canceled
)
{
return
;
}
self
.
emit
(
'end'
);
});
}
...
...
src/sidebar/test/search-client-test.js
View file @
d8efffcf
...
...
@@ -8,7 +8,7 @@ function awaitEvent(emitter, event) {
});
}
describe
(
'SearchClient'
,
function
()
{
describe
(
'SearchClient'
,
()
=>
{
const
RESULTS
=
[
{
id
:
'one'
},
{
id
:
'two'
},
...
...
@@ -18,7 +18,7 @@ describe('SearchClient', function() {
let
fakeSearchFn
;
beforeEach
(
function
()
{
beforeEach
(
()
=>
{
fakeSearchFn
=
sinon
.
spy
(
function
(
params
)
{
return
Promise
.
resolve
({
rows
:
RESULTS
.
slice
(
params
.
offset
,
params
.
offset
+
params
.
limit
),
...
...
@@ -27,34 +27,45 @@ describe('SearchClient', function() {
});
});
it
(
'emits "results"'
,
function
()
{
it
(
'emits "results"'
,
()
=>
{
const
client
=
new
SearchClient
(
fakeSearchFn
);
const
onResults
=
sinon
.
stub
();
client
.
on
(
'results'
,
onResults
);
client
.
get
({
uri
:
'http://example.com'
});
return
awaitEvent
(
client
,
'end'
).
then
(
function
()
{
return
awaitEvent
(
client
,
'end'
).
then
(
()
=>
{
assert
.
calledWith
(
onResults
,
RESULTS
);
});
});
it
(
'emits "results" with chunks in incremental mode'
,
function
()
{
it
(
'emits "end" only once'
,
()
=>
{
const
client
=
new
SearchClient
(
fakeSearchFn
,
{
chunkSize
:
2
});
client
.
on
(
'results'
,
sinon
.
stub
());
let
emitEndCounter
=
0
;
client
.
on
(
'end'
,
()
=>
{
emitEndCounter
+=
1
;
assert
.
equal
(
emitEndCounter
,
1
);
});
client
.
get
({
uri
:
'http://example.com'
});
});
it
(
'emits "results" with chunks in incremental mode'
,
()
=>
{
const
client
=
new
SearchClient
(
fakeSearchFn
,
{
chunkSize
:
2
});
const
onResults
=
sinon
.
stub
();
client
.
on
(
'results'
,
onResults
);
client
.
get
({
uri
:
'http://example.com'
});
return
awaitEvent
(
client
,
'end'
).
then
(
function
()
{
return
awaitEvent
(
client
,
'end'
).
then
(
()
=>
{
assert
.
calledWith
(
onResults
,
RESULTS
.
slice
(
0
,
2
));
assert
.
calledWith
(
onResults
,
RESULTS
.
slice
(
2
,
4
));
});
});
it
(
'stops fetching chunks if the results array is empty'
,
function
()
{
it
(
'stops fetching chunks if the results array is empty'
,
()
=>
{
// Simulate a situation where the `total` count for the server is incorrect
// and we appear to have reached the end of the result list even though
// `total` implies that there should be more results available.
//
// In that case the client should stop trying to fetch additional pages.
fakeSearchFn
=
sinon
.
spy
(
function
()
{
fakeSearchFn
=
sinon
.
spy
(
()
=>
{
return
Promise
.
resolve
({
rows
:
[],
total
:
1000
,
...
...
@@ -66,13 +77,13 @@ describe('SearchClient', function() {
client
.
get
({
uri
:
'http://example.com'
});
return
awaitEvent
(
client
,
'end'
).
then
(
function
()
{
return
awaitEvent
(
client
,
'end'
).
then
(
()
=>
{
assert
.
calledWith
(
onResults
,
[]);
assert
.
calledOnce
(
fakeSearchFn
);
});
});
it
(
'emits "results" once in non-incremental mode'
,
function
()
{
it
(
'emits "results" once in non-incremental mode'
,
()
=>
{
const
client
=
new
SearchClient
(
fakeSearchFn
,
{
chunkSize
:
2
,
incremental
:
false
,
...
...
@@ -80,13 +91,13 @@ describe('SearchClient', function() {
const
onResults
=
sinon
.
stub
();
client
.
on
(
'results'
,
onResults
);
client
.
get
({
uri
:
'http://example.com'
});
return
awaitEvent
(
client
,
'end'
).
then
(
function
()
{
return
awaitEvent
(
client
,
'end'
).
then
(
()
=>
{
assert
.
calledOnce
(
onResults
);
assert
.
calledWith
(
onResults
,
RESULTS
);
});
});
it
(
'does not emit "results" if canceled'
,
function
()
{
it
(
'does not emit "results" if canceled'
,
()
=>
{
const
client
=
new
SearchClient
(
fakeSearchFn
);
const
onResults
=
sinon
.
stub
();
const
onEnd
=
sinon
.
stub
();
...
...
@@ -94,22 +105,22 @@ describe('SearchClient', function() {
client
.
on
(
'end'
,
onEnd
);
client
.
get
({
uri
:
'http://example.com'
});
client
.
cancel
();
return
Promise
.
resolve
().
then
(
function
()
{
return
Promise
.
resolve
().
then
(
()
=>
{
assert
.
notCalled
(
onResults
);
assert
.
called
(
onEnd
);
});
});
it
(
'emits "error" event if search fails'
,
function
()
{
it
(
'emits "error" event if search fails'
,
()
=>
{
const
err
=
new
Error
(
'search failed'
);
fakeSearchFn
=
function
()
{
fakeSearchFn
=
()
=>
{
return
Promise
.
reject
(
err
);
};
const
client
=
new
SearchClient
(
fakeSearchFn
);
const
onError
=
sinon
.
stub
();
client
.
on
(
'error'
,
onError
);
client
.
get
({
uri
:
'http://example.com'
});
return
awaitEvent
(
client
,
'end'
).
then
(
function
()
{
return
awaitEvent
(
client
,
'end'
).
then
(
()
=>
{
assert
.
calledWith
(
onError
,
err
);
});
});
...
...
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