Skip to content

Commit 20e669e

Browse files
committed
Setup tests with Playwright
1 parent 2e983b0 commit 20e669e

File tree

8 files changed

+157
-5
lines changed

8 files changed

+157
-5
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
node_modules
22
dist
3+
/test-results/
4+
/playwright-report/
5+
/playwright/.cache/
6+
tests/GeneratorScript.js

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
node_modules
22
src
33
tests
4+
/test-results/
5+
/playwright-report/
6+
/playwright/.cache/
47
.gitignore
58
tsconfig.json

package-lock.json

Lines changed: 87 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"types": "dist/index.d.ts",
77
"type": "module",
88
"scripts": {
9-
"build": "tsc"
9+
"build": "tsc",
10+
"test": "npm run build && node tests/build.js && npx playwright test"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -27,5 +28,8 @@
2728
"bugs": {
2829
"url": "https://github.com/CSS-Canvas/CSS-to-HTML/issues"
2930
},
30-
"homepage": "https://github.com/CSS-Canvas/CSS-to-HTML#readme"
31+
"homepage": "https://github.com/CSS-Canvas/CSS-to-HTML#readme",
32+
"devDependencies": {
33+
"@playwright/test": "^1.35.1"
34+
}
3135
}

playwright.config.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration.
5+
*/
6+
export default defineConfig({
7+
testDir: './tests',
8+
/* Run tests in files in parallel */
9+
fullyParallel: true,
10+
/* Fail the build on CI if you accidentally left test.only in the source code. */
11+
forbidOnly: !!process.env.CI,
12+
/* Retry on CI only */
13+
retries: process.env.CI ? 2 : 0,
14+
/* Opt out of parallel tests on CI. */
15+
workers: process.env.CI ? 1 : undefined,
16+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
17+
reporter: 'html',
18+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
19+
use: {
20+
trace: 'on-first-retry',
21+
},
22+
23+
/* Configure projects for major browsers */
24+
projects: [
25+
{
26+
name: 'chromium',
27+
use: { ...devices['Desktop Chrome'] },
28+
},
29+
30+
{
31+
name: 'firefox',
32+
use: { ...devices['Desktop Firefox'] },
33+
},
34+
35+
{
36+
name: 'webkit',
37+
use: { ...devices['Desktop Safari'] },
38+
},
39+
],
40+
});

tests/build.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import fs from 'fs';
2+
3+
const file = fs.readFileSync('dist/Generator.js', { encoding: 'utf-8' });
4+
5+
let script = file;
6+
script = script.replace('export ', '');
7+
script = script.replace(/\/\/# sourceMappingURL=[a-z\.]+/i, '');
8+
9+
fs.writeFileSync('tests/GeneratorScript.js', script, { encoding: 'utf-8' });
10+
11+
console.log('Done.');

tests/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Document</title>
8-
<script src="index.js" type="module" defer></script>
8+
<script src="GeneratorScript.js" type="module" defer></script>
99
</head>
1010
<body style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;">
1111
<p>Press <kbd>F12</kbd> to open the console.</p>

tests/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ button {
5050
content: 'Double-click me';
5151
background-color: blue;
5252
}
53-
span:nth-child(4) {}
53+
span:nth-child(4),
5454
span.first:first-child {}
5555
span:nth-of-type(3) {
5656
content: '3rd span';
5757
}
58+
p.comma,
59+
.comma {
60+
content: ',';
61+
}
5862
`;
5963

6064
const output = cssToHtml(input);

0 commit comments

Comments
 (0)