Skip to content

Commit c2cec95

Browse files
authored
chore(test): move some error tests out of runtime (#8600)
1 parent f223bc1 commit c2cec95

File tree

37 files changed

+59
-24
lines changed

37 files changed

+59
-24
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as fs from 'node:fs';
2+
import * as path from 'node:path';
3+
import { assert, describe, expect, it } from 'vitest';
4+
import { compile } from '../../compiler.mjs';
5+
6+
const configs = import.meta.glob('./samples/*/_config.js', { import: 'default', eager: true });
7+
8+
describe('compiler-errors', () => {
9+
function run_test(dir) {
10+
if (dir[0] === '.') return;
11+
12+
const config = configs[`./samples/${dir}/_config.js`];
13+
14+
assert.ok(config, `Missing config for ${dir}`);
15+
16+
const solo = config.solo || /\.solo/.test(dir);
17+
18+
const it_fn = config.skip ? it.skip : solo ? it.only : it;
19+
20+
it_fn(dir, () => {
21+
const cwd = path.resolve(`${__dirname}/samples/${dir}`);
22+
23+
const compileOptions = Object.assign({}, config.compileOptions || {}, {
24+
format: 'cjs',
25+
immutable: config.immutable,
26+
accessors: 'accessors' in config ? config.accessors : true,
27+
generate: 'dom'
28+
});
29+
30+
try {
31+
compile(fs.readFileSync(`${cwd}/main.svelte`, 'utf-8'), compileOptions);
32+
} catch (error) {
33+
if (typeof config.error === 'function') {
34+
config.error(assert, error);
35+
} else {
36+
expect(error.message).toMatch(config.error);
37+
}
38+
39+
return;
40+
}
41+
42+
assert.fail('Expected an error');
43+
});
44+
}
45+
46+
const samples = fs.readdirSync(`${__dirname}/samples`);
47+
samples.forEach((sample) => run_test(sample));
48+
});

test/runtime/samples/component-slot-duplicate-error-2/main.svelte renamed to test/compiler-errors/samples/component-slot-duplicate-error-2/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import Nested from './Nested.svelte';
2+
import Nested from './irrelevant';
33
</script>
44

55
<Nested>

test/runtime/samples/component-slot-duplicate-error-3/main.svelte renamed to test/compiler-errors/samples/component-slot-duplicate-error-3/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import Nested from './Nested.svelte';
2+
import Nested from './irrelevant';
33
</script>
44

55
<Nested>

test/runtime/samples/component-slot-duplicate-error-4/main.svelte renamed to test/compiler-errors/samples/component-slot-duplicate-error-4/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import Nested from './Nested.svelte';
2+
import Nested from './irrelevant';
33
</script>
44

55
<Nested>

test/runtime/samples/component-slot-duplicate-error/main.svelte renamed to test/compiler-errors/samples/component-slot-duplicate-error/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import Nested from './Nested.svelte';
2+
import Nested from './irrelevant';
33
</script>
44

55
<Nested>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export default {
2-
error: [
2+
error:
33
"Element with a slot='...' attribute must be a child of a component or a descendant of a custom element"
4-
]
54
};

test/runtime/samples/component-slot-nested-error-2/main.svelte renamed to test/compiler-errors/samples/component-slot-nested-error-2/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import Nested from "./Nested.svelte";
2+
import Nested from './irrelevant';
33
</script>
44

55
<Nested>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export default {
2-
error: [
2+
error:
33
"Element with a slot='...' attribute must be a child of a component or a descendant of a custom element"
4-
]
54
};

test/runtime/samples/component-slot-nested-error-3/main.svelte renamed to test/compiler-errors/samples/component-slot-nested-error-3/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import Nested from "./Nested.svelte";
2+
import Nested from './irrelevant';
33
</script>
44

55
<Nested>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export default {
2-
error: [
2+
error:
33
"Element with a slot='...' attribute must be a child of a component or a descendant of a custom element"
4-
]
54
};

test/runtime/samples/component-slot-nested-error/main.svelte renamed to test/compiler-errors/samples/component-slot-nested-error/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import Nested from "./Nested.svelte";
2+
import Nested from './irrelevant';
33
</script>
44

55
<Nested>

test/runtime/samples/store-imported-module-b/main.svelte renamed to test/compiler-errors/samples/store-autosub-context-module/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script context="module">
2-
import foo from './foo.js';
2+
const foo = {};
33
const answer = $foo;
44
</script>
55

test/runtime/samples/component-slot-duplicate-error-2/Nested.svelte

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/runtime/samples/component-slot-duplicate-error-3/Nested.svelte

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/runtime/samples/component-slot-duplicate-error-4/Nested.svelte

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/runtime/samples/component-slot-duplicate-error/Nested.svelte

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/runtime/samples/component-slot-nested-error-2/Nested.svelte

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/runtime/samples/component-slot-nested-error-3/Nested.svelte

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/runtime/samples/component-slot-nested-error/Nested.svelte

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/runtime/samples/store-imported-module-b/foo.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)