|
|
|
@ -14,47 +14,41 @@ describe('vars', () => {
|
|
|
|
|
throw new Error('Forgot to remove `solo: true` from test');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(solo ? it.only : skip ? it.skip : it)(dir, () => {
|
|
|
|
|
const config = loadConfig(`./vars/samples/${dir}/_config.js`);
|
|
|
|
|
const filename = `test/vars/samples/${dir}/input.svelte`;
|
|
|
|
|
const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, '');
|
|
|
|
|
|
|
|
|
|
const expectedError = tryToLoadJson(
|
|
|
|
|
`test/vars/samples/${dir}/error.json`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let result;
|
|
|
|
|
let error;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
result = svelte.compile(input, config.options);
|
|
|
|
|
config.test(assert, result.vars);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || expectedError) {
|
|
|
|
|
if (error && !expectedError) {
|
|
|
|
|
throw error;
|
|
|
|
|
for (const generate of ['dom', 'ssr', false]) {
|
|
|
|
|
(solo ? it.only : skip ? it.skip : it)(`${dir}, generate: ${generate}`, () => {
|
|
|
|
|
const config = loadConfig(`./vars/samples/${dir}/_config.js`);
|
|
|
|
|
const filename = `test/vars/samples/${dir}/input.svelte`;
|
|
|
|
|
const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, '');
|
|
|
|
|
|
|
|
|
|
const expectedError = tryToLoadJson(
|
|
|
|
|
`test/vars/samples/${dir}/error.json`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let result;
|
|
|
|
|
let error;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
result = svelte.compile(input, { ...config.options, generate });
|
|
|
|
|
config.test(assert, result.vars);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (expectedError && !error) {
|
|
|
|
|
throw new Error(`Expected an error: ${expectedError.message}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.equal(error.message, expectedError.message);
|
|
|
|
|
assert.deepEqual(error.start, expectedError.start);
|
|
|
|
|
assert.deepEqual(error.end, expectedError.end);
|
|
|
|
|
assert.equal(error.pos, expectedError.pos);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
if (error || expectedError) {
|
|
|
|
|
if (error && !expectedError) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it('returns a vars object when options.generate is false', () => {
|
|
|
|
|
const { vars } = svelte.compile('', {
|
|
|
|
|
generate: false
|
|
|
|
|
});
|
|
|
|
|
if (expectedError && !error) {
|
|
|
|
|
throw new Error(`Expected an error: ${expectedError.message}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(vars));
|
|
|
|
|
assert.equal(error.message, expectedError.message);
|
|
|
|
|
assert.deepEqual(error.start, expectedError.start);
|
|
|
|
|
assert.deepEqual(error.end, expectedError.end);
|
|
|
|
|
assert.equal(error.pos, expectedError.pos);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|