Skip to content

Commit

Permalink
Fixed screenshot-test on windows getgauge/gauge#1476
Browse files Browse the repository at this point in the history
  • Loading branch information
negiDharmendra committed Jan 13, 2020
1 parent 6076bab commit e6cb955
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/screenshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const expect = require("chai").expect;
const screenshot = require("../src/screenshot");
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const sandbox = require("sinon").createSandbox();


Expand All @@ -14,17 +15,22 @@ function asyncScreenshotFunction() {
}

describe("screentshot.capture", function () {
const screenshotsDir = path.join(".gauge", "screenshots");

this.beforeEach( () => {
process.env.gauge_screenshots_dir = screenshotsDir;
});
afterEach(() => {
sandbox.restore();
});
describe("with default screenshot writer", () => {
it("should capture screentshot 5769768", function (done) {
process.env.gauge_screenshots_dir = ".gauge/screenshots";
let screenShotFile = "screenshot-21432453.png";
const spawnSyncStub = sandbox.stub(child_process, "spawnSync").returns({});
sandbox.stub(process.hrtime, "bigint").returns(21432453);
screenshot.capture().then(function (file) {
const expectedArgs = ["gauge_screenshot", [".gauge/screenshots/" + screenShotFile]];
const filePath = path.join(screenshotsDir, screenShotFile);
const expectedArgs = ["gauge_screenshot", [filePath]];
const actualArgs = spawnSyncStub.getCall(0).args;

expect(file).to.be.equal(screenShotFile);
Expand All @@ -45,7 +51,8 @@ describe("screentshot.capture", function () {
const writeFileSyncStub = sandbox.stub(fs, "writeFileSync");

screenshot.capture().then(function (file) {
const expectedArgs = [".gauge/screenshots/" + screenShotFile, Buffer.from("screentshot").toString("base64")];
const filePath = path.join(screenshotsDir, screenShotFile);
const expectedArgs = [filePath, Buffer.from("screentshot").toString("base64")];
const actualArgs = writeFileSyncStub.getCall(0).args;
expect(file).to.be.equal(screenShotFile);
expect(actualArgs).to.be.deep.equal(expectedArgs);
Expand All @@ -60,7 +67,8 @@ describe("screentshot.capture", function () {
const writeFileSyncStub = sandbox.stub(fs, "writeFileSync");

screenshot.capture().then(function (file) {
const expectedArgs = [".gauge/screenshots/" + screenShotFile, Buffer.from("screentshot").toString("base64")];
const filePath = path.join(screenshotsDir, screenShotFile);
const expectedArgs = [filePath, Buffer.from("screentshot").toString("base64")];
const actualArgs = writeFileSyncStub.getCall(0).args;
expect(file).to.be.equal(screenShotFile);
expect(actualArgs).to.be.deep.equal(expectedArgs);
Expand Down

0 comments on commit e6cb955

Please sign in to comment.