@blockquote/create-wc 1.110.1 → 2.0.1

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 CHANGED
@@ -1,26 +1,28 @@
1
- # Web Component with Lit - Scaffolding
1
+ # Web Components with Lit - Scaffold
2
2
 
3
- This scaffold generator extends and customizes the core parts of **[@open-wc/create](https://open-wc.org/docs/development/generator/#extending)** providing a starting point for creating a web component with **[Lit](https://lit.dev/)**
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 tools:
5
+ ## Development Tools
6
6
 
7
- - ### [Open Web Components](https://open-wc.org/) & [Modern Web](https://modern-web.dev/)
7
+ ### Scaffold
8
8
 
9
- - Scaffold
10
- - Lint        `es-lint`
11
- - Format   `prettier`
12
- - Test       `web-test-runner`
9
+ - Lint: `eslint`
10
+ - Format: `prettier`
13
11
 
14
- - ### [Vite](https://vitejs.dev/)
12
+ ### Vite & Vitest
15
13
 
16
- - [De Server](https://vitejs.dev/config/server-options.html)
17
- - [Preview](https://vitejs.dev/config/preview-options.html)
18
- - [Build](https://vitejs.dev/guide/build.html)
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
- - ### [Sass](https://github.com/oscarmarina/sass-style-template)
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
- - SCSS watcher with [sass](https://www.npmjs.com/package/sass)
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@latest
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 formatting
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 linting and formatting errors, run
55
+ To automatically fix them, run:
54
56
 
55
57
  ```bash
56
58
  npm run format
57
59
  ```
58
60
 
59
- ### Testing with Web Test Runner
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
- To execute a single test run:
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
- ### dev server
71
+ ### Development Server
129
72
 
130
- - Vite supports importing .ts files out of the box ([4848](https://github.com/vitejs/vite/issues/4848), [3040](https://github.com/vitejs/vite/issues/3040#issuecomment-940697809))
73
+ Start the development server:
131
74
 
132
75
  ```bash
133
- npm run vite
76
+ npm run start
134
77
  ```
135
78
 
136
- ### For hosting a static demo purposes only - [Do not bundle](https://justinfagnani.com/2019/11/01/how-to-publish-web-components-to-npm/#do-not-bundle)
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
- ### sass
103
+ ### Sass
157
104
 
158
- #### scss watcher
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 Element Manifest
115
+ ### Custom Elements Manifest
116
+
117
+ #### Generating README from `custom-elements.json`
167
118
 
168
- #### Generating README from custom-elements.json
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`; run `npm run prepare` to set up Husky and its Git hooks.
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
- > - https://github.com/oscarmarina/blockquote-web-components
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": "1.110.1",
3
+ "version": "2.0.1",
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.3.0",
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"
@@ -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, TestingScaffoldMixin} from '../testing/index.js';
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, TsTestingScaffoldMixin} from '../testing-ts/index.js';
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
  }
@@ -55,7 +55,7 @@
55
55
  "eslint-plugin-wc": "^2.2.0",
56
56
  "@typescript-eslint/parser": "^8.18.1",
57
57
  "typescript-eslint": "^8.18.1",
58
- "globals": "^15.13.0",
58
+ "globals": "^15.14.0",
59
59
  "husky": "^9.1.7",
60
60
  "lint-staged": "^15.2.11",
61
61
  "prettier": "^3.4.2",
@@ -19,27 +19,34 @@
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"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@blockquote/cem-to-markdown-readme": "^1.0.0",
29
- "@blockquote/coverage-table-reporter": "^1.2.0",
30
30
  "@blockquote/rollup-plugin-externalize-source-dependencies": "^1.0.0",
31
- "@blockquote/rollup-plugin-total-bundlesize": "^2.1.2",
31
+ "@blockquote/rollup-plugin-total-bundlesize": "^2.2.0",
32
32
  "@blockquote/sass-style-template": "^4.1.0",
33
33
  "@custom-elements-manifest/analyzer": "^0.10.4",
34
+ "@open-wc/semantic-dom-diff": "^0.20.1",
34
35
  "@open-wc/testing": "^4.0.0",
36
+ "playwright": "^1.49.1",
35
37
  "@types/mocha": "^10.0.10",
36
- "@web/test-runner": "^0.19.0",
37
- "@web/test-runner-playwright": "^0.11.0",
38
38
  "@rollup/plugin-multi-entry": "^6.0.1",
39
39
  "rollup-plugin-copy": "^3.5.0",
40
+ "rollup-plugin-node-externals": "^8.0.0",
41
+ "tinyglobby": "^0.2.10",
40
42
  "concurrently": "^9.1.0",
41
43
  "sort-package-json": "^2.12.0",
42
- "vite": "^6.0.3"
44
+ "@vitest/browser": "^3.0.0-beta.2",
45
+ "@vitest/coverage-istanbul": "^3.0.0-beta.2",
46
+ "@vitest/coverage-v8": "^3.0.0-beta.2",
47
+ "@vitest/ui": "^3.0.0-beta.2",
48
+ "vitest": "^3.0.0-beta.2",
49
+ "vite": "^6.0.4"
43
50
  },
44
51
  "publishConfig": {
45
52
  "access": "public"
@@ -14,9 +14,45 @@ const copyConfig = {
14
14
  hook: 'writeBundle',
15
15
  };
16
16
 
17
- const outDir = process.env.OUTDIR || '.';
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),
@@ -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 TestingWebTestRunnerMixin(subclass) {
9
+ class extends subclass {
11
10
  async execute() {
12
11
  await super.execute();
13
12
  this.copyTemplateJsonInto(
@@ -1,4 +1,8 @@
1
- import {html, fixture, assert, expect, fixtureCleanup} from '@open-wc/testing';
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
- teardown(() => fixtureCleanup());
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
- assert.equal(el.heading, 'Hey there');
19
- assert.equal(el.counter, 5);
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
- suite('Semantic Dom and a11y', () => {
23
- test('SHADOW DOM - Structure test', async () => {
24
- await expect(el).shadowDom.to.equalSnapshot();
25
- });
34
+ test('SHADOW DOM - Structure test', () => {
35
+ expect(getDiffableHTML(elShadowRoot)).toMatchSnapshot('SHADOW DOM');
36
+ });
26
37
 
27
- test('LIGHT DOM - Structure test', async () => {
28
- await expect(el).lightDom.to.equalSnapshot();
29
- });
38
+ test('LIGHT DOM - Structure test', () => {
39
+ expect(getDiffableHTML(el, {ignoreAttributes: ['id']})).toMatchSnapshot('LIGHT DOM');
40
+ });
30
41
 
31
- test('a11y', async () => {
32
- await assert.isAccessible(el);
33
- });
42
+ test('a11y', async () => {
43
+ await a11y.isAccessible(el);
34
44
  });
35
45
  });
36
46
 
37
47
  suite('Events ', () => {
38
- setup(async () => {
48
+ beforeEach(async () => {
39
49
  el = await fixture(html`<<%= tagName %>></<%= tagName %>>`);
50
+ elLocator = page.elementLocator(el);
40
51
  });
41
52
 
42
- test('increases the counter on button click', () => {
43
- el.shadowRoot?.querySelector('button')?.click();
44
- assert.equal(el.counter, 6);
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
- setup(async () => {
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', () => {
@@ -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 TsTestingWebTestRunnerMixin(subclass) {
9
+ class extends subclass {
11
10
  async execute() {
12
11
  await super.execute();
13
12
 
@@ -1,52 +1,84 @@
1
- import {html, fixture, assert, expect, fixtureCleanup} from '@open-wc/testing';
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
- teardown(() => fixtureCleanup());
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
- assert.equal(el.heading, 'Hey there');
17
- assert.equal(el.counter, 5);
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
- suite('Semantic Dom and a11y', () => {
21
- test('SHADOW DOM - Structure test', async () => {
22
- await expect(el).shadowDom.to.equalSnapshot();
23
- });
32
+ test('SHADOW DOM - Structure test', () => {
33
+ expect(getDiffableHTML(elShadowRoot)).toMatchSnapshot('SHADOW DOM');
34
+ });
24
35
 
25
- test('LIGHT DOM - Structure test', async () => {
26
- await expect(el).lightDom.to.equalSnapshot();
27
- });
36
+ test('LIGHT DOM - Structure test', () => {
37
+ expect(getDiffableHTML(el, {ignoreAttributes: ['id']})).toMatchSnapshot('LIGHT DOM');
38
+ });
28
39
 
29
- test('a11y', async () => {
30
- await assert.isAccessible(el);
31
- });
40
+ test('a11y', async () => {
41
+ await a11y.isAccessible(el);
32
42
  });
33
43
  });
34
44
 
35
45
  suite('Events ', () => {
36
- setup(async () => {
46
+ beforeEach(async () => {
37
47
  el = await fixture(html`<<%= tagName %>></<%= tagName %>>`);
48
+ elLocator = page.elementLocator(el);
38
49
  });
39
50
 
40
- test('increases the counter on button click', () => {
41
- const button = el.shadowRoot!.querySelector('button')!;
42
- button.click();
43
- assert.equal(el.counter, 6);
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
- setup(async () => {
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/src/index.js"
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/src/<%= className %>.js"
10
+ "default": "./dist/<%= className %>.js"
11
11
  },
12
12
  "./<%= tagName %>.js": {
13
- "default": "./dist/src/define/<%= tagName %>.js"
13
+ "default": "./dist/define/<%= tagName %>.js"
14
14
  },
15
15
  "./index.js": {
16
- "default": "./dist/src/index.js"
16
+ "default": "./dist/index.js"
17
17
  },
18
18
  "./<%= tagName %>-styles.css.js": {
19
- "default": "./dist/src/styles/<%= tagName %>-styles.css.js"
19
+ "default": "./dist/styles/<%= tagName %>-styles.css.js"
20
20
  }
21
21
  },
22
- "main": "dist/src/index.js",
23
- "module": "dist/src/index.js",
22
+ "main": "dist/index.js",
23
+ "module": "dist/index.js",
24
24
  "files": [
25
- "/dist/",
26
- "!/dist/test/"
25
+ "/src/",
26
+ "/dist/"
27
27
  ],
28
28
  "scripts": {
29
- "build": "npm run build:tsc && npm run dev:vite",
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
- "sourceMap": true,
17
- "outDir": "./dist",
18
- "stripInternal": true,
19
- "verbatimModuleSyntax": true,
7
+ "emitDeclarationOnly": true,
20
8
  "esModuleInterop": true,
9
+ "experimentalDecorators": true,
21
10
  "forceConsistentCasingInFileNames": true,
22
- "strict": true,
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
- "noImplicitReturns": true,
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
- "noFallthroughCasesInSwitch": true,
30
- "noImplicitOverride": true,
31
- "types": ["mocha"]
31
+ "verbatimModuleSyntax": true
32
32
  },
33
- "include": ["src/**/*.ts", "test/**/*.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
- });
@@ -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,6 +0,0 @@
1
- {
2
- "scripts": {
3
- "test": "wtr",
4
- "test:watch": "wtr --watch"
5
- }
6
- }
@@ -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
- };
@@ -1,6 +0,0 @@
1
- {
2
- "scripts": {
3
- "test": "tsc && OUTDIR=dist wtr",
4
- "test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"OUTDIR=dist wtr --watch\""
5
- }
6
- }