From c2cec9597e1c59782ff6d830985dc65f1b1ec62d Mon Sep 17 00:00:00 2001
From: gtmnayan <50981692+gtm-nayan@users.noreply.github.com>
Date: Tue, 23 May 2023 21:26:06 +0545
Subject: [PATCH] chore(test): move some error tests out of runtime (#8600)
---
test/compiler-errors/compiler-errors.test.js | 48 +++++++++++++++++++
.../_config.js | 0
.../main.svelte | 2 +-
.../_config.js | 0
.../main.svelte | 2 +-
.../_config.js | 0
.../main.svelte | 2 +-
.../component-slot-duplicate-error/_config.js | 0
.../main.svelte | 2 +-
.../component-slot-nested-error-2/_config.js | 3 +-
.../component-slot-nested-error-2/main.svelte | 2 +-
.../component-slot-nested-error-3/_config.js | 3 +-
.../component-slot-nested-error-3/main.svelte | 2 +-
.../component-slot-nested-error/_config.js | 3 +-
.../component-slot-nested-error/main.svelte | 2 +-
.../_config.js | 0
.../main.svelte | 0
.../_config.js | 0
.../main.svelte | 0
.../store-autosub-context-module}/_config.js | 0
.../store-autosub-context-module}/main.svelte | 2 +-
.../samples/store-contextual/_config.js | 0
.../samples/store-contextual/main.svelte | 0
.../_config.js | 0
.../main.svelte | 0
.../samples/store-shadow-scope/_config.js | 0
.../samples/store-shadow-scope/main.svelte | 0
.../_config.js | 0
.../main.svelte | 0
.../Nested.svelte | 1 -
.../Nested.svelte | 1 -
.../Nested.svelte | 1 -
.../Nested.svelte | 1 -
.../Nested.svelte | 1 -
.../Nested.svelte | 1 -
.../component-slot-nested-error/Nested.svelte | 1 -
.../samples/store-imported-module-b/foo.js | 3 --
37 files changed, 59 insertions(+), 24 deletions(-)
create mode 100644 test/compiler-errors/compiler-errors.test.js
rename test/{runtime => compiler-errors}/samples/component-slot-duplicate-error-2/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/component-slot-duplicate-error-2/main.svelte (74%)
rename test/{runtime => compiler-errors}/samples/component-slot-duplicate-error-3/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/component-slot-duplicate-error-3/main.svelte (69%)
rename test/{runtime => compiler-errors}/samples/component-slot-duplicate-error-4/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/component-slot-duplicate-error-4/main.svelte (67%)
rename test/{runtime => compiler-errors}/samples/component-slot-duplicate-error/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/component-slot-duplicate-error/main.svelte (63%)
rename test/{runtime => compiler-errors}/samples/component-slot-nested-error-2/_config.js (90%)
rename test/{runtime => compiler-errors}/samples/component-slot-nested-error-2/main.svelte (74%)
rename test/{runtime => compiler-errors}/samples/component-slot-nested-error-3/_config.js (90%)
rename test/{runtime => compiler-errors}/samples/component-slot-nested-error-3/main.svelte (72%)
rename test/{runtime => compiler-errors}/samples/component-slot-nested-error/_config.js (90%)
rename test/{runtime => compiler-errors}/samples/component-slot-nested-error/main.svelte (69%)
rename test/{runtime => compiler-errors}/samples/dynamic-element-binding-invalid/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/dynamic-element-binding-invalid/main.svelte (100%)
rename test/{runtime => compiler-errors}/samples/each-block-destructured-default-before-initialised/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/each-block-destructured-default-before-initialised/main.svelte (100%)
rename test/{runtime/samples/store-imported-module-b => compiler-errors/samples/store-autosub-context-module}/_config.js (100%)
rename test/{runtime/samples/store-imported-module-b => compiler-errors/samples/store-autosub-context-module}/main.svelte (57%)
rename test/{runtime => compiler-errors}/samples/store-contextual/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/store-contextual/main.svelte (100%)
rename test/{runtime => compiler-errors}/samples/store-prevent-user-declarations/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/store-prevent-user-declarations/main.svelte (100%)
rename test/{runtime => compiler-errors}/samples/store-shadow-scope/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/store-shadow-scope/main.svelte (100%)
rename test/{runtime => compiler-errors}/samples/store-template-expression-scope/_config.js (100%)
rename test/{runtime => compiler-errors}/samples/store-template-expression-scope/main.svelte (100%)
delete mode 100644 test/runtime/samples/component-slot-duplicate-error-2/Nested.svelte
delete mode 100644 test/runtime/samples/component-slot-duplicate-error-3/Nested.svelte
delete mode 100644 test/runtime/samples/component-slot-duplicate-error-4/Nested.svelte
delete mode 100644 test/runtime/samples/component-slot-duplicate-error/Nested.svelte
delete mode 100644 test/runtime/samples/component-slot-nested-error-2/Nested.svelte
delete mode 100644 test/runtime/samples/component-slot-nested-error-3/Nested.svelte
delete mode 100644 test/runtime/samples/component-slot-nested-error/Nested.svelte
delete mode 100644 test/runtime/samples/store-imported-module-b/foo.js
diff --git a/test/compiler-errors/compiler-errors.test.js b/test/compiler-errors/compiler-errors.test.js
new file mode 100644
index 0000000000..6f8917aea9
--- /dev/null
+++ b/test/compiler-errors/compiler-errors.test.js
@@ -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));
+});
diff --git a/test/runtime/samples/component-slot-duplicate-error-2/_config.js b/test/compiler-errors/samples/component-slot-duplicate-error-2/_config.js
similarity index 100%
rename from test/runtime/samples/component-slot-duplicate-error-2/_config.js
rename to test/compiler-errors/samples/component-slot-duplicate-error-2/_config.js
diff --git a/test/runtime/samples/component-slot-duplicate-error-2/main.svelte b/test/compiler-errors/samples/component-slot-duplicate-error-2/main.svelte
similarity index 74%
rename from test/runtime/samples/component-slot-duplicate-error-2/main.svelte
rename to test/compiler-errors/samples/component-slot-duplicate-error-2/main.svelte
index fefa1dc861..b3c93db8f3 100644
--- a/test/runtime/samples/component-slot-duplicate-error-2/main.svelte
+++ b/test/compiler-errors/samples/component-slot-duplicate-error-2/main.svelte
@@ -1,5 +1,5 @@
diff --git a/test/runtime/samples/component-slot-duplicate-error-3/_config.js b/test/compiler-errors/samples/component-slot-duplicate-error-3/_config.js
similarity index 100%
rename from test/runtime/samples/component-slot-duplicate-error-3/_config.js
rename to test/compiler-errors/samples/component-slot-duplicate-error-3/_config.js
diff --git a/test/runtime/samples/component-slot-duplicate-error-3/main.svelte b/test/compiler-errors/samples/component-slot-duplicate-error-3/main.svelte
similarity index 69%
rename from test/runtime/samples/component-slot-duplicate-error-3/main.svelte
rename to test/compiler-errors/samples/component-slot-duplicate-error-3/main.svelte
index 596c1313d6..560ba7039d 100644
--- a/test/runtime/samples/component-slot-duplicate-error-3/main.svelte
+++ b/test/compiler-errors/samples/component-slot-duplicate-error-3/main.svelte
@@ -1,5 +1,5 @@
diff --git a/test/runtime/samples/component-slot-duplicate-error-4/_config.js b/test/compiler-errors/samples/component-slot-duplicate-error-4/_config.js
similarity index 100%
rename from test/runtime/samples/component-slot-duplicate-error-4/_config.js
rename to test/compiler-errors/samples/component-slot-duplicate-error-4/_config.js
diff --git a/test/runtime/samples/component-slot-duplicate-error-4/main.svelte b/test/compiler-errors/samples/component-slot-duplicate-error-4/main.svelte
similarity index 67%
rename from test/runtime/samples/component-slot-duplicate-error-4/main.svelte
rename to test/compiler-errors/samples/component-slot-duplicate-error-4/main.svelte
index ee1dcfad7b..6c8b870c95 100644
--- a/test/runtime/samples/component-slot-duplicate-error-4/main.svelte
+++ b/test/compiler-errors/samples/component-slot-duplicate-error-4/main.svelte
@@ -1,5 +1,5 @@
diff --git a/test/runtime/samples/component-slot-duplicate-error/_config.js b/test/compiler-errors/samples/component-slot-duplicate-error/_config.js
similarity index 100%
rename from test/runtime/samples/component-slot-duplicate-error/_config.js
rename to test/compiler-errors/samples/component-slot-duplicate-error/_config.js
diff --git a/test/runtime/samples/component-slot-duplicate-error/main.svelte b/test/compiler-errors/samples/component-slot-duplicate-error/main.svelte
similarity index 63%
rename from test/runtime/samples/component-slot-duplicate-error/main.svelte
rename to test/compiler-errors/samples/component-slot-duplicate-error/main.svelte
index 9024bcd46f..05475a3bf2 100644
--- a/test/runtime/samples/component-slot-duplicate-error/main.svelte
+++ b/test/compiler-errors/samples/component-slot-duplicate-error/main.svelte
@@ -1,5 +1,5 @@
diff --git a/test/runtime/samples/component-slot-nested-error-2/_config.js b/test/compiler-errors/samples/component-slot-nested-error-2/_config.js
similarity index 90%
rename from test/runtime/samples/component-slot-nested-error-2/_config.js
rename to test/compiler-errors/samples/component-slot-nested-error-2/_config.js
index afece8880b..8dbdda14f7 100644
--- a/test/runtime/samples/component-slot-nested-error-2/_config.js
+++ b/test/compiler-errors/samples/component-slot-nested-error-2/_config.js
@@ -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"
- ]
};
diff --git a/test/runtime/samples/component-slot-nested-error-2/main.svelte b/test/compiler-errors/samples/component-slot-nested-error-2/main.svelte
similarity index 74%
rename from test/runtime/samples/component-slot-nested-error-2/main.svelte
rename to test/compiler-errors/samples/component-slot-nested-error-2/main.svelte
index a7142d6dc1..f0ba192c4f 100644
--- a/test/runtime/samples/component-slot-nested-error-2/main.svelte
+++ b/test/compiler-errors/samples/component-slot-nested-error-2/main.svelte
@@ -1,5 +1,5 @@
diff --git a/test/runtime/samples/component-slot-nested-error-3/_config.js b/test/compiler-errors/samples/component-slot-nested-error-3/_config.js
similarity index 90%
rename from test/runtime/samples/component-slot-nested-error-3/_config.js
rename to test/compiler-errors/samples/component-slot-nested-error-3/_config.js
index afece8880b..8dbdda14f7 100644
--- a/test/runtime/samples/component-slot-nested-error-3/_config.js
+++ b/test/compiler-errors/samples/component-slot-nested-error-3/_config.js
@@ -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"
- ]
};
diff --git a/test/runtime/samples/component-slot-nested-error-3/main.svelte b/test/compiler-errors/samples/component-slot-nested-error-3/main.svelte
similarity index 72%
rename from test/runtime/samples/component-slot-nested-error-3/main.svelte
rename to test/compiler-errors/samples/component-slot-nested-error-3/main.svelte
index a63b1defde..3031292d04 100644
--- a/test/runtime/samples/component-slot-nested-error-3/main.svelte
+++ b/test/compiler-errors/samples/component-slot-nested-error-3/main.svelte
@@ -1,5 +1,5 @@
diff --git a/test/runtime/samples/component-slot-nested-error/_config.js b/test/compiler-errors/samples/component-slot-nested-error/_config.js
similarity index 90%
rename from test/runtime/samples/component-slot-nested-error/_config.js
rename to test/compiler-errors/samples/component-slot-nested-error/_config.js
index afece8880b..8dbdda14f7 100644
--- a/test/runtime/samples/component-slot-nested-error/_config.js
+++ b/test/compiler-errors/samples/component-slot-nested-error/_config.js
@@ -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"
- ]
};
diff --git a/test/runtime/samples/component-slot-nested-error/main.svelte b/test/compiler-errors/samples/component-slot-nested-error/main.svelte
similarity index 69%
rename from test/runtime/samples/component-slot-nested-error/main.svelte
rename to test/compiler-errors/samples/component-slot-nested-error/main.svelte
index 531c96f08c..5f251ea625 100644
--- a/test/runtime/samples/component-slot-nested-error/main.svelte
+++ b/test/compiler-errors/samples/component-slot-nested-error/main.svelte
@@ -1,5 +1,5 @@
diff --git a/test/runtime/samples/dynamic-element-binding-invalid/_config.js b/test/compiler-errors/samples/dynamic-element-binding-invalid/_config.js
similarity index 100%
rename from test/runtime/samples/dynamic-element-binding-invalid/_config.js
rename to test/compiler-errors/samples/dynamic-element-binding-invalid/_config.js
diff --git a/test/runtime/samples/dynamic-element-binding-invalid/main.svelte b/test/compiler-errors/samples/dynamic-element-binding-invalid/main.svelte
similarity index 100%
rename from test/runtime/samples/dynamic-element-binding-invalid/main.svelte
rename to test/compiler-errors/samples/dynamic-element-binding-invalid/main.svelte
diff --git a/test/runtime/samples/each-block-destructured-default-before-initialised/_config.js b/test/compiler-errors/samples/each-block-destructured-default-before-initialised/_config.js
similarity index 100%
rename from test/runtime/samples/each-block-destructured-default-before-initialised/_config.js
rename to test/compiler-errors/samples/each-block-destructured-default-before-initialised/_config.js
diff --git a/test/runtime/samples/each-block-destructured-default-before-initialised/main.svelte b/test/compiler-errors/samples/each-block-destructured-default-before-initialised/main.svelte
similarity index 100%
rename from test/runtime/samples/each-block-destructured-default-before-initialised/main.svelte
rename to test/compiler-errors/samples/each-block-destructured-default-before-initialised/main.svelte
diff --git a/test/runtime/samples/store-imported-module-b/_config.js b/test/compiler-errors/samples/store-autosub-context-module/_config.js
similarity index 100%
rename from test/runtime/samples/store-imported-module-b/_config.js
rename to test/compiler-errors/samples/store-autosub-context-module/_config.js
diff --git a/test/runtime/samples/store-imported-module-b/main.svelte b/test/compiler-errors/samples/store-autosub-context-module/main.svelte
similarity index 57%
rename from test/runtime/samples/store-imported-module-b/main.svelte
rename to test/compiler-errors/samples/store-autosub-context-module/main.svelte
index 7abc91d4ed..9c5d168793 100644
--- a/test/runtime/samples/store-imported-module-b/main.svelte
+++ b/test/compiler-errors/samples/store-autosub-context-module/main.svelte
@@ -1,5 +1,5 @@
diff --git a/test/runtime/samples/store-contextual/_config.js b/test/compiler-errors/samples/store-contextual/_config.js
similarity index 100%
rename from test/runtime/samples/store-contextual/_config.js
rename to test/compiler-errors/samples/store-contextual/_config.js
diff --git a/test/runtime/samples/store-contextual/main.svelte b/test/compiler-errors/samples/store-contextual/main.svelte
similarity index 100%
rename from test/runtime/samples/store-contextual/main.svelte
rename to test/compiler-errors/samples/store-contextual/main.svelte
diff --git a/test/runtime/samples/store-prevent-user-declarations/_config.js b/test/compiler-errors/samples/store-prevent-user-declarations/_config.js
similarity index 100%
rename from test/runtime/samples/store-prevent-user-declarations/_config.js
rename to test/compiler-errors/samples/store-prevent-user-declarations/_config.js
diff --git a/test/runtime/samples/store-prevent-user-declarations/main.svelte b/test/compiler-errors/samples/store-prevent-user-declarations/main.svelte
similarity index 100%
rename from test/runtime/samples/store-prevent-user-declarations/main.svelte
rename to test/compiler-errors/samples/store-prevent-user-declarations/main.svelte
diff --git a/test/runtime/samples/store-shadow-scope/_config.js b/test/compiler-errors/samples/store-shadow-scope/_config.js
similarity index 100%
rename from test/runtime/samples/store-shadow-scope/_config.js
rename to test/compiler-errors/samples/store-shadow-scope/_config.js
diff --git a/test/runtime/samples/store-shadow-scope/main.svelte b/test/compiler-errors/samples/store-shadow-scope/main.svelte
similarity index 100%
rename from test/runtime/samples/store-shadow-scope/main.svelte
rename to test/compiler-errors/samples/store-shadow-scope/main.svelte
diff --git a/test/runtime/samples/store-template-expression-scope/_config.js b/test/compiler-errors/samples/store-template-expression-scope/_config.js
similarity index 100%
rename from test/runtime/samples/store-template-expression-scope/_config.js
rename to test/compiler-errors/samples/store-template-expression-scope/_config.js
diff --git a/test/runtime/samples/store-template-expression-scope/main.svelte b/test/compiler-errors/samples/store-template-expression-scope/main.svelte
similarity index 100%
rename from test/runtime/samples/store-template-expression-scope/main.svelte
rename to test/compiler-errors/samples/store-template-expression-scope/main.svelte
diff --git a/test/runtime/samples/component-slot-duplicate-error-2/Nested.svelte b/test/runtime/samples/component-slot-duplicate-error-2/Nested.svelte
deleted file mode 100644
index 32eee1534a..0000000000
--- a/test/runtime/samples/component-slot-duplicate-error-2/Nested.svelte
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/test/runtime/samples/component-slot-duplicate-error-3/Nested.svelte b/test/runtime/samples/component-slot-duplicate-error-3/Nested.svelte
deleted file mode 100644
index 32eee1534a..0000000000
--- a/test/runtime/samples/component-slot-duplicate-error-3/Nested.svelte
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/test/runtime/samples/component-slot-duplicate-error-4/Nested.svelte b/test/runtime/samples/component-slot-duplicate-error-4/Nested.svelte
deleted file mode 100644
index 0385342cef..0000000000
--- a/test/runtime/samples/component-slot-duplicate-error-4/Nested.svelte
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/test/runtime/samples/component-slot-duplicate-error/Nested.svelte b/test/runtime/samples/component-slot-duplicate-error/Nested.svelte
deleted file mode 100644
index 32eee1534a..0000000000
--- a/test/runtime/samples/component-slot-duplicate-error/Nested.svelte
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/test/runtime/samples/component-slot-nested-error-2/Nested.svelte b/test/runtime/samples/component-slot-nested-error-2/Nested.svelte
deleted file mode 100644
index c6f086d96c..0000000000
--- a/test/runtime/samples/component-slot-nested-error-2/Nested.svelte
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/test/runtime/samples/component-slot-nested-error-3/Nested.svelte b/test/runtime/samples/component-slot-nested-error-3/Nested.svelte
deleted file mode 100644
index c6f086d96c..0000000000
--- a/test/runtime/samples/component-slot-nested-error-3/Nested.svelte
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/test/runtime/samples/component-slot-nested-error/Nested.svelte b/test/runtime/samples/component-slot-nested-error/Nested.svelte
deleted file mode 100644
index c6f086d96c..0000000000
--- a/test/runtime/samples/component-slot-nested-error/Nested.svelte
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/test/runtime/samples/store-imported-module-b/foo.js b/test/runtime/samples/store-imported-module-b/foo.js
deleted file mode 100644
index b88c1cc577..0000000000
--- a/test/runtime/samples/store-imported-module-b/foo.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import { writable } from 'svelte/store';
-
-export default writable(42);