@stencil/vitest 0.0.1-dev.20260109124515.90fb962 → 0.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.
File without changes
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Setup file for happy-dom environment
3
+ * Auto-loaded when using a project named 'happy-dom' or containing 'happy-dom'
4
+ *
5
+ * Configures happy-dom with Stencil-specific setup
6
+ * happy-dom generally has better built-in support than jsdom, so fewer polyfills are needed
7
+ */
8
+ /**
9
+ * Main setup function for happy-dom environment
10
+ */
11
+ export declare function setup(): Promise<void>;
12
+ //# sourceMappingURL=happy-dom-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"happy-dom-setup.d.ts","sourceRoot":"","sources":["../../src/testing/happy-dom-setup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,wBAAsB,KAAK,kBAG1B"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Setup file for happy-dom environment
3
+ * Auto-loaded when using a project named 'happy-dom' or containing 'happy-dom'
4
+ *
5
+ * Configures happy-dom with Stencil-specific setup
6
+ * happy-dom generally has better built-in support than jsdom, so fewer polyfills are needed
7
+ */
8
+ /**
9
+ * Main setup function for happy-dom environment
10
+ */
11
+ export async function setup() {
12
+ // happy-dom is generally more complete than jsdom out of the box
13
+ // Add polyfills here as needed when issues are discovered
14
+ }
15
+ // Auto-run setup
16
+ setup();
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Setup jsdom environment for Stencil component testing
3
+ *
4
+ * This module provides polyfills and initialization for testing Stencil components
5
+ * in a jsdom environment. It handles:
6
+ * - Polyfilling adoptedStyleSheets for Shadow DOM
7
+ * - Polyfilling CSS support detection
8
+ * - Polyfilling requestAnimationFrame and related APIs
9
+ * - Loading and initializing Stencil lazy loader
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // vitest.config.ts
14
+ * export default defineVitestConfig({
15
+ * test: {
16
+ * setupFiles: ['@stencil/test-utils/jsdom-setup'],
17
+ * },
18
+ * });
19
+ * ```
20
+ */
21
+ /**
22
+ * Apply polyfills to a jsdom window object for Stencil components
23
+ * This function is reused by both the setup file and the custom environment
24
+ */
25
+ export declare function applyJsdomPolyfills(window: Window & typeof globalThis): void;
26
+ /**
27
+ * Initialize jsdom environment for Stencil testing
28
+ */
29
+ export declare function setup(): Promise<void>;
30
+ //# sourceMappingURL=jsdom-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdom-setup.d.ts","sourceRoot":"","sources":["../../src/testing/jsdom-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,UAAU,QA2DrE;AAED;;GAEG;AACH,wBAAsB,KAAK,kBAa1B"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Setup jsdom environment for Stencil component testing
3
+ *
4
+ * This module provides polyfills and initialization for testing Stencil components
5
+ * in a jsdom environment. It handles:
6
+ * - Polyfilling adoptedStyleSheets for Shadow DOM
7
+ * - Polyfilling CSS support detection
8
+ * - Polyfilling requestAnimationFrame and related APIs
9
+ * - Loading and initializing Stencil lazy loader
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // vitest.config.ts
14
+ * export default defineVitestConfig({
15
+ * test: {
16
+ * setupFiles: ['@stencil/test-utils/jsdom-setup'],
17
+ * },
18
+ * });
19
+ * ```
20
+ */
21
+ /**
22
+ * Apply polyfills to a jsdom window object for Stencil components
23
+ * This function is reused by both the setup file and the custom environment
24
+ */
25
+ export function applyJsdomPolyfills(window) {
26
+ // Polyfill adoptedStyleSheets for Shadow DOM
27
+ if (!window.document.adoptedStyleSheets) {
28
+ Object.defineProperty(window.document, 'adoptedStyleSheets', {
29
+ value: [],
30
+ writable: true,
31
+ configurable: true,
32
+ });
33
+ }
34
+ if (typeof window.ShadowRoot !== 'undefined' &&
35
+ !Object.prototype.hasOwnProperty.call(window.ShadowRoot.prototype, 'adoptedStyleSheets')) {
36
+ Object.defineProperty(window.ShadowRoot.prototype, 'adoptedStyleSheets', {
37
+ get() {
38
+ if (!this._adoptedStyleSheets) {
39
+ this._adoptedStyleSheets = [];
40
+ }
41
+ return this._adoptedStyleSheets;
42
+ },
43
+ set(value) {
44
+ this._adoptedStyleSheets = value;
45
+ },
46
+ configurable: true,
47
+ });
48
+ }
49
+ // Polyfill CSS support
50
+ if (!window.CSS) {
51
+ window.CSS = {
52
+ supports: () => true,
53
+ };
54
+ }
55
+ // Polyfill scrollTo
56
+ window.scrollTo = () => { };
57
+ // Add requestAnimationFrame and related APIs
58
+ if (!window.requestAnimationFrame) {
59
+ window.requestAnimationFrame = (cb) => {
60
+ return setTimeout(cb, 0);
61
+ };
62
+ }
63
+ if (!window.cancelAnimationFrame) {
64
+ window.cancelAnimationFrame = (id) => {
65
+ clearTimeout(id);
66
+ };
67
+ }
68
+ if (!window.requestIdleCallback) {
69
+ window.requestIdleCallback = (cb) => {
70
+ return setTimeout(cb, 0);
71
+ };
72
+ }
73
+ if (!window.cancelIdleCallback) {
74
+ window.cancelIdleCallback = (id) => {
75
+ clearTimeout(id);
76
+ };
77
+ }
78
+ }
79
+ /**
80
+ * Initialize jsdom environment for Stencil testing
81
+ */
82
+ export async function setup() {
83
+ // Only run in jsdom environment (Node.js with DOM)
84
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
85
+ return;
86
+ }
87
+ // Skip if running in actual browser (Playwright, WebdriverIO, etc.)
88
+ // In actual browsers, process is undefined or doesn't have cwd
89
+ if (typeof process === 'undefined' || typeof process.cwd !== 'function') {
90
+ return;
91
+ }
92
+ applyJsdomPolyfills(window);
93
+ }
94
+ // Auto-run setup when imported
95
+ setup();
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Setup for mock-doc environment
3
+ * This file is automatically loaded when using the mock-doc environment in Node.js
4
+ *
5
+ * IMPORTANT: This should only be imported/executed in Node.js runtime, not in browsers.
6
+ * The projects-based config ensures this is only loaded for node:mock-doc projects.
7
+ */
8
+ import { setupGlobal, teardownGlobal } from '@stencil/core/mock-doc';
9
+ /**
10
+ * Apply polyfills to a window object for Stencil components
11
+ * This function is reused by both the setup file and the custom environment
12
+ */
13
+ export declare function applyMockDocPolyfills(win: any): void;
14
+ declare let win: any;
15
+ declare let doc: any;
16
+ export { win, doc, setupGlobal, teardownGlobal };
17
+ //# sourceMappingURL=mock-doc-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-doc-setup.d.ts","sourceRoot":"","sources":["../../src/testing/mock-doc-setup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAc,WAAW,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEjF;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,QAmD7C;AAOD,QAAA,IAAI,GAAG,EAAE,GAAG,CAAC;AACb,QAAA,IAAI,GAAG,EAAE,GAAG,CAAC;AA6Bb,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Setup for mock-doc environment
3
+ * This file is automatically loaded when using the mock-doc environment in Node.js
4
+ *
5
+ * IMPORTANT: This should only be imported/executed in Node.js runtime, not in browsers.
6
+ * The projects-based config ensures this is only loaded for node:mock-doc projects.
7
+ */
8
+ import { MockWindow, setupGlobal, teardownGlobal } from '@stencil/core/mock-doc';
9
+ /**
10
+ * Apply polyfills to a window object for Stencil components
11
+ * This function is reused by both the setup file and the custom environment
12
+ */
13
+ export function applyMockDocPolyfills(win) {
14
+ // Set baseURI manually
15
+ Object.defineProperty(win.document, 'baseURI', {
16
+ value: 'http://localhost:3000/',
17
+ writable: false,
18
+ configurable: true,
19
+ });
20
+ // Setup global with mock-doc globals
21
+ setupGlobal(win);
22
+ // Add MessageEvent if it doesn't exist (needed by Node's undici)
23
+ if (!win.MessageEvent) {
24
+ win.MessageEvent = class MessageEvent extends win.Event {
25
+ constructor(type, eventInitDict) {
26
+ super(type, eventInitDict);
27
+ }
28
+ };
29
+ }
30
+ // Add AbortController if it doesn't exist
31
+ if (!win.AbortController) {
32
+ win.AbortController = class AbortController {
33
+ constructor() {
34
+ this.signal = {
35
+ aborted: false,
36
+ addEventListener: () => { },
37
+ removeEventListener: () => { },
38
+ dispatchEvent: () => true,
39
+ };
40
+ }
41
+ abort() {
42
+ this.signal.aborted = true;
43
+ }
44
+ };
45
+ }
46
+ // Add requestAnimationFrame and related APIs
47
+ win.requestAnimationFrame = (cb) => {
48
+ return setTimeout(cb, 0);
49
+ };
50
+ win.cancelAnimationFrame = (id) => {
51
+ clearTimeout(id);
52
+ };
53
+ win.requestIdleCallback = (cb) => {
54
+ return setTimeout(cb, 0);
55
+ };
56
+ win.cancelIdleCallback = (id) => {
57
+ clearTimeout(id);
58
+ };
59
+ }
60
+ // Only setup mock-doc if we're actually in Node.js (not a real browser)
61
+ // Check for Node.js-specific globals that don't exist in browsers
62
+ const isNodeEnvironment = typeof process !== 'undefined' && process?.versions?.node !== undefined && typeof window === 'undefined';
63
+ let win;
64
+ let doc;
65
+ if (!isNodeEnvironment) {
66
+ // We're in a real browser, skip mock-doc setup and export real globals
67
+ win = typeof window !== 'undefined' ? window : undefined;
68
+ doc = typeof document !== 'undefined' ? document : undefined;
69
+ }
70
+ else {
71
+ // We're in Node.js, setup mock-doc
72
+ // Create mock window with URL
73
+ win = new MockWindow('http://localhost:3000/');
74
+ doc = win.document;
75
+ // Apply polyfills
76
+ applyMockDocPolyfills(win);
77
+ // Assign to globalThis
78
+ globalThis.window = win;
79
+ globalThis.document = doc;
80
+ globalThis.HTMLElement = win.HTMLElement;
81
+ globalThis.CustomEvent = win.CustomEvent;
82
+ globalThis.Event = win.Event;
83
+ globalThis.Element = win.Element;
84
+ globalThis.Node = win.Node;
85
+ globalThis.DocumentFragment = win.DocumentFragment;
86
+ globalThis.requestAnimationFrame = win.requestAnimationFrame;
87
+ globalThis.cancelAnimationFrame = win.cancelAnimationFrame;
88
+ }
89
+ // Export the mock window for use in custom setup
90
+ export { win, doc, setupGlobal, teardownGlobal };
@@ -0,0 +1,19 @@
1
+ import type { Config as StencilConfig } from '@stencil/core/internal';
2
+ /**
3
+ * Load Stencil configuration from a file path
4
+ * Uses jiti to handle TypeScript files in Node.js
5
+ */
6
+ export declare function loadStencilConfig(configPath: string): Promise<StencilConfig | undefined>;
7
+ /**
8
+ * Get the source directory from Stencil config
9
+ */
10
+ export declare function getStencilSrcDir(config?: StencilConfig): string;
11
+ /**
12
+ * Get all output directories from Stencil config for exclusion
13
+ */
14
+ export declare function getStencilOutputDirs(config?: StencilConfig): string[];
15
+ /**
16
+ * Create resolve aliases from Stencil config
17
+ */
18
+ export declare function getStencilResolveAliases(config?: StencilConfig): Record<string, string>;
19
+ //# sourceMappingURL=config-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/utils/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAItE;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAsB9F;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,MAAM,CAE/D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,MAAM,EAAE,CAyCrE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBvF"}
@@ -0,0 +1,92 @@
1
+ import { existsSync } from 'fs';
2
+ import { resolve } from 'path';
3
+ /**
4
+ * Load Stencil configuration from a file path
5
+ * Uses jiti to handle TypeScript files in Node.js
6
+ */
7
+ export async function loadStencilConfig(configPath) {
8
+ const resolvedPath = resolve(process.cwd(), configPath);
9
+ if (!existsSync(resolvedPath)) {
10
+ console.warn(`Stencil config not found at ${resolvedPath}`);
11
+ return undefined;
12
+ }
13
+ try {
14
+ // Use jiti for loading TypeScript configs in Node.js
15
+ const { createJiti } = await import('jiti');
16
+ const jiti = createJiti(process.cwd(), {
17
+ interopDefault: true,
18
+ moduleCache: false,
19
+ });
20
+ const configModule = (await jiti.import(resolvedPath));
21
+ return configModule.config || configModule.default || configModule;
22
+ }
23
+ catch (error) {
24
+ console.error(`Failed to load Stencil config from ${resolvedPath}:`, error);
25
+ return undefined;
26
+ }
27
+ }
28
+ /**
29
+ * Get the source directory from Stencil config
30
+ */
31
+ export function getStencilSrcDir(config) {
32
+ return config?.srcDir || 'src';
33
+ }
34
+ /**
35
+ * Get all output directories from Stencil config for exclusion
36
+ */
37
+ export function getStencilOutputDirs(config) {
38
+ if (!config?.outputTargets) {
39
+ return ['dist', 'www', 'build', '.stencil'];
40
+ }
41
+ const outputDirs = new Set();
42
+ config.outputTargets.forEach((target) => {
43
+ // Add common output directories based on target type
44
+ if (target.dir) {
45
+ outputDirs.add(target.dir);
46
+ }
47
+ if (target.buildDir) {
48
+ outputDirs.add(target.buildDir);
49
+ }
50
+ // Handle Stencil default directories for output types that don't specify dir
51
+ // Based on Stencil's default behavior:
52
+ if (target.type === 'dist' || target.type === 'dist-custom-elements' || target.type === 'dist-hydrate-script') {
53
+ // These all default to 'dist' directory
54
+ if (!target.dir && !target.buildDir) {
55
+ outputDirs.add('dist');
56
+ }
57
+ }
58
+ if (target.type === 'www') {
59
+ // www defaults to 'www' directory
60
+ if (!target.dir && !target.buildDir) {
61
+ outputDirs.add('www');
62
+ }
63
+ }
64
+ // Note: esmLoaderPath is a relative import path like '../loader', not a directory
65
+ // We should NOT extract this as an exclude pattern
66
+ });
67
+ // Always include common output directories
68
+ outputDirs.add('.stencil');
69
+ // Filter out invalid paths (those that navigate up with ..)
70
+ const validDirs = Array.from(outputDirs).filter((dir) => !dir.includes('..'));
71
+ return validDirs.length > 0 ? validDirs : ['dist', 'www', 'build', '.stencil'];
72
+ }
73
+ /**
74
+ * Create resolve aliases from Stencil config
75
+ */
76
+ export function getStencilResolveAliases(config) {
77
+ const srcDir = getStencilSrcDir(config);
78
+ const aliases = {
79
+ '@': resolve(process.cwd(), srcDir),
80
+ };
81
+ // Add component alias if components directory exists
82
+ const componentsDir = resolve(process.cwd(), srcDir, 'components');
83
+ if (existsSync(componentsDir)) {
84
+ aliases['@components'] = componentsDir;
85
+ }
86
+ // Add utils alias if utils directory exists
87
+ const utilsDir = resolve(process.cwd(), srcDir, 'utils');
88
+ if (existsSync(utilsDir)) {
89
+ aliases['@utils'] = utilsDir;
90
+ }
91
+ return aliases;
92
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/stenciljs/vitest"
6
6
  },
7
- "version": "0.0.1-dev.20260109124515.90fb962",
7
+ "version": "0.0.1",
8
8
  "description": "First-class testing utilities for Stencil design systems with Vitest",
9
9
  "license": "MIT",
10
10
  "type": "module",