New API route to retrieve a screenshot
This commit is contained in:
+39
-2
@@ -16,6 +16,7 @@ describe('api', function() {
|
||||
|
||||
var syncRunResultUrl;
|
||||
var asyncRunId;
|
||||
var screenshotUrl;
|
||||
|
||||
|
||||
it('should refuse a query with an invalid key', function(done) {
|
||||
@@ -94,7 +95,8 @@ describe('api', function() {
|
||||
url: serverUrl + '/api/runs',
|
||||
body: {
|
||||
url: wwwUrl + '/simple-page.html',
|
||||
waitForResponse: true
|
||||
waitForResponse: true,
|
||||
screenshot: true
|
||||
},
|
||||
json: true,
|
||||
headers: {
|
||||
@@ -165,7 +167,9 @@ describe('api', function() {
|
||||
body.should.not.have.a.property('screenshotBuffer');
|
||||
// Check if the screenshot url is here
|
||||
body.should.have.a.property('screenshotUrl');
|
||||
body.screenshotUrl.should.have.string('/result/' + body.runId + '/screenshot.jpg');
|
||||
body.screenshotUrl.should.equal('/api/results/' + body.runId + '/screenshot.jpg');
|
||||
|
||||
screenshotUrl = body.screenshotUrl;
|
||||
|
||||
done();
|
||||
|
||||
@@ -523,4 +527,37 @@ describe('api', function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should retrieve the screenshot', function(done) {
|
||||
this.timeout(5000);
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
url: serverUrl + screenshotUrl
|
||||
}, function(error, response, body) {
|
||||
if (!error && response.statusCode === 200) {
|
||||
response.headers['content-type'].should.equal('image/jpeg');
|
||||
done();
|
||||
} else {
|
||||
done(error || response.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fail on a unexistant screenshot', function(done) {
|
||||
this.timeout(5000);
|
||||
|
||||
request({
|
||||
method: 'GET',
|
||||
url: serverUrl + '/api/results/000000/screenshot.jpg'
|
||||
}, function(error, response, body) {
|
||||
if (!error && response.statusCode === 404) {
|
||||
done();
|
||||
} else {
|
||||
done(error || response.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
var should = require('chai').should();
|
||||
var resultsDatastore = require('../../lib/server/datastores/resultsDatastore');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
describe('resultsDatastore', function() {
|
||||
|
||||
var datastore = new resultsDatastore();
|
||||
@@ -71,4 +74,48 @@ describe('resultsDatastore', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var testId3 = '555555';
|
||||
var testData3 = {
|
||||
runId: testId3,
|
||||
other: {
|
||||
foo: 'foo',
|
||||
bar: 2
|
||||
},
|
||||
screenshotBuffer: fs.readFileSync(path.join(__dirname, '../fixtures/logo-large.png'))
|
||||
};
|
||||
|
||||
it('should store a test with a screenshot', function(done) {
|
||||
|
||||
datastore.saveResult(testData3).then(function() {
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have a normal result', function(done) {
|
||||
datastore.getResult(testId3)
|
||||
.then(function(results) {
|
||||
|
||||
results.should.not.have.a.property('screenshot');
|
||||
|
||||
done();
|
||||
})
|
||||
.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should retrieve the saved image', function() {
|
||||
datastore.getScreenshot(testId3)
|
||||
.then(function(imageBuffer) {
|
||||
imageBuffer.should.be.an.instanceof(Buffer);
|
||||
done();
|
||||
})
|
||||
.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user