Skip to content

Commit b6cc1c9

Browse files
authored
Refactor: Setup Cypress and add more examples (#149)
* Started refactoring example page * refactoring examples * tweaks * Done adding examples * working on writing tests * finished writing tests * workaround prettier-browser problem * attempt setting up circleci * update ci conf * output more versions * run real tests * correct the test runner * hmmm * still trying * trying circleci image instead * not good, don't cache what could break * add cypress deps * sudo * attempt using chrome * cleanup
1 parent 1272020 commit b6cc1c9

File tree

21 files changed

+1123
-2168
lines changed

21 files changed

+1123
-2168
lines changed

.circleci/config.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,50 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/node:carbon
5+
- image: circleci/node:carbon-browsers
66

77
working_directory: ~/repo
88

99
steps:
1010
- checkout
1111

12+
- run: node --version && npm --version && npx --version && yarn --version
13+
14+
- run:
15+
name: Install Cypress dependencies
16+
command: sudo apt-get install xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
17+
1218
- add-ssh-keys:
1319
fingerprints:
1420
- "e1:ca:5d:f0:58:11:c7:ae:b7:ac:4a:1b:cc:3a:0d:4a"
1521

1622
- restore_cache:
1723
keys:
18-
- v2-dependencies-{{ checksum "yarn.lock" }}
19-
- v2-dependencies-
24+
- v3-dependencies-{{ checksum "yarn.lock" }}
25+
- v3-dependencies-
2026

2127
- run: yarn install
2228

2329
- run: yarn build
2430

31+
- run:
32+
command: yarn start
33+
background: true
34+
35+
- run: npx wait-on http://localhost:3000
36+
2537
- run: yarn test
2638

39+
- store_test_results:
40+
path: junit
41+
42+
- store_artifacts:
43+
path: cypress/screenshots
44+
2745
- save_cache:
2846
paths:
2947
- node_modules
30-
key: v2-dependencies-{{ checksum "yarn.lock" }}
48+
key: v3-dependencies-{{ checksum "yarn.lock" }}
3149

3250
- run: yarn semantic-release || true
3351

config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"reporterEnabled": "spec, mocha-junit-reporter"
3+
}

cypress.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"baseUrl": "http://localhost:3000"
3+
}

cypress/fixtures/example.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

cypress/fixtures/profile.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

cypress/fixtures/users.json

Lines changed: 0 additions & 232 deletions
This file was deleted.

cypress/integration/example.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
describe('Basic Functionality', function() {
2+
beforeEach(function() {
3+
// Visiting our app before each test removes any state build up from
4+
// previous tests. Visiting acts as if we closed a tab and opened a fresh one
5+
cy.visit('/')
6+
7+
// Setup observers and set dataset values for test convenience
8+
cy.window().then(win => {
9+
const { IntersectionObserver, document, scrollIntoViewIfNeeded } = win
10+
11+
var options = {
12+
root: null,
13+
rootMargin: '0px',
14+
threshold: [0, 0.25, 0.5, 0.75, 1],
15+
}
16+
17+
var observer = new IntersectionObserver(function(entries, observer) {
18+
entries.forEach(entry => {
19+
entry.target.dataset.visibility =
20+
entry.intersectionRatio >= 1 ? 'visible' : 'hidden'
21+
})
22+
}, options)
23+
observer.observe(document.querySelector('#instance1 > li:nth-child(21)'))
24+
document.querySelectorAll('button').forEach(button => {
25+
button.dataset.nth = parseInt(button.value, 10) + 1
26+
const parent = button.closest('div')
27+
const item = parent.querySelector(`li:nth-child(${button.dataset.nth})`)
28+
item.dataset.visibility = 'hidden'
29+
observer.observe(item)
30+
})
31+
})
32+
})
33+
it('should scroll the list correctly', function() {
34+
cy.get('#list1 button').each(function($el, index, $list) {
35+
cy.wrap($el).click({ force: true })
36+
const key = $el.data('nth')
37+
cy.wait(300)
38+
cy
39+
.get(`#list1 li:nth-child(${key})`)
40+
.should('have.data', 'visibility', 'visible')
41+
})
42+
})
43+
it('should not scroll beyond boundary', function() {
44+
cy.get('#list2').scrollIntoView()
45+
cy.get('#list2 button:last').click({ force: true })
46+
cy.wait(300)
47+
cy.get(`#list2 li:first`).should('have.data', 'visibility', 'hidden')
48+
cy.get(`#list2 li:last`).should('have.data', 'visibility', 'visible')
49+
})
50+
it('should scroll the last list correctly', function() {
51+
cy.get('#list3 button').each(function($el, index, $list) {
52+
cy.wrap($el).click({ force: true })
53+
const key = $el.data('nth')
54+
cy
55+
.get(`#list3 li:nth-child(${key})`)
56+
.should('have.data', 'visibility', 'visible')
57+
})
58+
})
59+
})

0 commit comments

Comments
 (0)