0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 01:11:24 +01:00
svelte/test/js/index.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

import * as assert from "assert";
2017-06-03 04:04:36 +02:00
import * as fs from "fs";
import * as path from "path";
import { loadConfig, svelte } from "../helpers.js";
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;
// 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-06-03 04:04:36 +02:00
if (solo && process.env.CI) {
throw new Error("Forgot to remove `solo: true` from test");
}
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);
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+$/, "");
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 {
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;
}
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, "")
);
});
});
});