Skip to content

Commit f41e122

Browse files
committedDec 28, 2020
added tests
1 parent 9adc6b4 commit f41e122

12 files changed

+2178
-1261
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
3-
TODO.md
3+
TODO.md
4+
tests/__image_snapshots__

‎dist/color-picker.min.js

+416-2
Large diffs are not rendered by default.

‎jest-playwright.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
browsers: ['chromium', 'firefox', 'webkit'],
3+
launchOptions: {
4+
headless: true
5+
},
6+
contextOptions: {
7+
deviceScaleFactor: 1,
8+
viewport: {
9+
width: 750,
10+
height: 750
11+
}
12+
},
13+
serverOptions: {
14+
command: 'serve . -p 5000',
15+
port: 5000
16+
}
17+
}

‎jest.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
preset: 'jest-playwright-preset',
3+
coverageReporters: ['text'],
4+
setupFilesAfterEnv: ['<rootDir>/tests/setup.js'],
5+
testTimeout: 35000 // Most timeouts in playwright are set to 30s
6+
}

‎package-lock.json

+1,645-1,249
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"makedir": "mkdirp dist",
4242
"push": "git push origin",
4343
"push:tags": "git push origin --tags",
44-
"test": "echo \"No test specified\"",
44+
"test": "jest",
4545
"prepublishOnly": "npm run build:prod && git add . && git commit -am '[BUILD]' && pkg-ok"
4646
},
4747
"author": {
@@ -63,27 +63,28 @@
6363
},
6464
"devDependencies": {
6565
"@babel/core": "^7.12.10",
66-
"@babel/preset-env": "^7.12.10",
66+
"@babel/preset-env": "^7.12.11",
6767
"@rollup/plugin-babel": "^5.2.2",
6868
"@rollup/plugin-commonjs": "^17.0.0",
69-
"@rollup/plugin-node-resolve": "^11.0.0",
69+
"@rollup/plugin-node-resolve": "^11.0.1",
7070
"concurrently": "^5.3.0",
7171
"jest": "^26.6.3",
7272
"jest-environment-puppeteer": "^4.4.0",
73-
"jest-image-snapshot": "^4.2.0",
73+
"jest-image-snapshot": "^4.3.0",
7474
"jest-playwright-preset": "^1.4.2",
7575
"mkdirp": "^1.0.4",
7676
"node-sass": "^5.0.0",
7777
"onchange": "^7.1.0",
78-
"playwright-chromium": "^1.6.2",
79-
"playwright-firefox": "^1.6.2",
80-
"playwright-webkit": "^1.6.2",
78+
"playwright-chromium": "^1.7.1",
79+
"playwright-firefox": "^1.7.1",
80+
"playwright-webkit": "^1.7.1",
8181
"rimraf": "^3.0.2",
82-
"rollup": "^2.34.2",
82+
"rollup": "^2.35.1",
8383
"rollup-plugin-cleanup": "^3.2.1",
8484
"rollup-plugin-livereload": "^2.0.0",
8585
"rollup-plugin-scss": "^2.6.1",
8686
"rollup-plugin-serve": "^1.1.0",
87-
"rollup-plugin-terser": "^7.0.2"
87+
"rollup-plugin-terser": "^7.0.2",
88+
"serve": "^11.3.2"
8889
}
8990
}

‎src/jest-playwright.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
browsers: ['chromium', 'firefox', 'webkit'],
3+
launchOptions: {
4+
headless: true
5+
},
6+
contextOptions: {
7+
deviceScaleFactor: 1,
8+
viewport: {
9+
width: 750,
10+
height: 750
11+
}
12+
},
13+
serverOptions: {
14+
command: 'serve . -p 5000',
15+
port: 5000
16+
}
17+
}

‎tests/basic.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { loadVisualTest } = require('./utils')
2+
3+
describe('color picker', () => {
4+
5+
it('Should display Hue, Saturation, Lightness & Alpha range sliders', async () => {
6+
await loadVisualTest('basic.html')
7+
expect(await page.screenshot()).toMatchImageSnapshot()
8+
})
9+
10+
it('Should display 4 colors in the swatches: red, blue, green, pink', async () => {
11+
await loadVisualTest('swatches.html')
12+
expect(await page.screenshot()).toMatchImageSnapshot()
13+
})
14+
15+
// it('Should call all callbacks with correct arguments', async() => {
16+
// await page.goto(`http://localhost:5000/tests/visual/basic.html`)
17+
18+
// page.click('.color-picker')
19+
20+
// expect(1).toEqual(1)
21+
// })
22+
})

‎tests/setup.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const {toMatchImageSnapshot} = require('jest-image-snapshot')
2+
expect.extend({toMatchImageSnapshot})
3+
4+
global.URL_BASE = 'http://localhost:5000/tests/visual'

‎tests/utils.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports.loadVisualTest = async name => {
2+
// Load page
3+
await page.goto(`http://localhost:5000/tests/visual/${name}`, {
4+
waitUntil: 'load' // networkidle doesn't work on firefox, it get's stuck
5+
})
6+
7+
// Wait until the next frame
8+
await page.evaluate(() => new Promise(requestAnimationFrame))
9+
}

‎tests/visual/basic.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<meta charset="utf-8">
2+
<script src="/dist/color-picker.min.js"></script>
3+
<link rel="stylesheet" href="/dist/styles.css">
4+
<script type="module">
5+
const cPicker = new ColorPicker({
6+
color: 'red', // accepts formats: HEX(A), RGB(A), HSL(A)
7+
className: 'fooClass',
8+
onClickOutside(e){
9+
window.onClickOutside(e.target)
10+
},
11+
onInput(color){
12+
window.onInput(color)
13+
},
14+
onChange(color){
15+
window.onChange(color)
16+
}
17+
})
18+
19+
document.body.appendChild(cPicker.DOM.scope)
20+
</script>

‎tests/visual/swatches.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<meta charset="utf-8">
2+
<script src="/dist/color-picker.min.js"></script>
3+
<link rel="stylesheet" href="/dist/styles.css">
4+
<script type="module">
5+
const cPicker = new ColorPicker({
6+
swatches: ['red', '#FF0000', '#0000FF', 'RGBA(0,128,0,1, .5)', 'HSLA(349.5, 100%, 87.6%, 100%)']
7+
})
8+
9+
document.body.appendChild(cPicker.DOM.scope)
10+
</script>

0 commit comments

Comments
 (0)
Please sign in to comment.