Skip to content

Commit

Permalink
- ActionSnapshot - added test for making snapshots
Browse files Browse the repository at this point in the history
:goose:
  • Loading branch information
maZahaca committed Nov 26, 2018
1 parent 927e5b8 commit c7c908f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
34 changes: 29 additions & 5 deletions test/integration/actions/actions.test.js
@@ -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', () => {
Expand All @@ -12,7 +12,9 @@ describe('Actions', () => {
beforeAll(async () => {
testServer = await createTestServer();
parser = new Parser({
environment: new ChromeEnvironment({}),
environment: new ChromeEnvironment({
snapshot: true,
}),
mode: 'multiple',
});
});
Expand Down Expand Up @@ -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" />`,
});
Expand All @@ -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" />`,
});
Expand All @@ -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);
});
});
});
28 changes: 28 additions & 0 deletions test/tools.js
@@ -1,4 +1,5 @@
const http = require('http');
const fs = require('fs');

const port = 60053;
let responseRoutes = [];
Expand Down Expand Up @@ -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}/`,
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit c7c908f

Please sign in to comment.