Skip to content

Commit 7a02793

Browse files
committed
playwright tests.
1 parent 5b81863 commit 7a02793

File tree

8 files changed

+183
-22
lines changed

8 files changed

+183
-22
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
*.swp
2+
node_modules/
3+
/test-results/
4+
/playwright-report/
5+
/playwright/.cache/

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# scrollparent.js
22

3+
[![NPM version][npm-image]][npm-url]
4+
[![Size][size-image]][size-url]
5+
[![Download count][downloads-image]][downloads-url]
6+
37
> A function to get the scrolling parent of an html element.
48
59
## Install
@@ -45,3 +49,10 @@ you should use a `document.scrollingElement` polyfill such as
4549
## License
4650

4751
MIT
52+
53+
[npm-image]: https://img.shields.io/npm/v/scrollparent.svg?style=flat-square
54+
[npm-url]: https://npmjs.org/package/scrollparent
55+
[downloads-image]: http://img.shields.io/npm/dm/scrollparent.js.svg?style=flat-square
56+
[downloads-url]: https://npmjs.org/package/scrollparent.js
57+
[size-image]: https://badge-size.herokuapp.com/olahol/scrollparent.js/master/scrollparent.js?style=flat-square
58+
[size-url]: https://github.com/olahol/scrollparent.js/blob/master/react-tagsinput.js

package-lock.json

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@
1818
"bugs": {
1919
"url": "https://github.com/olahol/scrollparent.js/issues"
2020
},
21-
"homepage": "https://github.com/olahol/scrollparent.js#readme"
21+
"homepage": "https://github.com/olahol/scrollparent.js#readme",
22+
"devDependencies": {
23+
"@playwright/test": "^1.27.1"
24+
},
25+
"scripts": {
26+
"test": "playwright test"
27+
},
28+
"files": []
2229
}

playwright.config.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const { devices } = require('@playwright/test');
2+
3+
const config = {
4+
testDir: './test',
5+
timeout: 30 * 1000,
6+
expect: {
7+
timeout: 5000
8+
},
9+
workers: 1,
10+
reporter: 'html',
11+
projects: [
12+
{
13+
name: 'chromium',
14+
use: {
15+
...devices['Desktop Chrome'],
16+
},
17+
},
18+
19+
{
20+
name: 'firefox',
21+
use: {
22+
...devices['Desktop Firefox'],
23+
},
24+
},
25+
26+
{
27+
name: 'webkit',
28+
use: {
29+
...devices['Desktop Safari'],
30+
},
31+
},
32+
33+
{
34+
name: 'mobile_chrome',
35+
use: {
36+
...devices['Pixel 5'],
37+
},
38+
},
39+
40+
{
41+
name: 'mobile_safari',
42+
use: {
43+
...devices['iPhone 12'],
44+
},
45+
},
46+
],
47+
};
48+
49+
module.exports = config;

scrollparent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
};
2525

2626
var scroll = function (node) {
27-
return regex.test(overflow(node));
27+
return regex.test(overflow(node));
2828
};
2929

3030
var scrollParent = function (node) {

test/scrollparent.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { resolve } = require('path');
2+
const { test, expect } = require('@playwright/test');
3+
4+
test('test scrollparent behaviour', async ({ page }) => {
5+
const testFile = resolve(__dirname, 'test.html');
6+
7+
page.on('console', msg => console.log(msg.text()));
8+
9+
await page.goto(`file://${testFile}`);
10+
11+
await expect(page).toHaveTitle('scrollparent.js test page');
12+
13+
await page.evaluate(() => {
14+
var top = document.scrollingElement || document.documentElement;
15+
16+
function equal(a, b, msg) {
17+
if (a !== b) {
18+
throw new Error(msg || "Page Error");
19+
}
20+
}
21+
22+
function byId(id) {
23+
return document.getElementById(id);
24+
}
25+
26+
equal(Scrollparent(byId("test1")).className, "scroll");
27+
28+
equal(Scrollparent(byId("test2")), top);
29+
equal(Scrollparent(byId("test3")), top);
30+
31+
equal(Scrollparent(byId("test4")).className, "scroll-y");
32+
equal(Scrollparent(byId("test5")).className, "scroll-x");
33+
});
34+
});

test.html renamed to test/test.html

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33

44
<head>
5-
<title></title>
5+
<title>scrollparent.js test page</title>
66
<meta charset="utf-8">
77
<style>
88
.scroll {
@@ -114,24 +114,6 @@
114114
</div>
115115
</div>
116116

117-
<script src="scrollparent.js"></script>
118-
<script>
119-
var equal = function (a, b) {
120-
console.log((a === b ? "ok" : "not ok") + " " + (++ assertion));
121-
}
122-
123-
var assertion = 0;
124-
125-
console.log("TAP version 13");
126-
console.log("1..5");
127-
128-
equal(Scrollparent(document.getElementById("test1")).className, "scroll");
129-
130-
equal(Scrollparent(document.getElementById("test2")), document.scrollingElement || document.documentElement);
131-
equal(Scrollparent(document.getElementById("test3")), document.scrollingElement || document.documentElement);
132-
133-
equal(Scrollparent(document.getElementById("test4")).className, "scroll-y");
134-
equal(Scrollparent(document.getElementById("test5")).className, "scroll-x");
135-
</script>
117+
<script src="../scrollparent.js"></script>
136118
</body>
137119
</html>

0 commit comments

Comments
 (0)