New 'screenshot' option when launching a test
This commit is contained in:
+8
-1
@@ -131,7 +131,6 @@ describe('api', function() {
|
||||
}, function(error, response, body) {
|
||||
if (!error && response.statusCode === 302) {
|
||||
|
||||
console.log(response.headers.location);
|
||||
response.headers.should.have.a.property('location').that.is.a('string');
|
||||
response.headers.location.should.contain('/rules');
|
||||
|
||||
@@ -160,6 +159,14 @@ describe('api', function() {
|
||||
body.should.have.a.property('toolsResults').that.is.an('object');
|
||||
body.should.have.a.property('javascriptExecutionTree').that.is.an('object');
|
||||
|
||||
// Check if the screenshot temporary file was correctly removed
|
||||
body.params.options.should.not.have.a.property('screenshot');
|
||||
// Check if the screenshot buffer was correctly removed
|
||||
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');
|
||||
|
||||
done();
|
||||
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
var should = require('chai').should();
|
||||
var ScreenshotHandler = require('../../lib/screenshotHandler');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
describe('screenshotHandler', function() {
|
||||
|
||||
var imagePath = path.join(__dirname, '../fixtures/logo-large.png');
|
||||
var screenshot, lwipImage;
|
||||
|
||||
|
||||
it('should open an image and return an lwip object', function(done) {
|
||||
ScreenshotHandler.openImage(imagePath)
|
||||
.then(function(image) {
|
||||
lwipImage = image;
|
||||
|
||||
lwipImage.should.be.an('object');
|
||||
lwipImage.width().should.equal(620);
|
||||
lwipImage.height().should.equal(104);
|
||||
|
||||
done();
|
||||
})
|
||||
.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should resize an lwip image', function(done) {
|
||||
ScreenshotHandler.resizeImage(lwipImage, 310)
|
||||
.then(function(image) {
|
||||
lwipImage = image;
|
||||
|
||||
lwipImage.width().should.equal(310);
|
||||
lwipImage.height().should.equal(52);
|
||||
|
||||
done();
|
||||
})
|
||||
.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should transform a lwip image into a buffer', function(done) {
|
||||
ScreenshotHandler.toBuffer(lwipImage)
|
||||
.then(function(buffer) {
|
||||
buffer.should.be.an.instanceof(Buffer);
|
||||
done();
|
||||
})
|
||||
.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should optimize an image and return a buffered version', function(done) {
|
||||
ScreenshotHandler.optimize(imagePath, 200)
|
||||
.then(function(buffer) {
|
||||
buffer.should.be.an.instanceof(Buffer);
|
||||
done();
|
||||
})
|
||||
.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should provide a temporary file object', function() {
|
||||
screenshot = ScreenshotHandler.getScreenshotTempFile();
|
||||
|
||||
screenshot.should.have.a.property('getTmpFolder').that.is.a('function');
|
||||
screenshot.should.have.a.property('getTmpFilePath').that.is.a('function');
|
||||
screenshot.should.have.a.property('toThumbnail').that.is.a('function');
|
||||
screenshot.should.have.a.property('deleteTmpFile').that.is.a('function');
|
||||
});
|
||||
|
||||
|
||||
it('should have created the temporary folder', function() {
|
||||
var folder = screenshot.getTmpFolder();
|
||||
fs.existsSync(folder.path).should.equal(true);
|
||||
});
|
||||
|
||||
|
||||
it('should respond a temporary file', function() {
|
||||
var file = screenshot.getTmpFilePath();
|
||||
file.should.have.string('/screenshot.jpg');
|
||||
});
|
||||
|
||||
|
||||
it('should delete the temp folder when there is no file', function(done) {
|
||||
var tmpFolderPath = screenshot;
|
||||
|
||||
screenshot.deleteTmpFile()
|
||||
.then(function() {
|
||||
fs.existsSync(screenshot.getTmpFolder().path).should.equal(false);
|
||||
done();
|
||||
})
|
||||
.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete the temp folder with the screenshot inside', function(done) {
|
||||
screenshot = ScreenshotHandler.getScreenshotTempFile();
|
||||
var tmpFolderPath = screenshot.getTmpFolder().path;
|
||||
var tmpImagePath = path.join(tmpFolderPath, 'screenshot.jpg');
|
||||
|
||||
// Copy image
|
||||
var testImage = fs.readFileSync(imagePath);
|
||||
fs.writeFileSync(tmpImagePath, testImage);
|
||||
|
||||
fs.existsSync(tmpImagePath).should.equal(true);
|
||||
|
||||
screenshot.deleteTmpFile()
|
||||
.then(function() {
|
||||
fs.existsSync(tmpImagePath).should.equal(false);
|
||||
fs.existsSync(tmpFolderPath).should.equal(false);
|
||||
done();
|
||||
})
|
||||
.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user