mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
6 years ago
|
import * as fs from 'fs';
|
||
|
import * as assert from 'assert';
|
||
4 years ago
|
import { svelte, loadConfig, tryToLoadJson } from '../helpers';
|
||
6 years ago
|
|
||
|
describe('vars', () => {
|
||
5 years ago
|
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
|
||
6 years ago
|
if (dir[0] === '.') return;
|
||
|
|
||
|
// add .solo to a sample directory name to only run that test
|
||
|
const solo = /\.solo/.test(dir);
|
||
|
const skip = /\.skip/.test(dir);
|
||
|
|
||
|
if (solo && process.env.CI) {
|
||
|
throw new Error('Forgot to remove `solo: true` from test');
|
||
|
}
|
||
|
|
||
6 years ago
|
for (const generate of ['dom', 'ssr', false]) {
|
||
|
(solo ? it.only : skip ? it.skip : it)(`${dir}, generate: ${generate}`, () => {
|
||
5 years ago
|
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);
|
||
|
const filename = `${__dirname}/samples/${dir}/input.svelte`;
|
||
6 years ago
|
const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, '');
|
||
|
|
||
|
const expectedError = tryToLoadJson(
|
||
5 years ago
|
`${__dirname}/samples/${dir}/error.json`
|
||
6 years ago
|
);
|
||
|
|
||
|
let result;
|
||
|
let error;
|
||
|
|
||
|
try {
|
||
|
result = svelte.compile(input, { ...config.options, generate });
|
||
|
config.test(assert, result.vars);
|
||
|
} catch (e) {
|
||
|
error = e;
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
if (error || expectedError) {
|
||
|
if (error && !expectedError) {
|
||
|
throw error;
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
if (expectedError && !error) {
|
||
|
throw new Error(`Expected an error: ${expectedError.message}`);
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
assert.equal(error.message, expectedError.message);
|
||
|
assert.deepEqual(error.start, expectedError.start);
|
||
|
assert.deepEqual(error.end, expectedError.end);
|
||
|
assert.equal(error.pos, expectedError.pos);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
6 years ago
|
});
|
||
|
});
|