suite.ts — svelte Source File
Architecture documentation for suite.ts, a typescript file in the svelte codebase. 2 imports, 4 dependents.
Entity Profile
Dependency Diagram
graph LR 2b655554_f9cf_daf9_c56b_a99baafbe0fd["suite.ts"] f596e027_a951_36c9_7695_83acc4f0d6b9["node:fs"] 2b655554_f9cf_daf9_c56b_a99baafbe0fd --> f596e027_a951_36c9_7695_83acc4f0d6b9 b63ddb92_634c_990b_eb1b_0bad8a4d434e["vitest"] 2b655554_f9cf_daf9_c56b_a99baafbe0fd --> b63ddb92_634c_990b_eb1b_0bad8a4d434e 9ad2616a_f7be_f67c_79c2_34dda6d049e8["test.ts"] 9ad2616a_f7be_f67c_79c2_34dda6d049e8 --> 2b655554_f9cf_daf9_c56b_a99baafbe0fd 42f0f097_4458_875b_c920_692659ecc7f1["test-ssr.ts"] 42f0f097_4458_875b_c920_692659ecc7f1 --> 2b655554_f9cf_daf9_c56b_a99baafbe0fd 8e711bf9_bf97_b655_8376_8fca789308e2["test.ts"] 8e711bf9_bf97_b655_8376_8fca789308e2 --> 2b655554_f9cf_daf9_c56b_a99baafbe0fd 0021c40c_0ebc_e6e9_7eae_a8ec68210cc3["_config.js"] 0021c40c_0ebc_e6e9_7eae_a8ec68210cc3 --> 2b655554_f9cf_daf9_c56b_a99baafbe0fd style 2b655554_f9cf_daf9_c56b_a99baafbe0fd fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs';
import { it } from 'vitest';
export interface BaseTest {
skip?: boolean;
solo?: boolean;
}
/**
* To filter tests, run one of these:
*
* FILTER=my-test pnpm test (runs only the 'my-test' test)
* FILTER=/feature/ pnpm test (runs all tests matching /feature/)
*/
const filter = process.env.FILTER
? new RegExp(
process.env.FILTER.startsWith('/')
? process.env.FILTER.slice(1, -1).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
: `^${process.env.FILTER.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')}$`
)
: /./;
// this defaults to 10, which is too low for some of our tests
Error.stackTraceLimit = 100;
export function suite<Test extends BaseTest>(fn: (config: Test, test_dir: string) => void) {
return {
test: (config: Test) => config,
run: async (cwd: string, samples_dir = 'samples') => {
await for_each_dir<Test>(cwd, samples_dir, (config, dir) => {
let it_fn = config.skip ? it.skip : config.solo ? it.only : it;
it_fn(dir, () => fn(config, `${cwd}/${samples_dir}/${dir}`));
});
}
};
}
export function suite_with_variants<Test extends BaseTest, Variants extends string, Common>(
variants: Variants[],
should_skip_variant: (variant: Variants, config: Test, test_name: string) => boolean | 'no-test',
common_setup: (config: Test, test_dir: string) => Promise<Common> | Common,
fn: (config: Test, test_dir: string, variant: Variants, common: Common) => void
) {
return {
test: (config: Test) => config,
run: async (cwd: string, samples_dir = 'samples') => {
await for_each_dir<Test>(cwd, samples_dir, (config, dir) => {
let called_common = false;
let common: any = undefined;
for (const variant of variants) {
if (should_skip_variant(variant, config, dir) === 'no-test') {
continue;
}
// TODO unify test interfaces
const skip = config.skip || should_skip_variant(variant, config, dir);
const solo = config.solo;
let it_fn = skip ? it.skip : solo ? it.only : it;
it_fn(`${dir} (${variant})`, async () => {
if (!called_common) {
called_common = true;
common = await common_setup(config, `${cwd}/${samples_dir}/${dir}`);
}
return fn(config, `${cwd}/${samples_dir}/${dir}`, variant, common);
});
}
});
}
};
}
// If a directory only contains these children, it's a sign that it's leftover
// from a different branch, and we can skip the test
const ignored = ['_output', '_actual.json'];
async function for_each_dir<Test extends BaseTest>(
cwd: string,
samples_dir = 'samples',
fn: (config: Test, test_dir: string) => void
) {
cwd = cwd.replace(/\\/g, '/');
let created_test = false;
for (const dir of fs.readdirSync(`${cwd}/${samples_dir}`)) {
if (dir[0] === '.' || !filter.test(dir)) continue;
if (fs.readdirSync(`${cwd}/${samples_dir}/${dir}`).every((file) => ignored.includes(file))) {
continue;
}
const file = `${cwd}/${samples_dir}/${dir}/_config.js`;
created_test = true;
const config = (fs.existsSync(file) ? (await import(file)).default : {}) as Test;
fn(config, dir);
}
if (!created_test) {
// prevent vitest from polluting the console with a "no tests found" message
it.skip(`[SKIP] ${cwd}`, () => {});
}
}
export function assert_ok(value: any): asserts value {
if (!value) {
throw new Error(`Expected truthy value, got ${value}`);
}
}
Domain
Subdomains
Types
Dependencies
- node:fs
- vitest
Imported By
Source
Frequently Asked Questions
What does suite.ts do?
suite.ts is a source file in the svelte codebase, written in typescript. It belongs to the BuildSystem domain, MessageProcessor subdomain.
What functions are defined in suite.ts?
suite.ts defines 4 function(s): assert_ok, for_each_dir, suite, suite_with_variants.
What does suite.ts depend on?
suite.ts imports 2 module(s): node:fs, vitest.
What files import suite.ts?
suite.ts is imported by 4 file(s): _config.js, test-ssr.ts, test.ts, test.ts.
Where is suite.ts in the architecture?
suite.ts is located at packages/svelte/tests/suite.ts (domain: BuildSystem, subdomain: MessageProcessor, directory: packages/svelte/tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free