@blockquote/create-wc 1.110.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -92
- package/package.json +2 -2
- package/src/app/gatherMixins.js +2 -8
- package/src/common-linting/templates/package.json +5 -5
- package/src/common-repo/templates/package.json +12 -4
- package/src/common-repo/templates/static/vite.config.js +37 -1
- package/src/testing/index.js +1 -2
- package/src/testing/templates/my-el.test.js +56 -23
- package/src/testing-ts/index.js +1 -2
- package/src/testing-ts/templates/my-el.test.ts +56 -24
- package/src/wc-lit-element-ts/index.js +4 -0
- package/src/wc-lit-element-ts/templates/package.json +11 -10
- package/src/wc-lit-element-ts/templates/tsconfig.json +20 -20
- package/src/wc-lit-element-ts/templates/vite.lib.config.js +26 -0
- package/src/common-testing-wtr/index.js +0 -14
- package/src/common-testing-wtr/templates/static/web-test-runner.config.js +0 -66
- package/src/testing-wtr/index.js +0 -19
- package/src/testing-wtr/templates/package.json +0 -6
- package/src/testing-wtr-ts/index.js +0 -19
- package/src/testing-wtr-ts/templates/package.json +0 -6
package/README.md
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
# Web
|
|
1
|
+
# Web Components with Lit - Scaffold
|
|
2
2
|
|
|
3
|
-
This scaffold generator extends and customizes
|
|
3
|
+
This scaffold generator extends and customizes **[@open-wc/create](https://open-wc.org/docs/development/generator/#extending)**, providing a starting point for creating web components with **[Lit](https://lit.dev/)**.
|
|
4
4
|
|
|
5
|
-
## Development
|
|
5
|
+
## Development Tools
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### Scaffold
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- Format `prettier`
|
|
12
|
-
- Test `web-test-runner`
|
|
9
|
+
- Lint: `eslint`
|
|
10
|
+
- Format: `prettier`
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
### Vite & Vitest
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- TypeScript & [tsconfig](https://github.com/lit/lit/blob/main/packages/lit-starter-ts/tsconfig.json)
|
|
14
|
+
- **Server**: [Vite Server](https://vitejs.dev/config/server-options.html)
|
|
15
|
+
- **Preview**: [Vite Preview](https://vitejs.dev/config/preview-options.html)
|
|
16
|
+
- **Build**: [Vite Build](https://vitejs.dev/guide/build.html)
|
|
20
17
|
|
|
21
|
-
-
|
|
18
|
+
- TypeScript: [`vite` transpile only](https://vite.dev/guide/features.html#typescript)
|
|
19
|
+
- TypeScript: [`tsc` emit declarations only](https://www.typescriptlang.org/tsconfig/#emitDeclarationOnly)
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
- **Test**: [Vitest browser mode](https://vitest.dev/guide/browser/)
|
|
22
|
+
|
|
23
|
+
- ### Sass
|
|
24
|
+
|
|
25
|
+
- SCSS [watcher](https://github.com/oscarmarina/sass-style-template) with [sass](https://www.npmjs.com/package/sass)
|
|
24
26
|
|
|
25
27
|
- ### analyze
|
|
26
28
|
- [Custom Elements Manifest](https://custom-elements-manifest.open-wc.org/blog/intro/)
|
|
@@ -31,7 +33,7 @@ This scaffold generator extends and customizes the core parts of **[@open-wc/cre
|
|
|
31
33
|
## Installation
|
|
32
34
|
|
|
33
35
|
```bash
|
|
34
|
-
npm init @blockquote/wc
|
|
36
|
+
npm init @blockquote/wc
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
### Start
|
|
@@ -42,103 +44,48 @@ npm start
|
|
|
42
44
|
|
|
43
45
|
<hr>
|
|
44
46
|
|
|
45
|
-
### Linting and
|
|
47
|
+
### Linting and Formatting
|
|
46
48
|
|
|
47
|
-
To scan the project for linting and formatting errors, run
|
|
49
|
+
To scan the project for linting and formatting errors, run:
|
|
48
50
|
|
|
49
51
|
```bash
|
|
50
52
|
npm run lint
|
|
51
53
|
```
|
|
52
54
|
|
|
53
|
-
To automatically fix
|
|
55
|
+
To automatically fix them, run:
|
|
54
56
|
|
|
55
57
|
```bash
|
|
56
58
|
npm run format
|
|
57
59
|
```
|
|
58
60
|
|
|
59
|
-
### Testing
|
|
60
|
-
|
|
61
|
-
- playwright
|
|
62
|
-
- coverage
|
|
63
|
-
- TDD option
|
|
64
|
-
|
|
65
|
-
<br>
|
|
66
|
-
|
|
67
|
-
### web-test-runner.config
|
|
68
|
-
|
|
69
|
-
```js
|
|
70
|
-
import {playwrightLauncher} from '@web/test-runner-playwright';
|
|
71
|
-
import {defaultReporter, summaryReporter} from '@web/test-runner';
|
|
72
|
-
import {coverageTableReporter} from '@blockquote/coverage-table-reporter';
|
|
73
|
-
|
|
74
|
-
const filteredLogs = ['in dev mode'];
|
|
75
|
-
const outDir = process.env.OUTDIR || '.';
|
|
76
|
-
|
|
77
|
-
export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
|
|
78
|
-
files: [`${outDir}/test/**/*.test.js`],
|
|
79
|
-
nodeResolve: true,
|
|
80
|
-
browsers: [playwrightLauncher({product: 'chromium'}), playwrightLauncher({product: 'webkit'})],
|
|
81
|
-
concurrentBrowsers: 2,
|
|
82
|
-
concurrency: 1,
|
|
83
|
-
reporters: [summaryReporter({}), defaultReporter(), coverageTableReporter()],
|
|
84
|
-
preserveSymlinks: true,
|
|
85
|
-
coverage: true,
|
|
86
|
-
coverageConfig: {
|
|
87
|
-
reportDir: `${outDir}/test/coverage`,
|
|
88
|
-
reporters: ['lcov', 'lcovonly', 'json'],
|
|
89
|
-
threshold: {
|
|
90
|
-
statements: 80,
|
|
91
|
-
branches: 80,
|
|
92
|
-
functions: 80,
|
|
93
|
-
lines: 80,
|
|
94
|
-
},
|
|
95
|
-
include: ['**/src/**/*', '**/define/**/*'],
|
|
96
|
-
},
|
|
97
|
-
testFramework: {
|
|
98
|
-
config: {
|
|
99
|
-
ui: 'tdd',
|
|
100
|
-
timeout: 4000,
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
filterBrowserLogs(log) {
|
|
104
|
-
for (const arg of log.args) {
|
|
105
|
-
if (typeof arg === 'string' && filteredLogs.some((l) => arg.includes(l))) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return true;
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
```
|
|
61
|
+
### Testing
|
|
113
62
|
|
|
114
|
-
|
|
63
|
+
Run tests with:
|
|
115
64
|
|
|
116
65
|
```bash
|
|
117
66
|
npm run test
|
|
118
67
|
```
|
|
119
68
|
|
|
120
|
-
To run the tests in interactive watch mode run:
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
npm run test:watch
|
|
124
|
-
```
|
|
125
|
-
|
|
126
69
|
<hr>
|
|
127
70
|
|
|
128
|
-
###
|
|
71
|
+
### Development Server
|
|
129
72
|
|
|
130
|
-
|
|
73
|
+
Start the development server:
|
|
131
74
|
|
|
132
75
|
```bash
|
|
133
|
-
npm run
|
|
76
|
+
npm run start
|
|
134
77
|
```
|
|
135
78
|
|
|
136
|
-
###
|
|
79
|
+
### Hosting a Static Demo (Do Not Bundle)
|
|
80
|
+
|
|
81
|
+
For hosting a static demo without bundling:
|
|
137
82
|
|
|
138
83
|
```bash
|
|
139
84
|
npm run dev:vite
|
|
140
85
|
```
|
|
141
86
|
|
|
87
|
+
Preview demo:
|
|
88
|
+
|
|
142
89
|
```bash
|
|
143
90
|
npm run preview:vite
|
|
144
91
|
```
|
|
@@ -153,9 +100,11 @@ npm run build
|
|
|
153
100
|
|
|
154
101
|
<hr>
|
|
155
102
|
|
|
156
|
-
###
|
|
103
|
+
### Sass
|
|
157
104
|
|
|
158
|
-
####
|
|
105
|
+
#### SCSS Watcher
|
|
106
|
+
|
|
107
|
+
Start the SCSS watcher:
|
|
159
108
|
|
|
160
109
|
```bash
|
|
161
110
|
npm run sass:watch
|
|
@@ -163,9 +112,11 @@ npm run sass:watch
|
|
|
163
112
|
|
|
164
113
|
<hr>
|
|
165
114
|
|
|
166
|
-
### Custom
|
|
115
|
+
### Custom Elements Manifest
|
|
116
|
+
|
|
117
|
+
#### Generating README from `custom-elements.json`
|
|
167
118
|
|
|
168
|
-
|
|
119
|
+
Generate documentation:
|
|
169
120
|
|
|
170
121
|
```bash
|
|
171
122
|
npm run analyze
|
|
@@ -175,12 +126,16 @@ npm run analyze
|
|
|
175
126
|
|
|
176
127
|
Husky is pre-installed.
|
|
177
128
|
|
|
178
|
-
After `git init
|
|
129
|
+
After initializing Git with `git init`, run:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm run prepare
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
to set up Husky and its Git hooks.
|
|
179
136
|
|
|
180
137
|
<hr>
|
|
181
138
|
|
|
182
139
|
**Example:**
|
|
183
140
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
<hr>
|
|
141
|
+
- [lit-vitest-testing-comparison](https://github.com/oscarmarina/lit-vitest-testing-comparison)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockquote/create-wc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Web component with Lit scaffolding - Extending Open Web Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lit",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@open-wc/create": "^0.38.151",
|
|
54
|
-
"chalk": "^5.
|
|
54
|
+
"chalk": "^5.4.0",
|
|
55
55
|
"command-line-args": "^6.0.1",
|
|
56
56
|
"prompts": "^2.4.2",
|
|
57
57
|
"semver": "^7.6.3"
|
package/src/app/gatherMixins.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
// js
|
|
2
2
|
import {CommonLintingMixin} from '../common-linting/index.js';
|
|
3
|
-
import {CommonTestingWtrMixin} from '../common-testing-wtr/index.js';
|
|
4
|
-
|
|
5
3
|
import {WcLitElementPackageMixin} from '../wc-lit-element/index.js';
|
|
6
|
-
import {TestingMixin
|
|
4
|
+
import {TestingScaffoldMixin /* TestingMixin */} from '../testing/index.js';
|
|
7
5
|
|
|
8
6
|
// ts
|
|
9
7
|
import {TsWcLitElementPackageMixin} from '../wc-lit-element-ts/index.js';
|
|
10
|
-
import {TsTestingMixin
|
|
8
|
+
import {TsTestingScaffoldMixin /* TsTestingMixin */} from '../testing-ts/index.js';
|
|
11
9
|
|
|
12
10
|
export function gatherMixins(options) {
|
|
13
11
|
const mixins = [];
|
|
14
12
|
if (options.typescript === 'true') {
|
|
15
13
|
mixins.push(CommonLintingMixin);
|
|
16
|
-
mixins.push(CommonTestingWtrMixin);
|
|
17
|
-
mixins.push(TsTestingMixin);
|
|
18
14
|
mixins.push(TsTestingScaffoldMixin);
|
|
19
15
|
mixins.push(TsWcLitElementPackageMixin);
|
|
20
16
|
} else {
|
|
21
17
|
mixins.push(CommonLintingMixin);
|
|
22
|
-
mixins.push(CommonTestingWtrMixin);
|
|
23
|
-
mixins.push(TestingMixin);
|
|
24
18
|
mixins.push(TestingScaffoldMixin);
|
|
25
19
|
mixins.push(WcLitElementPackageMixin);
|
|
26
20
|
}
|
|
@@ -47,19 +47,19 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@html-eslint/eslint-plugin": "^0.31.1",
|
|
49
49
|
"@html-eslint/parser": "^0.31.0",
|
|
50
|
-
"eslint": "^9.
|
|
50
|
+
"eslint": "^9.17.0",
|
|
51
51
|
"eslint-config-prettier": "^9.1.0",
|
|
52
52
|
"eslint-plugin-import": "^2.31.0",
|
|
53
53
|
"eslint-plugin-lit": "^1.15.0",
|
|
54
54
|
"eslint-plugin-lit-a11y": "^4.1.4",
|
|
55
55
|
"eslint-plugin-wc": "^2.2.0",
|
|
56
|
-
"@typescript-eslint/parser": "^8.18.
|
|
57
|
-
"typescript-eslint": "^8.18.
|
|
58
|
-
"globals": "^15.
|
|
56
|
+
"@typescript-eslint/parser": "^8.18.1",
|
|
57
|
+
"typescript-eslint": "^8.18.1",
|
|
58
|
+
"globals": "^15.14.0",
|
|
59
59
|
"husky": "^9.1.7",
|
|
60
60
|
"lint-staged": "^15.2.11",
|
|
61
61
|
"prettier": "^3.4.2",
|
|
62
|
-
"stylelint": "^16.
|
|
62
|
+
"stylelint": "^16.12.0",
|
|
63
63
|
"stylelint-config-standard-scss": "^14.0.0"
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"analyze": "cem analyze --litelement --globs \"src/**/*.{js,ts}\" \"index.js\"",
|
|
20
20
|
"sort:package": "npx sort-package-json",
|
|
21
21
|
"postinstall": "npm run sort:package",
|
|
22
|
-
"prepare": "husky"
|
|
22
|
+
"prepare": "husky",
|
|
23
|
+
"test": "vitest"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"lit": "^3.2.1"
|
|
@@ -31,15 +32,22 @@
|
|
|
31
32
|
"@blockquote/rollup-plugin-total-bundlesize": "^2.1.2",
|
|
32
33
|
"@blockquote/sass-style-template": "^4.1.0",
|
|
33
34
|
"@custom-elements-manifest/analyzer": "^0.10.4",
|
|
35
|
+
"@open-wc/semantic-dom-diff": "^0.20.1",
|
|
34
36
|
"@open-wc/testing": "^4.0.0",
|
|
37
|
+
"playwright": "^1.49.1",
|
|
35
38
|
"@types/mocha": "^10.0.10",
|
|
36
|
-
"@web/test-runner": "^0.19.0",
|
|
37
|
-
"@web/test-runner-playwright": "^0.11.0",
|
|
38
39
|
"@rollup/plugin-multi-entry": "^6.0.1",
|
|
39
40
|
"rollup-plugin-copy": "^3.5.0",
|
|
41
|
+
"rollup-plugin-node-externals": "^8.0.0",
|
|
42
|
+
"tinyglobby": "^0.2.10",
|
|
40
43
|
"concurrently": "^9.1.0",
|
|
41
44
|
"sort-package-json": "^2.12.0",
|
|
42
|
-
"
|
|
45
|
+
"@vitest/browser": "^3.0.0-beta.2",
|
|
46
|
+
"@vitest/coverage-istanbul": "^3.0.0-beta.2",
|
|
47
|
+
"@vitest/coverage-v8": "^3.0.0-beta.2",
|
|
48
|
+
"@vitest/ui": "^3.0.0-beta.2",
|
|
49
|
+
"vitest": "^3.0.0-beta.2",
|
|
50
|
+
"vite": "^6.0.4"
|
|
43
51
|
},
|
|
44
52
|
"publishConfig": {
|
|
45
53
|
"access": "public"
|
|
@@ -14,9 +14,45 @@ const copyConfig = {
|
|
|
14
14
|
hook: 'writeBundle',
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// https://vitejs.dev/config/
|
|
18
|
+
// https://vite-rollup-plugins.patak.dev/
|
|
18
19
|
|
|
19
20
|
export default defineConfig({
|
|
21
|
+
test: {
|
|
22
|
+
onConsoleLog(log, type) {
|
|
23
|
+
if (log.includes('in dev mode')) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
include: ['test/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
|
|
28
|
+
browser: {
|
|
29
|
+
enabled: true,
|
|
30
|
+
headless: false,
|
|
31
|
+
name: 'chromium',
|
|
32
|
+
provider: 'playwright',
|
|
33
|
+
screnshotfailures: false,
|
|
34
|
+
viewport: {width: 1920, height: 1080},
|
|
35
|
+
providerOptions: {
|
|
36
|
+
launch: {
|
|
37
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu'],
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
coverage: {
|
|
42
|
+
provider: 'v8',
|
|
43
|
+
reportsDirectory: './test/coverage/',
|
|
44
|
+
reporter: ['lcov', 'json', 'text-summary', 'html'],
|
|
45
|
+
enabled: true,
|
|
46
|
+
thresholds: {
|
|
47
|
+
statements: 80,
|
|
48
|
+
branches: 80,
|
|
49
|
+
functions: 80,
|
|
50
|
+
lines: 80,
|
|
51
|
+
},
|
|
52
|
+
include: ['**/src/**/*'],
|
|
53
|
+
exclude: ['**/src/**/index.*', '**/src/styles/'],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
20
56
|
plugins: [
|
|
21
57
|
externalizeSourceDependencies(['/__web-dev-server__web-socket.js']),
|
|
22
58
|
copy(copyConfig),
|
package/src/testing/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/* eslint-disable max-classes-per-file */
|
|
2
2
|
import {fileURLToPath} from 'url';
|
|
3
3
|
import {dirname} from 'path';
|
|
4
|
-
import {TestingWebTestRunnerMixin} from '../testing-wtr/index.js';
|
|
5
4
|
|
|
6
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
6
|
const __dirname = dirname(__filename);
|
|
8
7
|
|
|
9
8
|
export const TestingMixin = (subclass) =>
|
|
10
|
-
class extends
|
|
9
|
+
class extends subclass {
|
|
11
10
|
async execute() {
|
|
12
11
|
await super.execute();
|
|
13
12
|
this.copyTemplateJsonInto(
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {beforeAll, afterAll, beforeEach, afterEach, suite, assert, expect, vi, test} from 'vitest';
|
|
2
|
+
import {page, userEvent} from '@vitest/browser/context';
|
|
3
|
+
import {html} from 'lit';
|
|
4
|
+
import {getDiffableHTML} from '@open-wc/semantic-dom-diff';
|
|
5
|
+
import {assert as a11y, fixture, fixtureCleanup} from '@open-wc/testing';
|
|
2
6
|
import '../src/define/<%= tagName %>.js';
|
|
3
7
|
|
|
4
8
|
suite('<%= className %>', () => {
|
|
@@ -6,48 +10,77 @@ suite('<%= className %>', () => {
|
|
|
6
10
|
* @type {import('../src/index').<%= className %>}
|
|
7
11
|
*/
|
|
8
12
|
let el;
|
|
13
|
+
let elShadowRoot;
|
|
14
|
+
let elLocator;
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
suite('Default', () => {
|
|
13
|
-
setup(async () => {
|
|
16
|
+
suite('Semantic Dom and a11y', () => {
|
|
17
|
+
beforeAll(async () => {
|
|
14
18
|
el = await fixture(html`<<%= tagName %>>light-dom</<%= tagName %>>`);
|
|
19
|
+
elShadowRoot = el?.shadowRoot?.innerHTML;
|
|
20
|
+
elLocator = page.elementLocator(el);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterAll(() => {
|
|
24
|
+
fixtureCleanup();
|
|
15
25
|
});
|
|
16
26
|
|
|
17
|
-
test('has a default heading "Hey there" and counter 5', () => {
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
test('has a default heading "Hey there" and counter 5', async () => {
|
|
28
|
+
const button = await elLocator.getByText('Counter: 5').query();
|
|
29
|
+
const heading = await elLocator.getByText('Hey there').query();
|
|
30
|
+
assert.isOk(button);
|
|
31
|
+
assert.isOk(heading);
|
|
20
32
|
});
|
|
21
33
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
34
|
+
test('SHADOW DOM - Structure test', () => {
|
|
35
|
+
expect(getDiffableHTML(elShadowRoot)).toMatchSnapshot('SHADOW DOM');
|
|
36
|
+
});
|
|
26
37
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
test('LIGHT DOM - Structure test', () => {
|
|
39
|
+
expect(getDiffableHTML(el, {ignoreAttributes: ['id']})).toMatchSnapshot('LIGHT DOM');
|
|
40
|
+
});
|
|
30
41
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
42
|
+
test('a11y', async () => {
|
|
43
|
+
await a11y.isAccessible(el);
|
|
34
44
|
});
|
|
35
45
|
});
|
|
36
46
|
|
|
37
47
|
suite('Events ', () => {
|
|
38
|
-
|
|
48
|
+
beforeEach(async () => {
|
|
39
49
|
el = await fixture(html`<<%= tagName %>></<%= tagName %>>`);
|
|
50
|
+
elLocator = page.elementLocator(el);
|
|
40
51
|
});
|
|
41
52
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
fixtureCleanup();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('should increment value on click', async () => {
|
|
58
|
+
const button = elLocator.getByText('Counter: 5');
|
|
59
|
+
const elButton = button.query();
|
|
60
|
+
await button.dblClick();
|
|
61
|
+
await el.updateComplete;
|
|
62
|
+
assert.include(elButton.textContent, 'Counter: 7');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('counterchange event is dispatched', async () => {
|
|
66
|
+
const spyEvent = vi.spyOn(el, 'dispatchEvent');
|
|
67
|
+
const button = elLocator.getByText('Counter: 5');
|
|
68
|
+
const elButton = button.query();
|
|
69
|
+
await userEvent.click(elButton);
|
|
70
|
+
await el.updateComplete;
|
|
71
|
+
const calledWithCounterChange = spyEvent.mock.lastCall?.[0].type === 'counterchange';
|
|
72
|
+
assert.isTrue(calledWithCounterChange);
|
|
45
73
|
});
|
|
46
74
|
});
|
|
47
75
|
|
|
48
76
|
suite('Override ', () => {
|
|
49
|
-
|
|
77
|
+
beforeEach(async () => {
|
|
50
78
|
el = await fixture(html`<<%= tagName %> heading="attribute heading"></<%= tagName %>>`);
|
|
79
|
+
elLocator = page.elementLocator(el);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
fixtureCleanup();
|
|
51
84
|
});
|
|
52
85
|
|
|
53
86
|
test('can override the heading via attribute', () => {
|
package/src/testing-ts/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/* eslint-disable max-classes-per-file */
|
|
2
2
|
import {fileURLToPath} from 'url';
|
|
3
3
|
import {dirname} from 'path';
|
|
4
|
-
import {TsTestingWebTestRunnerMixin} from '../testing-wtr-ts/index.js';
|
|
5
4
|
|
|
6
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
6
|
const __dirname = dirname(__filename);
|
|
8
7
|
|
|
9
8
|
export const TsTestingMixin = (subclass) =>
|
|
10
|
-
class extends
|
|
9
|
+
class extends subclass {
|
|
11
10
|
async execute() {
|
|
12
11
|
await super.execute();
|
|
13
12
|
|
|
@@ -1,52 +1,84 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {beforeAll, afterAll, beforeEach, afterEach, suite, assert, expect, vi, test} from 'vitest';
|
|
2
|
+
import {page, userEvent, type Locator} from '@vitest/browser/context';
|
|
3
|
+
import {html} from 'lit';
|
|
4
|
+
import {getDiffableHTML} from '@open-wc/semantic-dom-diff';
|
|
5
|
+
import {assert as a11y, fixture, fixtureCleanup} from '@open-wc/testing';
|
|
2
6
|
import {<%= className %>} from '../src/<%= className %>.js';
|
|
3
7
|
import '../src/define/<%= tagName %>.js';
|
|
4
8
|
|
|
5
9
|
suite('<%= className %>', () => {
|
|
6
10
|
let el: <%= className %>;
|
|
11
|
+
let elShadowRoot: string;
|
|
12
|
+
let elLocator: Locator;
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
suite('Default', () => {
|
|
11
|
-
setup(async () => {
|
|
14
|
+
suite('Semantic Dom and a11y', () => {
|
|
15
|
+
beforeAll(async () => {
|
|
12
16
|
el = await fixture(html`<<%= tagName %>>light-dom</<%= tagName %>>`);
|
|
17
|
+
elShadowRoot = el?.shadowRoot!.innerHTML;
|
|
18
|
+
elLocator = page.elementLocator(el);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterAll(() => {
|
|
22
|
+
fixtureCleanup();
|
|
13
23
|
});
|
|
14
24
|
|
|
15
|
-
test('has a default heading "Hey there" and counter 5', () => {
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
test('has a default heading "Hey there" and counter 5', async () => {
|
|
26
|
+
const button = await elLocator.getByText('Counter: 5').query();
|
|
27
|
+
const heading = await elLocator.getByText('Hey there').query();
|
|
28
|
+
assert.isOk(button);
|
|
29
|
+
assert.isOk(heading);
|
|
18
30
|
});
|
|
19
31
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
32
|
+
test('SHADOW DOM - Structure test', () => {
|
|
33
|
+
expect(getDiffableHTML(elShadowRoot)).toMatchSnapshot('SHADOW DOM');
|
|
34
|
+
});
|
|
24
35
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
test('LIGHT DOM - Structure test', () => {
|
|
37
|
+
expect(getDiffableHTML(el, {ignoreAttributes: ['id']})).toMatchSnapshot('LIGHT DOM');
|
|
38
|
+
});
|
|
28
39
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
40
|
+
test('a11y', async () => {
|
|
41
|
+
await a11y.isAccessible(el);
|
|
32
42
|
});
|
|
33
43
|
});
|
|
34
44
|
|
|
35
45
|
suite('Events ', () => {
|
|
36
|
-
|
|
46
|
+
beforeEach(async () => {
|
|
37
47
|
el = await fixture(html`<<%= tagName %>></<%= tagName %>>`);
|
|
48
|
+
elLocator = page.elementLocator(el);
|
|
38
49
|
});
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
fixtureCleanup();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('should increment value on click', async () => {
|
|
56
|
+
const button = elLocator.getByText('Counter: 5');
|
|
57
|
+
const elButton = button.query()!;
|
|
58
|
+
await button.dblClick();
|
|
59
|
+
await el.updateComplete;
|
|
60
|
+
assert.include(elButton.textContent, 'Counter: 7');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('counterchange event is dispatched', async () => {
|
|
64
|
+
const spyEvent = vi.spyOn(el, 'dispatchEvent');
|
|
65
|
+
const button = elLocator.getByText('Counter: 5');
|
|
66
|
+
const elButton = button.query()!;
|
|
67
|
+
await userEvent.click(elButton);
|
|
68
|
+
await el.updateComplete;
|
|
69
|
+
const calledWithCounterChange = spyEvent.mock.lastCall?.[0].type === 'counterchange';
|
|
70
|
+
assert.isTrue(calledWithCounterChange);
|
|
44
71
|
});
|
|
45
72
|
});
|
|
46
73
|
|
|
47
74
|
suite('Override ', () => {
|
|
48
|
-
|
|
75
|
+
beforeEach(async () => {
|
|
49
76
|
el = await fixture(html`<<%= tagName %> heading="attribute heading"></<%= tagName %>>`);
|
|
77
|
+
elLocator = page.elementLocator(el);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
fixtureCleanup();
|
|
50
82
|
});
|
|
51
83
|
|
|
52
84
|
test('can override the heading via attribute', () => {
|
|
@@ -79,6 +79,10 @@ export const TsWcLitElementPackageMixin = (subclass) =>
|
|
|
79
79
|
`${__dirname}/templates/tsconfig.json`,
|
|
80
80
|
this.destinationPath('tsconfig.json')
|
|
81
81
|
);
|
|
82
|
+
this.copyTemplate(
|
|
83
|
+
`${__dirname}/templates/vite.lib.config.js`,
|
|
84
|
+
this.destinationPath('vite.lib.config.js')
|
|
85
|
+
);
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
async end() {
|
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"exports": {
|
|
3
3
|
".": {
|
|
4
|
-
"default": "./dist/
|
|
4
|
+
"default": "./dist/index.js"
|
|
5
5
|
},
|
|
6
6
|
"./package.json": {
|
|
7
7
|
"default": "./package.json"
|
|
8
8
|
},
|
|
9
9
|
"./<%= className %>.js": {
|
|
10
|
-
"default": "./dist
|
|
10
|
+
"default": "./dist/<%= className %>.js"
|
|
11
11
|
},
|
|
12
12
|
"./<%= tagName %>.js": {
|
|
13
|
-
"default": "./dist/
|
|
13
|
+
"default": "./dist/define/<%= tagName %>.js"
|
|
14
14
|
},
|
|
15
15
|
"./index.js": {
|
|
16
|
-
"default": "./dist/
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
17
|
},
|
|
18
18
|
"./<%= tagName %>-styles.css.js": {
|
|
19
|
-
"default": "./dist/
|
|
19
|
+
"default": "./dist/styles/<%= tagName %>-styles.css.js"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
|
-
"main": "dist/
|
|
23
|
-
"module": "dist/
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"module": "dist/index.js",
|
|
24
24
|
"files": [
|
|
25
|
-
"/
|
|
26
|
-
"
|
|
25
|
+
"/src/",
|
|
26
|
+
"/dist/"
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
|
-
"build": "npm run build:
|
|
29
|
+
"build": "npm run dev:vite && npm run build:lib && npm run build:tsc",
|
|
30
|
+
"build:lib": "vite build --config vite.lib.config.js",
|
|
30
31
|
"build:tsc": "tsc",
|
|
31
32
|
"sass:watch": "sass-style-template -j ts"
|
|
32
33
|
},
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"incremental": true,
|
|
4
|
-
"composite": true,
|
|
5
|
-
"target": "ES2022",
|
|
6
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
-
"experimentalDecorators": true,
|
|
8
|
-
"module": "ES2022",
|
|
9
|
-
"moduleResolution": "Bundler",
|
|
10
|
-
"resolvePackageJsonExports": true,
|
|
11
|
-
"resolvePackageJsonImports": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
3
|
"allowArbitraryExtensions": true,
|
|
14
4
|
"declaration": true,
|
|
5
|
+
"declarationDir": "./dist/",
|
|
15
6
|
"declarationMap": true,
|
|
16
|
-
"
|
|
17
|
-
"outDir": "./dist",
|
|
18
|
-
"stripInternal": true,
|
|
19
|
-
"verbatimModuleSyntax": true,
|
|
7
|
+
"emitDeclarationOnly": true,
|
|
20
8
|
"esModuleInterop": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
21
10
|
"forceConsistentCasingInFileNames": true,
|
|
22
|
-
"
|
|
11
|
+
"lib": ["es2022", "DOM", "DOM.Iterable"],
|
|
12
|
+
"module": "es2022",
|
|
13
|
+
"moduleResolution": "Bundler",
|
|
14
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
15
|
"noImplicitAny": true,
|
|
16
|
+
"noImplicitOverride": true,
|
|
17
|
+
"noImplicitReturns": true,
|
|
24
18
|
"noImplicitThis": true,
|
|
25
19
|
"noUnusedLocals": true,
|
|
26
20
|
"noUnusedParameters": true,
|
|
27
|
-
"
|
|
21
|
+
"resolveJsonModule": true,
|
|
22
|
+
"resolvePackageJsonExports": true,
|
|
23
|
+
"resolvePackageJsonImports": true,
|
|
24
|
+
"rootDir": "./src/",
|
|
25
|
+
"sourceMap": true,
|
|
26
|
+
"strict": true,
|
|
27
|
+
"stripInternal": true,
|
|
28
|
+
"target": "es2022",
|
|
29
|
+
"types": ["mocha"],
|
|
28
30
|
"useDefineForClassFields": false,
|
|
29
|
-
"
|
|
30
|
-
"noImplicitOverride": true,
|
|
31
|
-
"types": ["mocha"]
|
|
31
|
+
"verbatimModuleSyntax": true
|
|
32
32
|
},
|
|
33
|
-
"include": ["src/**/*.ts"
|
|
33
|
+
"include": ["src/**/*.ts"]
|
|
34
34
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {defineConfig} from 'vite';
|
|
2
|
+
import {nodeExternals} from 'rollup-plugin-node-externals';
|
|
3
|
+
import {globSync} from 'tinyglobby';
|
|
4
|
+
|
|
5
|
+
const srcDir = 'src';
|
|
6
|
+
const srcGlob = `${srcDir}/**/*.ts`;
|
|
7
|
+
|
|
8
|
+
// https://github.com/vitejs/vite/discussions/1736#discussioncomment-5126923
|
|
9
|
+
const entries = Object.fromEntries(
|
|
10
|
+
globSync(srcGlob).map((file) => {
|
|
11
|
+
const [key] = file.match(new RegExp(`(?<=${srcDir}\/).*`)) || [];
|
|
12
|
+
return [key?.replace(/\.[^.]*$/, ''), file];
|
|
13
|
+
})
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
plugins: [nodeExternals()],
|
|
18
|
+
build: {
|
|
19
|
+
target: ['es2022'],
|
|
20
|
+
lib: {
|
|
21
|
+
entry: entries,
|
|
22
|
+
formats: ['es'],
|
|
23
|
+
},
|
|
24
|
+
minify: false,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import {fileURLToPath} from 'url';
|
|
3
|
-
import {dirname} from 'path';
|
|
4
|
-
|
|
5
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
-
const __dirname = dirname(__filename);
|
|
7
|
-
|
|
8
|
-
export const CommonTestingWtrMixin = (subclass) =>
|
|
9
|
-
class extends subclass {
|
|
10
|
-
async execute() {
|
|
11
|
-
await super.execute();
|
|
12
|
-
await this.copyTemplates(`${__dirname}/templates/static/**/*`);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
/* process.env.npm_lifecycle_event, process.env.npm_lifecycle_script, process.env.OUTDIR; */
|
|
3
|
-
import {playwrightLauncher} from '@web/test-runner-playwright';
|
|
4
|
-
import {defaultReporter, summaryReporter} from '@web/test-runner';
|
|
5
|
-
import {coverageTableReporter} from '@blockquote/coverage-table-reporter';
|
|
6
|
-
|
|
7
|
-
const filteredLogs = ['in dev mode'];
|
|
8
|
-
const outDir = process.env.OUTDIR || '.';
|
|
9
|
-
|
|
10
|
-
export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
|
|
11
|
-
/** Test files to run */
|
|
12
|
-
files: [`${outDir}/test/**/*.test.js`],
|
|
13
|
-
|
|
14
|
-
/** Resolve bare module imports */
|
|
15
|
-
nodeResolve: true,
|
|
16
|
-
|
|
17
|
-
/** Browsers to run tests on */
|
|
18
|
-
browsers: [playwrightLauncher({product: 'chromium'}), playwrightLauncher({product: 'webkit'})],
|
|
19
|
-
|
|
20
|
-
/** Amount of browsers to run concurrently */
|
|
21
|
-
concurrentBrowsers: 2,
|
|
22
|
-
|
|
23
|
-
/** Amount of test files per browser to test concurrently */
|
|
24
|
-
concurrency: 1,
|
|
25
|
-
|
|
26
|
-
reporters: [summaryReporter({}), defaultReporter(), coverageTableReporter()],
|
|
27
|
-
|
|
28
|
-
preserveSymlinks: true,
|
|
29
|
-
|
|
30
|
-
coverage: true,
|
|
31
|
-
coverageConfig: {
|
|
32
|
-
// https://github.com/istanbuljs/v8-to-istanbul#ignoring-uncovered-lines
|
|
33
|
-
reportDir: `${outDir}/test/coverage`,
|
|
34
|
-
reporters: ['lcov', 'lcovonly', 'json'],
|
|
35
|
-
threshold: {
|
|
36
|
-
statements: 80,
|
|
37
|
-
branches: 80,
|
|
38
|
-
functions: 80,
|
|
39
|
-
lines: 80,
|
|
40
|
-
},
|
|
41
|
-
include: ['**/src/**/*'],
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
testFramework: {
|
|
45
|
-
// https://mochajs.org/api/mocha
|
|
46
|
-
config: {
|
|
47
|
-
ui: 'tdd',
|
|
48
|
-
timeout: 4000,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
/** Filter out lit dev mode logs */
|
|
53
|
-
filterBrowserLogs(log) {
|
|
54
|
-
for (const arg of log.args) {
|
|
55
|
-
if (typeof arg === 'string' && filteredLogs.some((l) => arg.includes(l))) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
|
|
63
|
-
// esbuildTarget: 'auto',
|
|
64
|
-
|
|
65
|
-
// See documentation for all available options
|
|
66
|
-
});
|
package/src/testing-wtr/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {fileURLToPath} from 'url';
|
|
2
|
-
import {dirname} from 'path';
|
|
3
|
-
|
|
4
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
-
const __dirname = dirname(__filename);
|
|
6
|
-
|
|
7
|
-
export const TestingWebTestRunnerMixin = (subclass) =>
|
|
8
|
-
class extends subclass {
|
|
9
|
-
async execute() {
|
|
10
|
-
await super.execute();
|
|
11
|
-
|
|
12
|
-
this.copyTemplateJsonInto(
|
|
13
|
-
`${__dirname}/templates/package.json`,
|
|
14
|
-
this.destinationPath('package.json')
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
// await this.copyTemplates(`${__dirname}/templates/static/**/*`);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {fileURLToPath} from 'url';
|
|
2
|
-
import {dirname} from 'path';
|
|
3
|
-
|
|
4
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
-
const __dirname = dirname(__filename);
|
|
6
|
-
|
|
7
|
-
export const TsTestingWebTestRunnerMixin = (subclass) =>
|
|
8
|
-
class extends subclass {
|
|
9
|
-
async execute() {
|
|
10
|
-
await super.execute();
|
|
11
|
-
|
|
12
|
-
this.copyTemplateJsonInto(
|
|
13
|
-
`${__dirname}/templates/package.json`,
|
|
14
|
-
this.destinationPath('package.json')
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
// await this.copyTemplates(`${__dirname}/templates/static/**/*`);
|
|
18
|
-
}
|
|
19
|
-
};
|