Home / File/ test.ts — svelte Source File

test.ts — svelte Source File

Architecture documentation for test.ts, a typescript file in the svelte codebase. 7 imports, 144 dependents.

File typescript BuildSystem QualityControl 7 imports 144 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  9ad2616a_f7be_f67c_79c2_34dda6d049e8["test.ts"]
  2b655554_f9cf_daf9_c56b_a99baafbe0fd["suite.ts"]
  9ad2616a_f7be_f67c_79c2_34dda6d049e8 --> 2b655554_f9cf_daf9_c56b_a99baafbe0fd
  1354ddff_1efb_c4e4_5cd0_7b354ba0a9b4["suite"]
  9ad2616a_f7be_f67c_79c2_34dda6d049e8 --> 1354ddff_1efb_c4e4_5cd0_7b354ba0a9b4
  e97e8c41_1b06_4e9a_29f3_64dbb37dee3c["helpers.js"]
  9ad2616a_f7be_f67c_79c2_34dda6d049e8 --> e97e8c41_1b06_4e9a_29f3_64dbb37dee3c
  bb4cfd90_903a_17e0_cd39_889d49aef9bb["read_file"]
  9ad2616a_f7be_f67c_79c2_34dda6d049e8 --> bb4cfd90_903a_17e0_cd39_889d49aef9bb
  f596e027_a951_36c9_7695_83acc4f0d6b9["node:fs"]
  9ad2616a_f7be_f67c_79c2_34dda6d049e8 --> f596e027_a951_36c9_7695_83acc4f0d6b9
  b63ddb92_634c_990b_eb1b_0bad8a4d434e["vitest"]
  9ad2616a_f7be_f67c_79c2_34dda6d049e8 --> b63ddb92_634c_990b_eb1b_0bad8a4d434e
  a8d49317_f479_a216_78e7_48c9e32499d5["compiler"]
  9ad2616a_f7be_f67c_79c2_34dda6d049e8 --> a8d49317_f479_a216_78e7_48c9e32499d5
  71782492_7b1e_cec4_828d_41a915245b70["_config.js"]
  71782492_7b1e_cec4_828d_41a915245b70 --> 9ad2616a_f7be_f67c_79c2_34dda6d049e8
  55ff88fe_70f5_3bf9_7600_808ac1250823["_config.js"]
  55ff88fe_70f5_3bf9_7600_808ac1250823 --> 9ad2616a_f7be_f67c_79c2_34dda6d049e8
  a95d18ec_6db2_f052_d811_bf1e206f2001["_config.js"]
  a95d18ec_6db2_f052_d811_bf1e206f2001 --> 9ad2616a_f7be_f67c_79c2_34dda6d049e8
  43816d9d_8759_327a_5dff_9abe63d2953f["_config.js"]
  43816d9d_8759_327a_5dff_9abe63d2953f --> 9ad2616a_f7be_f67c_79c2_34dda6d049e8
  5b2db24b_afbe_4bd7_dd14_b76b999e0209["_config.js"]
  5b2db24b_afbe_4bd7_dd14_b76b999e0209 --> 9ad2616a_f7be_f67c_79c2_34dda6d049e8
  03990ac6_4f35_66c0_1a3b_9d99e639da6b["_config.js"]
  03990ac6_4f35_66c0_1a3b_9d99e639da6b --> 9ad2616a_f7be_f67c_79c2_34dda6d049e8
  d56ede13_36c4_a48c_a8ec_49ef52aa5e2f["_config.js"]
  d56ede13_36c4_a48c_a8ec_49ef52aa5e2f --> 9ad2616a_f7be_f67c_79c2_34dda6d049e8
  style 9ad2616a_f7be_f67c_79c2_34dda6d049e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import * as fs from 'node:fs';
import { assert, expect, it } from 'vitest';
import { compile, compileModule, type CompileError } from 'svelte/compiler';
import { suite, type BaseTest } from '../suite';
import { read_file } from '../helpers.js';

interface CompilerErrorTest extends BaseTest {
	async?: boolean;
	error: {
		code: string;
		message: string;
		position?: [number, number];
	};
}

/**
 * Remove the "https://svelte.dev/e/..." link
 */
function strip_link(message: string) {
	return message.slice(0, message.lastIndexOf('\n'));
}

const { test, run } = suite<CompilerErrorTest>((config, cwd) => {
	if (!fs.existsSync(`${cwd}/main.svelte`) && !fs.existsSync(`${cwd}/main.svelte.js`)) {
		throw new Error('Expected main.svelte or main.svelte.js');
	}

	if (fs.existsSync(`${cwd}/main.svelte`)) {
		let caught_error = false;

		try {
			compile(read_file(`${cwd}/main.svelte`), {
				generate: 'client',
				experimental: { async: config.async ?? false }
			});
		} catch (e) {
			const error = e as CompileError;

			caught_error = true;

			expect(error.code).toBe(config.error.code);
			expect(strip_link(error.message)).toBe(config.error.message);

			if (config.error.position) {
				expect(error.position).toEqual(config.error.position);
			}
		}

		if (!caught_error) {
			assert.fail('Expected an error');
		}
	}

	if (fs.existsSync(`${cwd}/main.svelte.js`)) {
		let caught_error = false;

		try {
			compileModule(read_file(`${cwd}/main.svelte.js`), {
				generate: 'client'
			});
		} catch (e) {
			const error = e as CompileError;

			caught_error = true;

			expect(error.code).toEqual(config.error.code);
			expect(strip_link(error.message)).toEqual(config.error.message);

			if (config.error.position) {
				expect(error.position).toEqual(config.error.position);
			}
		}

		if (!caught_error) {
			assert.fail('Expected an error');
		}
	}
});

export { test };

await run(__dirname);

it('resets the compiler state including filename', () => {
	// start with something that succeeds
	compile('<div>hello</div>', { filename: 'foo.svelte' });
	// then try something that fails in the parsing stage
	try {
		compile('<p>hello<div>invalid</p>', { filename: 'bar.svelte' });
		expect.fail('Expected an error');
	} catch (e: any) {
		expect(e.toString()).toContain('bar.svelte');
	}
});

Domain

Subdomains

Functions

Dependencies

Imported By

Frequently Asked Questions

What does test.ts do?
test.ts is a source file in the svelte codebase, written in typescript. It belongs to the BuildSystem domain, QualityControl subdomain.
What functions are defined in test.ts?
test.ts defines 1 function(s): strip_link.
What does test.ts depend on?
test.ts imports 7 module(s): compiler, helpers.js, node:fs, read_file, suite, suite.ts, vitest.
What files import test.ts?
test.ts is imported by 144 file(s): _config.js, _config.js, _config.js, _config.js, _config.js, _config.js, _config.js, _config.js, and 136 more.
Where is test.ts in the architecture?
test.ts is located at packages/svelte/tests/compiler-errors/test.ts (domain: BuildSystem, subdomain: QualityControl, directory: packages/svelte/tests/compiler-errors).

Analyze Your Own Codebase

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

Try Supermodel Free