Skip to content

Commit 2ce8906

Browse files
committed
Fixes for Node 12 and various other changes for maintance
- Fixes all jest tests - Fixes various require statements to import - Fixes docusaurus by locking version - Changes `takeSnapshot` functions to `compareSnapshot` - Changes related phrases for take to compare - Replaces `When` for compare with `Then`, its only an assertion, even though there is a side effect of saving snapshots Remaining work: Resolve cypress tests
1 parent cdb0463 commit 2ce8906

File tree

17 files changed

+110
-107
lines changed

17 files changed

+110
-107
lines changed

__tests__/functions.spec.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
import * as functions from '../functions';
1+
import * as functions from '../common/functions';
2+
import * as cypressFunctions from '../cypress/cypressFunctions';
23
import { ELEMENT_SELECTORS, STATE, setScreens } from '../common/variables';
34

5+
46
let {
57
hex2rgbCSS,
68
buildClassSelector,
79
parseNumberEls,
8-
getNormalized,
910
getSelector,
11+
} = functions;
1012

13+
let {
14+
getNormalized,
1115
scroll,
1216
click,
1317
type,
1418
replace,
1519
open,
1620
waitForResults,
1721
dragAbove,
18-
takeSnapshot,
19-
takeElSnapshot,
22+
compareSnapshot,
23+
compareElSnapshot,
24+
compareNamedSnapshot,
2025
onPage,
2126
redirectedTo,
2227
nElements,
@@ -25,7 +30,7 @@ let {
2530
elDoesNotExist,
2631
elBackground,
2732
elBorder,
28-
} = functions;
33+
} = cypressFunctions;
2934

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

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

388393
});
389394

