/
write_tsconfig.spec.js
92 lines (80 loc) · 1.93 KB
/
write_tsconfig.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { assert, expect, test } from 'vitest';
import { validate_config } from '../config/index.js';
import { get_tsconfig } from './write_tsconfig.js';
test('Creates tsconfig path aliases from kit.alias', () => {
const { kit } = validate_config({
kit: {
alias: {
simpleKey: 'simple/value',
key: 'value',
'key/*': 'some/other/value/*',
keyToFile: 'path/to/file.ts'
}
}
});
const { compilerOptions } = get_tsconfig(kit);
// $lib isn't part of the outcome because there's a "path exists"
// check in the implementation
expect(compilerOptions.paths).toEqual({
simpleKey: ['../simple/value'],
'simpleKey/*': ['../simple/value/*'],
key: ['../value'],
'key/*': ['../some/other/value/*'],
keyToFile: ['../path/to/file.ts']
});
});
test('Allows generated tsconfig to be mutated', () => {
const { kit } = validate_config({
kit: {
typescript: {
config: (config) => {
config.extends = 'some/other/tsconfig.json';
}
}
}
});
const config = get_tsconfig(kit);
// @ts-expect-error
assert.equal(config.extends, 'some/other/tsconfig.json');
});
test('Allows generated tsconfig to be replaced', () => {
const { kit } = validate_config({
kit: {
typescript: {
config: (config) => ({
...config,
extends: 'some/other/tsconfig.json'
})
}
}
});
const config = get_tsconfig(kit);
// @ts-expect-error
assert.equal(config.extends, 'some/other/tsconfig.json');
});
test('Creates tsconfig include from kit.files', () => {
const { kit } = validate_config({
kit: {
files: {
lib: 'app'
}
}
});
const { include } = get_tsconfig(kit);
expect(include).toEqual([
'ambient.d.ts',
'non-ambient.d.ts',
'./types/**/$types.d.ts',
'../vite.config.js',
'../vite.config.ts',
'../app/**/*.js',
'../app/**/*.ts',
'../app/**/*.svelte',
'../src/**/*.js',
'../src/**/*.ts',
'../src/**/*.svelte',
'../tests/**/*.js',
'../tests/**/*.ts',
'../tests/**/*.svelte'
]);
});