chore(test): move some error tests out of runtime (#8600)

pull/8619/head
gtmnayan 1 year ago committed by GitHub
parent f223bc1c53
commit c2cec9597e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,48 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import { assert, describe, expect, it } from 'vitest';
import { compile } from '../../compiler.mjs';
const configs = import.meta.glob('./samples/*/_config.js', { import: 'default', eager: true });
describe('compiler-errors', () => {
function run_test(dir) {
if (dir[0] === '.') return;
const config = configs[`./samples/${dir}/_config.js`];
assert.ok(config, `Missing config for ${dir}`);
const solo = config.solo || /\.solo/.test(dir);
const it_fn = config.skip ? it.skip : solo ? it.only : it;
it_fn(dir, () => {
const cwd = path.resolve(`${__dirname}/samples/${dir}`);
const compileOptions = Object.assign({}, config.compileOptions || {}, {
format: 'cjs',
immutable: config.immutable,
accessors: 'accessors' in config ? config.accessors : true,
generate: 'dom'
});
try {
compile(fs.readFileSync(`${cwd}/main.svelte`, 'utf-8'), compileOptions);
} catch (error) {
if (typeof config.error === 'function') {
config.error(assert, error);
} else {
expect(error.message).toMatch(config.error);
}
return;
}
assert.fail('Expected an error');
});
}
const samples = fs.readdirSync(`${__dirname}/samples`);
samples.forEach((sample) => run_test(sample));
});

@ -1,5 +1,5 @@
<script>
import Nested from './Nested.svelte';
import Nested from './irrelevant';
</script>
<Nested>

@ -1,5 +1,5 @@
<script>
import Nested from './Nested.svelte';
import Nested from './irrelevant';
</script>
<Nested>

@ -1,5 +1,5 @@
<script>
import Nested from './Nested.svelte';
import Nested from './irrelevant';
</script>
<Nested>

@ -1,5 +1,5 @@
<script>
import Nested from './Nested.svelte';
import Nested from './irrelevant';
</script>
<Nested>

@ -1,5 +1,4 @@
export default {
error: [
error:
"Element with a slot='...' attribute must be a child of a component or a descendant of a custom element"
]
};

@ -1,5 +1,5 @@
<script>
import Nested from "./Nested.svelte";
import Nested from './irrelevant';
</script>
<Nested>

@ -1,5 +1,4 @@
export default {
error: [
error:
"Element with a slot='...' attribute must be a child of a component or a descendant of a custom element"
]
};

@ -1,5 +1,5 @@
<script>
import Nested from "./Nested.svelte";
import Nested from './irrelevant';
</script>
<Nested>

@ -1,5 +1,4 @@
export default {
error: [
error:
"Element with a slot='...' attribute must be a child of a component or a descendant of a custom element"
]
};

@ -1,5 +1,5 @@
<script>
import Nested from "./Nested.svelte";
import Nested from './irrelevant';
</script>
<Nested>

@ -1,5 +1,5 @@
<script context="module">
import foo from './foo.js';
const foo = {};
const answer = $foo;
</script>

@ -1,3 +0,0 @@
import { writable } from 'svelte/store';
export default writable(42);
Loading…
Cancel
Save