390-
test('takeSnapshot', () => {
391-
takeSnapshot('Test');
395+
test('compareSnapshot', () => {
396+
compareSnapshot();
392397

393398
expect(matchImageSnapshot).toBeCalledWith(
394-
'Test', {
395-
threshold: 1000,
396-
thresholdType: 'pixel'
399+
null, {
400+
failureThreshold: 0.1,
401+
failureThresholdType: "percent"
397402
}
398403
);
399404
});
400405

401-
test('takeElSnapshot', () => {
402-
takeElSnapshot('Input');
406+
test('compareElSnapshot', () => {
407+
compareElSnapshot('Input');
403408

404409
expect(matchImageSnapshot).toBeCalledWith(
405410
'Input', {
406-
threshold: 1000,
407-
thresholdType: 'pixel'
411+
failureThreshold: 0.1,
412+
failureThresholdType: "percent"
408413
}
409414
);
410415
});
411416

417+
test('compareNamedSnapshot', () => {
418+
compareNamedSnapshot('Test Page');
419+
420+
expect(matchImageSnapshot).toBeCalledWith(
421+
'Test Page', {
422+
failureThreshold: 0.1,
423+
failureThresholdType: "percent"
424+
}
425+
);
426+
});
427+
412428
test('onPage', () => {
413429
onPage('Home');
414430

__tests__/phrases.spec.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { REGEX } from '../phrases';
1+
import * as REGEX from '../common/regex';
22

33
describe('REGEX', () => {
44
describe('SCROLL', () => {
@@ -217,19 +217,28 @@ describe('REGEX', () => {
217217
});
218218
});
219219

220-
describe('TAKE_SNAPSHOT', () => {
221-
it('I take a snapshot named "Home Page"', () => {
222-
const m = 'I take a snapshot named "Home Page"'
223-
.match(REGEX.TAKE_SNAPSHOT);
220+
describe('COMPARE_SNAPSHOT', () => {
221+
it('I compare a snapshot', () => {
222+
const m = 'I compare a snapshot'
223+
.match(REGEX.COMPARE_SNAPSHOT);
224+
225+
expect(m[1]).toBe(undefined);
226+
});
227+
});
228+
229+
describe('COMPARE_SNAPSHOT_NAMED', () => {
230+
it('I compare a snapshot named "Home Page"', () => {
231+
const m = 'I compare a snapshot named "Home Page"'
232+
.match(REGEX.COMPARE_SNAPSHOT_NAMED);
224233

225234
expect(m[1]).toBe('Home Page');
226235
});
227236
});
228237

229-
describe('TAKE_EL_SNAPSHOT', () => {
230-
it('I take a snapshot of the "Modal"', () => {
231-
const m = 'I take a snapshot of the "Modal"'
232-
.match(REGEX.TAKE_EL_SNAPSHOT);
238+
describe('COMPARE_EL_SNAPSHOT', () => {
239+
it('I compare a snapshot of the "Modal"', () => {
240+
const m = 'I compare a snapshot of the "Modal"'
241+
.match(REGEX.COMPARE_EL_SNAPSHOT);
233242

234243
expect(m[1]).toBe('Modal');
235244
});

__tests__/regexBuilder.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
int,
66
elInEl,
77
page,
8-
} from '../regexBuilder';
8+
} from '../common/regexBuilder';
99

1010
describe('RegexBuilder', () => {
1111
describe('r', () => {

__tests__/router.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { processRoutes } from "../router";
1+
import { processRoutes } from "../cypress/router";
22

33
describe('Router', () => {
44
describe('buildMap', () => {

common/functions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const hex2rgb = require('hex-rgb');
2-
const { wordsToNumbers } = require('words-to-numbers');
2+
let wordsToNumbers = require('words-to-numbers');
3+
wordsToNumbers = wordsToNumbers.default;
34
const pluralize = require('pluralize');
4-
const { ELEMENT_SELECTORS } = require('../common/variables');
5+
let variables = require('../common/variables');
6+
let { ELEMENT_SELECTORS } = variables;
57

68
// COMMON FUNCTIONS
79

common/regex.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
const regexBuilder = require('./regexBuilder');
12
const {
23
r,
34
string,
45
int,
56
elInEl,
67
page,
7-
} = require('./regexBuilder');
8+
} = regexBuilder;
89

910
module.exports = {
1011
SCROLL: r(`I scroll to the (top|bottom) of the page`),
@@ -16,9 +17,9 @@ module.exports = {
1617
WAIT_FOR_RESULTS: r(`I wait for results to load`),
1718
WAIT_SECONDS: r(`I wait ${int} seconds`),
1819
DRAG_ABOVE: r(`I drag${elInEl} above${elInEl}`),
19-
TAKE_SNAPSHOT: r(`I take a snapshot`),
20-
TAKE_EL_SNAPSHOT: r(`I take a snapshot of${elInEl}`),
21-
TAKE_SNAPSHOT_NAMED: r(`I take a snapshot named ${string}`),
20+
COMPARE_SNAPSHOT: r(`I compare a snapshot`),
21+
COMPARE_EL_SNAPSHOT: r(`I compare a snapshot of${elInEl}`),
22+
COMPARE_SNAPSHOT_NAMED: r(`I compare a snapshot named ${string}`),
2223
ON_PAGE: r(`I should be on${page}`),
2324
REDIRECTED_TO: r(`I should be redirected to${page}`),
2425
N_ELEMENTS: r(`I should see ${int}${elInEl}`),

cypress/cypressFunctions.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
const {
1+
const variables = require('../common/variables');
2+
let {
23
SCREENS,
34
STATE,
45
setState,
5-
} = require('../common/variables');
6+
} = variables;
7+
8+
const functions = require('../common/functions');
9+
let { getSelector, hex2rgbCSS } = functions;
610

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

912
const getNormalized = (elements, { text, singular } = {}) => {
1013
const { className, firstOrdinal } = getSelector(elements, { text, singular, showOrdinals: true })
@@ -123,16 +126,15 @@ const snapshotOptions = {
123126
failureThresholdType: 'percent',
124127
}
125128

126-
const takeSnapshot = () => {
129+
const compareSnapshot = () => {
127130
cy.matchImageSnapshot(null, snapshotOptions);
128-
129131
}
130132

131-
const takeNamedSnapshot = (name) => {
133+
const compareNamedSnapshot = (name) => {
132134
cy.matchImageSnapshot(name, snapshotOptions);
133135
}
134136

135-
const takeElSnapshot = (el, parent) => {
137+
const compareElSnapshot = (el, parent) => {
136138
getNormalized([parent, el]).matchImageSnapshot(el, snapshotOptions);
137139
}
138140

@@ -180,9 +182,9 @@ module.exports = {
180182
wait,
181183
waitForResults,
182184
dragAbove,
183-
takeSnapshot,
184-
takeElSnapshot,
185-
takeNamedSnapshot,
185+
compareSnapshot,
186+
compareElSnapshot,
187+
compareNamedSnapshot,
186188
onPage,
187189
redirectedTo,
188190
nElements,

cypress/cypressPhrases.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const {
66
open,
77
waitForResults,
88
dragAbove,
9-
takeSnapshot,
10-
takeElSnapshot,
11-
takeNamedSnapshot,
9+
compareSnapshot,
10+
compareElSnapshot,
11+
compareNamedSnapshot,
1212
onPage,
1313
redirectedTo,
1414
nElements,
@@ -56,12 +56,9 @@ module.exports = () => {
5656
// This is experimental and not part of the official API
5757
When(REGEX.DRAG_ABOVE, dragAbove);
5858

59-
When(REGEX.TAKE_SNAPSHOT, takeSnapshot);
60-
When(REGEX.TAKE_EL_SNAPSHOT, takeElSnapshot);
61-
When(REGEX.TAKE_SNAPSHOT_NAMED, takeNamedSnapshot)
62-
Then(REGEX.TAKE_SNAPSHOT, takeSnapshot);
63-
Then(REGEX.TAKE_EL_SNAPSHOT, takeElSnapshot);
64-
Then(REGEX.TAKE_SNAPSHOT_NAMED, takeNamedSnapshot)
59+
Then(REGEX.COMPARE_SNAPSHOT, compareSnapshot);
60+
Then(REGEX.COMPARE_EL_SNAPSHOT, compareElSnapshot);
61+
Then(REGEX.COMPARE_SNAPSHOT_NAMED, compareNamedSnapshot)
6562

6663
// ex: I should be on the "Login Screen"
6764
Then(REGEX.ON_PAGE, onPage);

cypress/router.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const processRoutes = (routes) => {
1616
});
1717
}
1818

19-
module.exports =(routes, { stubAll } = {}) => {
19+
module.exports = (routes, { stubAll } = {}) => {
2020
beforeEach(() => {
2121
cy.server();
2222

@@ -25,4 +25,6 @@ module.exports =(routes, { stubAll } = {}) => {
2525

2626
processRoutes(routes);
2727
});
28-
}
28+
}
29+
30+
module.exports.processRoutes = processRoutes

docs/functions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,18 @@ waitForResults() =>
208208
cy.timeout(1000)
209209
```
210210

211-
### takeSnapshot
212-
Takes s a snapshot of the entire page and matches it against al old snapshot taken. Save is under the name specified
211+
### compareSnapshot
212+
Saves and compares a snapshot of the entire page to the previously (if one) taken snapshot. Saved under the name specified
213213

214214
```
215-
takeSnapshot('Test Page')
215+
compareSnapshot('Test Page')
216216
```
217217

218-
### takeElSnapshot
218+
### compareElSnapshot
219219
Takes a snapshot of an element
220220

221221
```
222-
takeElSnapshot('Input');
222+
compareElSnapshot('Input');
223223
```
224224

225225
### onPage

0 commit comments

Comments
 (0)