|
|
|
@ -16,56 +16,49 @@ describe('parse', () => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(solo ? it.only : it)(dir, () => {
|
|
|
|
|
const input = fs
|
|
|
|
|
.readFileSync(`test/parser/samples/${dir}/input.html`, 'utf-8')
|
|
|
|
|
.replace(/\s+$/, '');
|
|
|
|
|
|
|
|
|
|
const input_v2 = fs
|
|
|
|
|
.readFileSync(`test/parser/samples/${dir}/input-v2.html`, 'utf-8')
|
|
|
|
|
.replace(/\s+$/, '');
|
|
|
|
|
|
|
|
|
|
const options = tryToLoadJson(`test/parser/samples/${dir}/options.json`) || {};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const actual = svelte.parse(input, options);
|
|
|
|
|
const expected = require(`./samples/${dir}/output.json`);
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
`test/parser/samples/${dir}/_actual.json`,
|
|
|
|
|
JSON.stringify(actual, null, '\t')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(actual.html, expected.html);
|
|
|
|
|
assert.deepEqual(actual.css, expected.css);
|
|
|
|
|
assert.deepEqual(actual.js, expected.js);
|
|
|
|
|
|
|
|
|
|
// TODO remove v1 tests
|
|
|
|
|
const actual_v2 = svelte.parse(input_v2, Object.assign({ parser: 'v2' }, options));
|
|
|
|
|
const expected_v2 = require(`./samples/${dir}/output-v2.json`);
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
`test/parser/samples/${dir}/_actual-v2.json`,
|
|
|
|
|
JSON.stringify(actual_v2, null, '\t')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(actual_v2.html, expected_v2.html);
|
|
|
|
|
assert.deepEqual(actual_v2.css, expected_v2.css);
|
|
|
|
|
assert.deepEqual(actual_v2.js, expected_v2.js);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (err.name !== 'ParseError') throw err;
|
|
|
|
|
|
|
|
|
|
function test(options, input, expectedOutput, expectedError, outputFile) {
|
|
|
|
|
try {
|
|
|
|
|
const expected = require(`./samples/${dir}/error.json`);
|
|
|
|
|
|
|
|
|
|
assert.equal(err.message, expected.message);
|
|
|
|
|
assert.deepEqual(err.loc, expected.loc);
|
|
|
|
|
assert.equal(err.pos, expected.pos);
|
|
|
|
|
assert.equal(err.toString().split('\n')[0], `${expected.message} (${expected.loc.line}:${expected.loc.column})`);
|
|
|
|
|
} catch (err2) {
|
|
|
|
|
const e = err2.code === 'MODULE_NOT_FOUND' ? err : err2;
|
|
|
|
|
throw e;
|
|
|
|
|
const actual = svelte.parse(input, options);
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(outputFile, JSON.stringify(actual, null, '\t'));
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(actual.html, expectedOutput.html);
|
|
|
|
|
assert.deepEqual(actual.css, expectedOutput.css);
|
|
|
|
|
assert.deepEqual(actual.js, expectedOutput.js);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (err.name !== 'ParseError') throw err;
|
|
|
|
|
if (!expectedError) throw err;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
assert.equal(err.message, expectedError.message);
|
|
|
|
|
assert.deepEqual(err.loc, expectedError.loc);
|
|
|
|
|
assert.equal(err.pos, expectedError.pos);
|
|
|
|
|
assert.equal(err.toString().split('\n')[0], `${expectedError.message} (${expectedError.loc.line}:${expectedError.loc.column})`);
|
|
|
|
|
} catch (err2) {
|
|
|
|
|
const e = err2.code === 'MODULE_NOT_FOUND' ? err : err2;
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO remove v1 tests
|
|
|
|
|
test(
|
|
|
|
|
options,
|
|
|
|
|
fs.readFileSync(`test/parser/samples/${dir}/input.html`, 'utf-8').replace(/\s+$/, ''),
|
|
|
|
|
tryToLoadJson(`test/parser/samples/${dir}/output.json`),
|
|
|
|
|
tryToLoadJson(`test/parser/samples/${dir}/error.json`),
|
|
|
|
|
`test/parser/samples/${dir}/_actual.json`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
Object.assign({ parser: 'v2' }, options),
|
|
|
|
|
fs.readFileSync(`test/parser/samples/${dir}/input-v2.html`, 'utf-8').replace(/\s+$/, ''),
|
|
|
|
|
tryToLoadJson(`test/parser/samples/${dir}/output-v2.json`),
|
|
|
|
|
tryToLoadJson(`test/parser/samples/${dir}/error-v2.json`),
|
|
|
|
|
`test/parser/samples/${dir}/_actual-v2.json`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|