Home / File/ _config.js — svelte Source File

_config.js — svelte Source File

Architecture documentation for _config.js, a javascript file in the svelte codebase. 2 imports, 0 dependents.

File javascript BuildSystem QualityControl 2 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  786fd3fa_1346_154b_fdbd_cfaf5ccc7340["_config.js"]
  654af6d6_2570_6860_f8dd_6b6131e1eec4["test.ts"]
  786fd3fa_1346_154b_fdbd_cfaf5ccc7340 --> 654af6d6_2570_6860_f8dd_6b6131e1eec4
  4ead6623_c53e_ab40_5690_64903d5addf1["svelte"]
  786fd3fa_1346_154b_fdbd_cfaf5ccc7340 --> 4ead6623_c53e_ab40_5690_64903d5addf1
  style 786fd3fa_1346_154b_fdbd_cfaf5ccc7340 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { flushSync } from 'svelte';
import { test } from '../../test';

/** @type {() => DOMRect} */
let originalDivGetBoundingClientRect;
/** @type {() => DOMRect} */
let originalSpanGetBoundingClientRect;
/** @type {() => DOMRect} */
let originalParagraphGetBoundingClientRect;

export default test({
	mode: ['client', 'hydrate'], // no animations in SSR
	get props() {
		return {
			things: [
				{ id: 1, name: 'a' },
				{ id: 2, name: 'b' },
				{ id: 3, name: 'c' },
				{ id: 4, name: 'd' },
				{ id: 5, name: 'e' }
			],
			tag: 'div'
		};
	},

	html: `
		<div>a</div>
		<div>b</div>
		<div>c</div>
		<div>d</div>
		<div>e</div>
	`,

	before_test() {
		originalDivGetBoundingClientRect = window.HTMLDivElement.prototype.getBoundingClientRect;
		originalSpanGetBoundingClientRect = window.HTMLSpanElement.prototype.getBoundingClientRect;
		originalParagraphGetBoundingClientRect =
			window.HTMLParagraphElement.prototype.getBoundingClientRect;

		window.HTMLDivElement.prototype.getBoundingClientRect = fakeGetBoundingClientRect;
		window.HTMLSpanElement.prototype.getBoundingClientRect = fakeGetBoundingClientRect;
		window.HTMLParagraphElement.prototype.getBoundingClientRect = fakeGetBoundingClientRect;

		/**
		 * @this {HTMLElement}
		 */
		function fakeGetBoundingClientRect() {
			const index = [...(this.parentNode?.children ?? [])].indexOf(this);
			const top = index * 30;

			return /** @type {DOMRect} */ ({
				left: 0,
				right: 100,
				top,
				bottom: top + 20
			});
		}
	},
	after_test() {
		window.HTMLDivElement.prototype.getBoundingClientRect = originalDivGetBoundingClientRect;
		window.HTMLSpanElement.prototype.getBoundingClientRect = originalSpanGetBoundingClientRect;
		window.HTMLParagraphElement.prototype.getBoundingClientRect =
			originalParagraphGetBoundingClientRect;
	},

	async test({ assert, component, raf }) {
		// switch tag and things at the same time
		flushSync(() => {
			component.update('p', [
				{ id: 5, name: 'e' },
				{ id: 2, name: 'b' },
				{ id: 3, name: 'c' },
				{ id: 4, name: 'd' },
				{ id: 1, name: 'a' }
			]);
		});

		const ps = /** @type {NodeListOf<HTMLParagraphElement & { dy: number }>} */ (
			document.querySelectorAll('p')
		);
		raf.tick(0);
		assert.equal(ps[0].dy, 120);
		assert.equal(ps[4].dy, -120);

		raf.tick(50);
		assert.equal(ps[0].dy, 60);
		assert.equal(ps[4].dy, -60);

		raf.tick(100);
		assert.equal(ps[0].dy, 0);
		assert.equal(ps[4].dy, 0);

		flushSync(() => {
			component.update('span', [
				{ id: 1, name: 'a' },
				{ id: 2, name: 'b' },
				{ id: 3, name: 'c' },
				{ id: 4, name: 'd' },
				{ id: 5, name: 'e' }
			]);
		});

		const spans = /** @type {NodeListOf<HTMLSpanElement & { dy: number }>} */ (
			document.querySelectorAll('span')
		);

		raf.tick(100);
		assert.equal(spans[0].dy, 120);
		assert.equal(spans[4].dy, -120);

		raf.tick(150);
		assert.equal(spans[0].dy, 60);
		assert.equal(spans[4].dy, -60);

		raf.tick(200);
		assert.equal(spans[0].dy, 0);
		assert.equal(spans[4].dy, 0);
	}
});

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does _config.js do?
_config.js is a source file in the svelte codebase, written in javascript. It belongs to the BuildSystem domain, QualityControl subdomain.
What functions are defined in _config.js?
_config.js defines 4 function(s): default.after_test, default.before_test, default.props, default.test.
What does _config.js depend on?
_config.js imports 2 module(s): svelte, test.ts.
Where is _config.js in the architecture?
_config.js is located at packages/svelte/tests/runtime-legacy/samples/dynamic-element-animation-2/_config.js (domain: BuildSystem, subdomain: QualityControl, directory: packages/svelte/tests/runtime-legacy/samples/dynamic-element-animation-2).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free