Skip to content

Fixes for Node 12 and various other changes for maintenance #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"presets": [
"stage-0"
"@babel/preset-env"
],
"plugins": [
"transform-es2015-modules-umd",
"@babel/plugin-transform-modules-umd",
"add-module-exports"
]
}
44 changes: 30 additions & 14 deletions __tests__/functions.spec.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import * as functions from '../functions';
import * as functions from '../common/functions';
import * as cypressFunctions from '../cypress/cypressFunctions';
import { ELEMENT_SELECTORS, STATE, setScreens } from '../common/variables';


let {
hex2rgbCSS,
buildClassSelector,
parseNumberEls,
getNormalized,
getSelector,
} = functions;

let {
getNormalized,
scroll,
click,
type,
replace,
open,
waitForResults,
dragAbove,
takeSnapshot,
takeElSnapshot,
compareSnapshot,
compareElSnapshot,
compareNamedSnapshot,
onPage,
redirectedTo,
nElements,
Expand All @@ -25,7 +30,7 @@ let {
elDoesNotExist,
elBackground,
elBorder,
} = functions;
} = cypressFunctions;

jest.mock('../common/variables');

Expand Down Expand Up @@ -387,28 +392,39 @@ describe('functions', () => {

});

test('takeSnapshot', () => {
takeSnapshot('Test');
test('compareSnapshot', () => {
compareSnapshot();

expect(matchImageSnapshot).toBeCalledWith(
'Test', {
threshold: 1000,
thresholdType: 'pixel'
null, {
failureThreshold: 0.1,
failureThresholdType: "percent"
}
);
});

test('takeElSnapshot', () => {
takeElSnapshot('Input');
test('compareElSnapshot', () => {
compareElSnapshot('Input');

expect(matchImageSnapshot).toBeCalledWith(
'Input', {
threshold: 1000,
thresholdType: 'pixel'
failureThreshold: 0.1,
failureThresholdType: "percent"
}
);
});

test('compareNamedSnapshot', () => {
compareNamedSnapshot('Test Page');

expect(matchImageSnapshot).toBeCalledWith(
'Test Page', {
failureThreshold: 0.1,
failureThresholdType: "percent"
}
);
});

test('onPage', () => {
onPage('Home');

Expand Down
27 changes: 18 additions & 9 deletions __tests__/phrases.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { REGEX } from '../phrases';
import * as REGEX from '../common/regex';

describe('REGEX', () => {
describe('SCROLL', () => {
Expand Down Expand Up @@ -217,19 +217,28 @@ describe('REGEX', () => {
});
});

describe('TAKE_SNAPSHOT', () => {
it('I take a snapshot named "Home Page"', () => {
const m = 'I take a snapshot named "Home Page"'
.match(REGEX.TAKE_SNAPSHOT);
describe('COMPARE_SNAPSHOT', () => {
it('I compare a snapshot', () => {
const m = 'I compare a snapshot'
.match(REGEX.COMPARE_SNAPSHOT);

expect(m[1]).toBe(undefined);
});
});

describe('COMPARE_SNAPSHOT_NAMED', () => {
it('I compare a snapshot named "Home Page"', () => {
const m = 'I compare a snapshot named "Home Page"'
.match(REGEX.COMPARE_SNAPSHOT_NAMED);

expect(m[1]).toBe('Home Page');
});
});

describe('TAKE_EL_SNAPSHOT', () => {
it('I take a snapshot of the "Modal"', () => {
const m = 'I take a snapshot of the "Modal"'
.match(REGEX.TAKE_EL_SNAPSHOT);
describe('COMPARE_EL_SNAPSHOT', () => {
it('I compare a snapshot of the "Modal"', () => {
const m = 'I compare a snapshot of the "Modal"'
.match(REGEX.COMPARE_EL_SNAPSHOT);

expect(m[1]).toBe('Modal');
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/regexBuilder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
int,
elInEl,
page,
} from '../regexBuilder';
} from '../common/regexBuilder';

describe('RegexBuilder', () => {
describe('r', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/router.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { processRoutes } from "../router";
import { processRoutes } from "../cypress/router";

describe('Router', () => {
describe('buildMap', () => {
Expand Down
6 changes: 4 additions & 2 deletions common/functions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const hex2rgb = require('hex-rgb');
const { wordsToNumbers } = require('words-to-numbers');
let wordsToNumbers = require('words-to-numbers');
wordsToNumbers = wordsToNumbers.default;
const pluralize = require('pluralize');
const { ELEMENT_SELECTORS } = require('../common/variables');
let variables = require('../common/variables');
let { ELEMENT_SELECTORS } = variables;

// COMMON FUNCTIONS

Expand Down
10 changes: 6 additions & 4 deletions common/regex.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
const regexBuilder = require('./regexBuilder');
const {
r,
string,
int,
elInEl,
page,
} = require('./regexBuilder');
} = regexBuilder;

module.exports = {
SCROLL: r(`I scroll to the (top|bottom) of the page`),
SCROLL_TO: r(`I scroll to${elInEl}`),
CLICK: r(`I click${elInEl}`),
TYPE: r(`I type ${string}${elInEl}`),
// TODO: FAKE: for faker methods is implemented directly in cypressPhrases on the fly
REPLACE: r(`I replace the contents${elInEl} with ${string}`),
OPEN: r(`I open${page}`),
WAIT_FOR_RESULTS: r(`I wait for results to load`),
WAIT_SECONDS: r(`I wait ${int} seconds`),
DRAG_ABOVE: r(`I drag${elInEl} above${elInEl}`),
TAKE_SNAPSHOT: r(`I take a snapshot`),
TAKE_EL_SNAPSHOT: r(`I take a snapshot of${elInEl}`),
TAKE_SNAPSHOT_NAMED: r(`I take a snapshot named ${string}`),
COMPARE_SNAPSHOT: r(`I compare a snapshot`),
COMPARE_EL_SNAPSHOT: r(`I compare a snapshot of${elInEl}`),
COMPARE_SNAPSHOT_NAMED: r(`I compare a snapshot named ${string}`),
ON_PAGE: r(`I should be on${page}`),
REDIRECTED_TO: r(`I should be redirected to${page}`),
N_ELEMENTS: r(`I should see ${int}${elInEl}`),
Expand Down
32 changes: 21 additions & 11 deletions cypress/cypressFunctions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const {
const variables = require('../common/variables');
let {
SCREENS,
STATE,
setState,
} = require('../common/variables');
} = variables;

const functions = require('../common/functions');
let { getSelector, hex2rgbCSS } = functions;

const { getSelector, hex2rgbCSS } = require('../common/functions');

const getNormalized = (elements, { text, singular } = {}) => {
const { className, firstOrdinal } = getSelector(elements, { text, singular, showOrdinals: true })
Expand Down Expand Up @@ -56,7 +59,7 @@ const type = (text, input, parent) => {
setState(randomVariable[1], randomNumber);
}

const stateVariableRegex = /<var:(\w+) >/;
const stateVariableRegex = /<var:(\w+)>/;
const stateVariable = text.match(stateVariableRegex);

if (stateVariable) {
Expand All @@ -66,6 +69,12 @@ const type = (text, input, parent) => {
getNormalized([parent, input]).type(text);
}

const fake = (asName, fakeValue, input, parent) => {
setState(asName, fakeValue);
getNormalized([parent, input]).type(fakeValue);
}


const replace = (input, parent, contains, text) => {
getNormalized([parent, input], { text: contains })
.clear()
Expand Down Expand Up @@ -123,16 +132,15 @@ const snapshotOptions = {
failureThresholdType: 'percent',
}

const takeSnapshot = () => {
const compareSnapshot = () => {
cy.matchImageSnapshot(null, snapshotOptions);

}

const takeNamedSnapshot = (name) => {
const compareNamedSnapshot = (name) => {
cy.matchImageSnapshot(name, snapshotOptions);
}

const takeElSnapshot = (el, parent) => {
const compareElSnapshot = (el, parent) => {
getNormalized([parent, el]).matchImageSnapshot(el, snapshotOptions);
}

Expand Down Expand Up @@ -175,13 +183,15 @@ module.exports = {
scroll,
click,
type,
fake,
replace,
open,
wait,
waitForResults,
dragAbove,
takeSnapshot,
takeElSnapshot,
compareSnapshot,
compareElSnapshot,
compareNamedSnapshot,
onPage,
redirectedTo,
nElements,
Expand All @@ -191,4 +201,4 @@ module.exports = {
elDoesNotExist,
elBackground,
elBorder,
};
};
Loading