Add sinon-test for easier test stub cleanup
This commit is contained in:
parent
5b7c0a98f7
commit
2f51c130cc
6 changed files with 71 additions and 58 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -4634,6 +4634,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"sinon-test": {
|
||||||
|
"version": "2.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/sinon-test/-/sinon-test-2.2.1.tgz",
|
||||||
|
"integrity": "sha512-j2X8jRz6GG/xBxCss3P36Q8QVdwV7DnOXOe4cNCsI0pbKRc2sErGTsHDimqZ1tiOmxw8ANog68T0SQq8hVMQRw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"slash": {
|
"slash": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz",
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
"multimatch": "^2.1.0",
|
"multimatch": "^2.1.0",
|
||||||
"node-sass": "^4.9.0",
|
"node-sass": "^4.9.0",
|
||||||
"sinon": "^4.5.0",
|
"sinon": "^4.5.0",
|
||||||
|
"sinon-test": "^2.2.1",
|
||||||
"universalify": "^0.1.1"
|
"universalify": "^0.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,13 @@ const browserifyConfigs = [
|
||||||
config: {
|
config: {
|
||||||
standalone: 'chaiAsPromised'
|
standalone: 'chaiAsPromised'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: 'node_modules/sinon-test/dist/sinon-test.js',
|
||||||
|
dest: 'test/resource/sinon-test.js',
|
||||||
|
config: {
|
||||||
|
standalone: 'sinonTest'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<script src="resource://zotero-unit/mocha.js"></script>
|
<script src="resource://zotero-unit/mocha.js"></script>
|
||||||
<script src="resource://zotero-unit/co-mocha.js"></script>
|
<script src="resource://zotero-unit/co-mocha.js"></script>
|
||||||
<script src="resource://zotero-unit/sinon.js"></script>
|
<script src="resource://zotero-unit/sinon.js"></script>
|
||||||
|
<script src="resource://zotero-unit/sinon-test.js"></script>
|
||||||
<script src="resource://zotero-unit/pako_inflate.js"></script>
|
<script src="resource://zotero-unit/pako_inflate.js"></script>
|
||||||
<script src="support.js" type="application/javascript;version=1.8"></script>
|
<script src="support.js" type="application/javascript;version=1.8"></script>
|
||||||
<script src="runtests.js" type="application/javascript;version=1.8"></script>
|
<script src="runtests.js" type="application/javascript;version=1.8"></script>
|
||||||
|
|
|
@ -171,6 +171,8 @@ mocha.setup({
|
||||||
|
|
||||||
coMocha(Mocha);
|
coMocha(Mocha);
|
||||||
|
|
||||||
|
sinon.test = sinonTest(sinon);
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
// Store all prefs set in runtests.sh
|
// Store all prefs set in runtests.sh
|
||||||
Components.utils.import("resource://zotero/config.js");
|
Components.utils.import("resource://zotero/config.js");
|
||||||
|
|
|
@ -790,66 +790,62 @@ describe("Connector Server", function () {
|
||||||
assert.equal(item.getField('title'), 'Title');
|
assert.equal(item.getField('title'), 'Title');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should save a PDF to the current selected collection and retrieve metadata", async function () {
|
it("should save a PDF to the current selected collection and retrieve metadata", sinon.test(async function () {
|
||||||
try {
|
var collection = await createDataObject('collection');
|
||||||
var collection = await createDataObject('collection');
|
await waitForItemsLoad(win);
|
||||||
await waitForItemsLoad(win);
|
|
||||||
|
var file = getTestDataDirectory();
|
||||||
|
file.append('test.pdf');
|
||||||
|
httpd.registerFile("/test.pdf", file);
|
||||||
|
|
||||||
|
var promise = waitForItemEvent('add');
|
||||||
|
var recognizerPromise = waitForRecognizer();
|
||||||
|
|
||||||
|
var origRequest = Zotero.HTTP.request.bind(Zotero.HTTP);
|
||||||
|
var called = 0;
|
||||||
|
var stub = sinon.stub(Zotero.HTTP, 'request').callsFake(function (method, url, options) {
|
||||||
|
// Forward saveSnapshot request
|
||||||
|
if (url.endsWith('saveSnapshot')) {
|
||||||
|
return origRequest(...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
var file = getTestDataDirectory();
|
// Fake recognizer response
|
||||||
file.append('test.pdf');
|
return Zotero.Promise.resolve({
|
||||||
httpd.registerFile("/test.pdf", file);
|
getResponseHeader: () => {},
|
||||||
|
responseText: JSON.stringify({
|
||||||
var promise = waitForItemEvent('add');
|
title: 'Test',
|
||||||
var recognizerPromise = waitForRecognizer();
|
authors: []
|
||||||
|
})
|
||||||
var origRequest = Zotero.HTTP.request.bind(Zotero.HTTP);
|
|
||||||
var called = 0;
|
|
||||||
var stub = sinon.stub(Zotero.HTTP, 'request').callsFake(function (method, url, options) {
|
|
||||||
// Forward saveSnapshot request
|
|
||||||
if (url.endsWith('saveSnapshot')) {
|
|
||||||
return origRequest(...arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fake recognizer response
|
|
||||||
return Zotero.Promise.resolve({
|
|
||||||
getResponseHeader: () => {},
|
|
||||||
responseText: JSON.stringify({
|
|
||||||
title: 'Test',
|
|
||||||
authors: []
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
await Zotero.HTTP.request(
|
|
||||||
'POST',
|
await Zotero.HTTP.request(
|
||||||
connectorServerPath + "/connector/saveSnapshot",
|
'POST',
|
||||||
{
|
connectorServerPath + "/connector/saveSnapshot",
|
||||||
headers: {
|
{
|
||||||
"Content-Type": "application/json"
|
headers: {
|
||||||
},
|
"Content-Type": "application/json"
|
||||||
body: JSON.stringify({
|
},
|
||||||
url: testServerPath + "/test.pdf",
|
body: JSON.stringify({
|
||||||
pdf: true
|
url: testServerPath + "/test.pdf",
|
||||||
})
|
pdf: true
|
||||||
}
|
})
|
||||||
);
|
}
|
||||||
|
);
|
||||||
var ids = await promise;
|
|
||||||
|
var ids = await promise;
|
||||||
assert.lengthOf(ids, 1);
|
|
||||||
var item = Zotero.Items.get(ids[0]);
|
assert.lengthOf(ids, 1);
|
||||||
assert.isTrue(item.isImportedAttachment());
|
var item = Zotero.Items.get(ids[0]);
|
||||||
assert.equal(item.attachmentContentType, 'application/pdf');
|
assert.isTrue(item.isImportedAttachment());
|
||||||
assert.isTrue(collection.hasItem(item.id));
|
assert.equal(item.attachmentContentType, 'application/pdf');
|
||||||
|
assert.isTrue(collection.hasItem(item.id));
|
||||||
var progressWindow = await recognizerPromise;
|
|
||||||
progressWindow.close();
|
var progressWindow = await recognizerPromise;
|
||||||
Zotero.RecognizePDF.cancel();
|
progressWindow.close();
|
||||||
assert.isFalse(item.isTopLevelItem());
|
Zotero.RecognizePDF.cancel();
|
||||||
} finally {
|
assert.isFalse(item.isTopLevelItem());
|
||||||
stub.restore();
|
}));
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should switch to My Library if a read-only library is selected", function* () {
|
it("should switch to My Library if a read-only library is selected", function* () {
|
||||||
var group = yield createGroup({
|
var group = yield createGroup({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue