Skip to content
Permalink
Browse files

- ActionSnapshot - added test for making snapshots

:goose:
  • Loading branch information...
maZahaca committed Nov 26, 2018
1 parent 927e5b8 commit c7c908f92413715e8a0b5baffc0a32e734608bb3
Showing with 61 additions and 9 deletions.
  1. +1 −1 package.json
  2. +29 −5 test/integration/actions/actions.test.js
  3. +28 −0 test/tools.js
  4. +3 −3 yarn.lock
@@ -64,7 +64,7 @@
"devDependencies": {
"codecov": "^3.1.0",
"goose-abstract-environment": "^1.0.12",
"goose-chrome-environment": "^1.1.1",
"goose-chrome-environment": "^1.1.2",
"goose-paginator": "^1.0.2",
"jest": "^23.6.0",
"rimraf": "^2.6.2",
@@ -1,8 +1,8 @@
/* eslint-env jest */

const { createTestServer, setServerResponse, url } = require('../../tools');
const Parser = require('../../../lib/Parser');
const ChromeEnvironment = require('goose-chrome-environment');
const { fileExists, removeFile, createTestServer, setServerResponse, url } = require('../../tools');
const Parser = require('../../../lib/Parser');

jest.setTimeout(20000);
describe('Actions', () => {
@@ -12,7 +12,9 @@ describe('Actions', () => {
beforeAll(async () => {
testServer = await createTestServer();
parser = new Parser({
environment: new ChromeEnvironment({}),
environment: new ChromeEnvironment({
snapshot: true,
}),
mode: 'multiple',
});
});
@@ -551,7 +553,7 @@ describe('Actions', () => {
});

describe('ActionParse', () => {
test('typing value from prev action', async () => {
test('parse nothing', async () => {
setServerResponse({
html: `<span>test</span><input type="text" />`,
});
@@ -578,7 +580,7 @@ describe('Actions', () => {
});

describe('ActionUrl', () => {
test('typing value from prev action', async () => {
test('fetching page url', async () => {
setServerResponse({
html: `<span>test</span><input type="text" />`,
});
@@ -603,4 +605,26 @@ describe('Actions', () => {
expect(result).toEqual(url);
});
});

describe('ActionSnapshot', () => {
test('making page snapshot', async () => {
setServerResponse({
html: `<span>test</span><input type="text" />`,
});
await parser.parse({
url,
actions: [
{
type: 'snapshot',
name: 'test',
},
],
});

const filePath = './snapshots/localhost/test.png';
const snapshotExists = await fileExists(filePath);
expect(snapshotExists).toEqual(true);
await removeFile(filePath);
});
});
});
@@ -1,4 +1,5 @@
const http = require('http');
const fs = require('fs');

const port = 60053;
let responseRoutes = [];
@@ -73,7 +74,34 @@ function setServerResponse(response) {
}
}

function fileExists(path) {
return new Promise(resolve => {
fs.access(path, fs.F_OK, (err) => {
if (err) {
resolve(false);
return;
}

resolve(true);
});
});
}

function removeFile(path) {
return new Promise((resolve, reject) => {
fs.unlink(path, (err) => {
if (err) {
reject(err);
return;
}
resolve();
});
});
}

module.exports = {
fileExists,
removeFile,
setServerResponse,
createTestServer,
url: `http://localhost:${port}/`,
@@ -1329,9 +1329,9 @@ goose-abstract-environment@^1.0.12:
babel-polyfill "^6.23.0"
debug "^3.1.0"

goose-chrome-environment@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/goose-chrome-environment/-/goose-chrome-environment-1.1.1.tgz#115c892002dc0e59afb24421d603c9e64290f5b5"
goose-chrome-environment@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/goose-chrome-environment/-/goose-chrome-environment-1.1.2.tgz#b06f6aff57a29cea7aa1589670785105a32cf39c"
dependencies:
babel-polyfill "^6.23.0"
debug "^3.1.0"

0 comments on commit c7c908f

Please sign in to comment.
You can’t perform that action at this time.