2018-12-16 01:18:03 +01:00
|
|
|
import * as assert from "assert";
|
2017-06-03 04:04:36 +02:00
|
|
|
import * as fs from "fs";
|
|
|
|
import * as path from "path";
|
2017-08-18 01:04:07 +02:00
|
|
|
import { loadConfig, svelte } from "../helpers.js";
|
2017-04-04 18:05:54 +02:00
|
|
|
|
2018-04-13 18:02:07 +02:00
|
|
|
describe("js", () => {
|
2019-10-23 20:52:49 +02:00
|
|
|
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
|
2017-06-03 04:04:36 +02:00
|
|
|
if (dir[0] === ".") return;
|
2017-04-04 18:05:54 +02:00
|
|
|
|
|
|
|
// add .solo to a sample directory name to only run that test
|
2017-06-03 04:04:36 +02:00
|
|
|
const solo = /\.solo/.test(dir);
|
2017-04-04 18:05:54 +02:00
|
|
|
|
2017-06-03 04:04:36 +02:00
|
|
|
if (solo && process.env.CI) {
|
|
|
|
throw new Error("Forgot to remove `solo: true` from test");
|
2017-04-04 18:05:54 +02:00
|
|
|
}
|
|
|
|
|
2017-06-03 04:04:36 +02:00
|
|
|
(solo ? it.only : it)(dir, () => {
|
2019-10-23 20:52:49 +02:00
|
|
|
dir = path.resolve(`${__dirname}/samples`, dir);
|
2017-08-18 01:04:07 +02:00
|
|
|
const config = loadConfig(`${dir}/_config.js`);
|
|
|
|
|
2019-02-08 15:32:36 +01:00
|
|
|
const input = fs.readFileSync(`${dir}/input.svelte`, "utf-8").replace(/\s+$/, "");
|
2017-04-04 18:05:54 +02:00
|
|
|
|
2018-04-16 03:13:39 +02:00
|
|
|
let actual;
|
2017-04-17 03:57:00 +02:00
|
|
|
|
2018-04-16 03:13:39 +02:00
|
|
|
try {
|
2019-02-17 19:10:37 +01:00
|
|
|
const options = Object.assign(config.options || {});
|
2018-04-16 03:13:39 +02:00
|
|
|
|
2019-02-04 04:21:03 +01:00
|
|
|
actual = svelte.compile(input, options).js.code.replace(/generated by Svelte v\d+\.\d+\.\d+(-\w+\.\d+)?/, 'generated by Svelte vX.Y.Z');
|
2018-04-16 03:13:39 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err.frame);
|
|
|
|
throw err;
|
|
|
|
}
|
2017-08-18 01:04:07 +02:00
|
|
|
|
2018-04-16 03:13:39 +02:00
|
|
|
const output = `${dir}/_actual.js`;
|
|
|
|
fs.writeFileSync(output, actual);
|
2018-10-28 03:57:09 +01:00
|
|
|
|
|
|
|
const expected = fs.readFileSync(`${dir}/expected.js`, "utf-8");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
actual.trim().replace(/^[ \t]+$/gm, ""),
|
|
|
|
expected.trim().replace(/^[ \t]+$/gm, "")
|
|
|
|
);
|
2017-04-04 18:05:54 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|