Skip to content

Commit 52652a7

Browse files
committed
chore: tidy
1 parent 982749f commit 52652a7

9 files changed

Lines changed: 24 additions & 24 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ All examples so far have mentioned setting up tests against **pre-built dist out
479479
1. `vi.mock()` cannot intercept imports made by your components, because the dependency is already bundled away before Vitest gets involved.
480480
2. Coverage reports will not work out-of-the-box without additional configuration (`sourceMap: true` / [3rd party tools](https://github.com/cenfun/vitest-monocart-coverage)) and even then, may not be accurate.
481481

482-
The experimental `stencilVitestPlugin` solves this by hooking into Vite's transform pipeline: Stencil files are compiled on-the-fly before Vitest imports them; each component file becomes its own entry in Vitest's module graph and its imports are independently resolvable and mockable.
482+
The experimental `stencilVitestPlugin` solves this by hooking into Vite's transform pipeline: Stencil files are compiled on-the-fly before Vitest imports them; each component file becomes its own entry in Vitest's module graph - and its imports are independently resolvable and mockable.
483483

484484
### Setup
485485

@@ -497,7 +497,7 @@ export default defineVitestConfig({
497497
test: {
498498
name: 'plugin',
499499
include: ['src/**/*.plugin.spec.{ts,tsx}'],
500-
// No dist setup file needed each component source file registers
500+
// No dist setup file needed - each component source file registers
501501

502502
environment: 'stencil',
503503
// ^^ you can use the plugin with any setup - even browser tests!
@@ -535,7 +535,7 @@ It can then be imported and tested with mocked dependencies:
535535
import { describe, it, expect, vi } from 'vitest';
536536
import { render, h } from '@stencil/vitest';
537537

538-
// vi.mock() is hoisted the mock is in place before any imports resolve
538+
// vi.mock() is hoisted - the mock is in place before any imports resolve
539539
vi.mock('../utils/index.js', () => ({
540540
capitalize: vi.fn((s: string) => `[mocked:${s}]`),
541541
}));
@@ -561,7 +561,7 @@ it('renders using the mocked utility', async () => {
561561
In Stencil v4 `transpile()` (used within the plugin) is a single-file compiler. When a component class `extends` a base class that lives in a separate file, `transpile()` cannot follow the import to merge the parent's metadata and will throw an error.
562562

563563
```tsx
564-
// ❌ Will fail base class is in a separate file
564+
// ❌ Will fail - base class is in a separate file
565565
import { FormBase } from './form-base.js';
566566

567567
@Component({ tag: 'my-input', shadow: true })

src/plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Plugin } from 'vitest/config';
99
*
1010
* The compiled output uses `componentExport: 'customelement'`, which appends a
1111
* `customElements.define()` call at the end of the transformed file. The component
12-
* registers itself the moment the module is imported no dist loader or setup file
12+
* registers itself the moment the module is imported - no dist loader or setup file
1313
* required. Works with `@stencil/core` v4 and v5.
1414
*
1515
* @example
@@ -27,7 +27,7 @@ import type { Plugin } from 'vitest/config';
2727
* name: 'stencil',
2828
* environment: 'stencil',
2929
* include: ['**\/*.spec.tsx'],
30-
* // No dist loader needed import components from source directly
30+
* // No dist loader needed - import components from source directly
3131
* },
3232
* },
3333
* ],
@@ -104,7 +104,7 @@ export function stencilVitestPlugin(opts: { css?: boolean } = {}): Plugin {
104104
const result = await transpile(code, {
105105
file: id,
106106
// 'customelement' appends a customElements.define() call so the component
107-
// self-registers the moment this module is imported no loader needed.
107+
// self-registers the moment this module is imported - no loader needed.
108108
componentExport: 'customelement',
109109
componentMetadata: 'runtimestatic',
110110
currentDirectory: process.cwd(),
@@ -114,7 +114,7 @@ export function stencilVitestPlugin(opts: { css?: boolean } = {}): Plugin {
114114
style: opts.css ? 'static' : null,
115115
styleImportData: opts.css ? 'queryparams' : null,
116116
target: 'es2017',
117-
// Don't rewrite import paths let Vite handle resolution via aliases
117+
// Don't rewrite import paths - let Vite handle resolution via aliases
118118
transformAliasedImportPaths: false,
119119
});
120120

test/project/src/components.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export namespace Components {
2222
*/
2323
interface MyBadge {
2424
/**
25-
* The badge label passed through this.format() before rendering
25+
* The badge label - passed through this.format() before rendering
2626
* @default ''
2727
*/
2828
label: string;
@@ -72,7 +72,7 @@ export namespace Components {
7272
*/
7373
interface MyLabel {
7474
/**
75-
* Raw text to display run through `capitalize()` before rendering
75+
* Raw text to display - run through `capitalize()` before rendering
7676
* @default ''
7777
*/
7878
value: string;
@@ -214,7 +214,7 @@ declare namespace LocalJSX {
214214
*/
215215
interface MyBadge {
216216
/**
217-
* The badge label passed through this.format() before rendering
217+
* The badge label - passed through this.format() before rendering
218218
* @default ''
219219
*/
220220
label?: string;
@@ -268,7 +268,7 @@ declare namespace LocalJSX {
268268
*/
269269
interface MyLabel {
270270
/**
271-
* Raw text to display run through `capitalize()` before rendering
271+
* Raw text to display - run through `capitalize()` before rendering
272272
* @default ''
273273
*/
274274
value?: string;

test/project/src/components/my-badge/my-badge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { capitalize } from '../../utils/index.js';
88
* and cannot follow imports to resolve external base class metadata.
99
*/
1010
class FormattedBase {
11-
/** Applies capitalize() from utils mockable in tests */
11+
/** Applies capitalize() from utils - mockable in tests */
1212
protected format(value: string): string {
1313
return capitalize(value);
1414
}
@@ -23,7 +23,7 @@ class FormattedBase {
2323
shadow: true,
2424
})
2525
export class MyBadge extends FormattedBase {
26-
/** The badge label passed through this.format() before rendering */
26+
/** The badge label - passed through this.format() before rendering */
2727
@Prop() label: string = '';
2828

2929
render() {

test/project/src/components/my-button/matchers-new.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ describe('my-button - matchers', () => {
232232

233233
describe('shadow DOM text traversal (shadow: true)', () => {
234234
it('should find text that lives inside the shadow root', async () => {
235-
// cardTitle renders as <h3> inside the shadow root not in light DOM
235+
// cardTitle renders as <h3> inside the shadow root - not in light DOM
236236
const { root } = await render(<my-card cardTitle="Shadow Title">Slotted Content</my-card>);
237237

238238
expect(root).toHaveTextContent('Shadow Title');
@@ -263,7 +263,7 @@ describe('my-button - matchers', () => {
263263
});
264264

265265
it('should NOT find text that is only in the shadow root', async () => {
266-
// cardTitle is rendered inside the shadow DOM light DOM traversal should not see it
266+
// cardTitle is rendered inside the shadow DOM - light DOM traversal should not see it
267267
const { root } = await render(<my-card cardTitle="Shadow Title">Slotted Content</my-card>);
268268

269269
expect(root).not.toHaveLightTextContent('Shadow Title');
@@ -300,7 +300,7 @@ describe('my-button - matchers', () => {
300300
});
301301

302302
it('should match text that lives inside the shadow root', async () => {
303-
// cardTitle renders as <h3> inside the shadow root toEqualText should see it
303+
// cardTitle renders as <h3> inside the shadow root - toEqualText should see it
304304
const { root } = await render(<my-card cardTitle="Only Title" />);
305305

306306
expect(root).toEqualText('Only Title');
@@ -315,7 +315,7 @@ describe('my-button - matchers', () => {
315315
});
316316

317317
it('should NOT match text that is only in the shadow root', async () => {
318-
// cardTitle renders inside the shadow DOM light text will be empty
318+
// cardTitle renders inside the shadow DOM - light text will be empty
319319
const { root } = await render(<my-card cardTitle="Shadow Title" />);
320320

321321
expect(root).not.toEqualLightText('Shadow Title');

test/project/src/components/my-button/matchers.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe('my-button - custom matchers', () => {
208208
// Regression: a previous attempt at attribute sorting (sortAttributesInHtml)
209209
// used a regex that truncated values containing double-quotes (e.g. JSON objects)
210210
// and stripped values from single-quoted attributes entirely.
211-
// The fix is to not sort users write attributes in the order the serializer
211+
// The fix is to not sort - users write attributes in the order the serializer
212212
// produces them (alphabetical), same as every other testing library.
213213

214214
it('toEqualLightHtml: attribute with JSON value (single-quoted in expected string)', async () => {

test/project/src/components/my-label/my-label.plugin.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The plugin transforms my-label.tsx on-the-fly via the Stencil compiler
55
* (componentExport: 'customelement'), so it enters Vitest's module graph as
66
* a discrete ES module. That means vi.mock() can intercept any import the
7-
* component makes here we mock the capitalize() utility it calls in render().
7+
* component makes - here we mock the capitalize() utility it calls in render().
88
*
99
* This is impossible with the pre-built dist approach because the component
1010
* and its dependencies are already bundled together before Vitest sees them.
@@ -19,13 +19,13 @@ vi.mock('../../utils/index.js', () => ({
1919
capitalize: vi.fn((s: string) => `[mocked:${s}]`),
2020
}));
2121

22-
// Import the component source the plugin transforms it on-the-fly
22+
// Import the component source - the plugin transforms it on-the-fly
2323
// and the resulting customElements.define() call registers <my-label>
2424
// the moment this import resolves.
2525
import './my-label.tsx';
2626
import { capitalize } from '../../utils/index.js';
2727

28-
describe('my-label module mocking via stencilVitestPlugin', () => {
28+
describe('my-label - module mocking via stencilVitestPlugin', () => {
2929
beforeEach(() => {
3030
vi.clearAllMocks();
3131
});

test/project/src/components/my-label/my-label.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { capitalize } from '../../utils/index.js';
1111
styleUrl: 'my-label.css',
1212
})
1313
export class MyLabel {
14-
/** Raw text to display run through `capitalize()` before rendering */
14+
/** Raw text to display - run through `capitalize()` before rendering */
1515
@Prop() value: string = '';
1616

1717
@State() state = {

test/project/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default defineVitestConfig({
3333
name: 'plugin',
3434
environment: 'stencil',
3535
include: ['**/*.plugin.spec.{ts,tsx}'],
36-
// No dist setup file the plugin's customElements.define() output
36+
// No dist setup file - the plugin's customElements.define() output
3737
// registers each component the moment its source file is imported.
3838
},
3939
},

0 commit comments

Comments
 (0)