mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Co-authored-by: Michael Rawlings <mirawlings@ebay.com> Co-authored-by: Dylan Piercey <dpiercey@ebay.com> Co-authored-by: Andrew Gliga <agliga@ebay.com>
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
import fs from "fs";
|
|
import path from "path";
|
|
import autotest from "mocha-autotest";
|
|
import stripAnsi from "strip-ansi";
|
|
import { compileFileSync } from "../src";
|
|
|
|
fs.readdirSync(path.join(__dirname, "../../"))
|
|
.map(dir => /^translator-(.*)|/.exec(dir)[1])
|
|
.filter(Boolean)
|
|
.forEach(translator => {
|
|
autotest(path.normalize(`../../translator-${translator}/test/fixtures`), {
|
|
html: runTest({ output: "html" }),
|
|
vdom: runTest({ output: "dom" }),
|
|
generated: runTest({ _parseOnly: true })
|
|
});
|
|
|
|
function runTest(config) {
|
|
return ({ mode, test, resolve, snapshot }) => {
|
|
const testConfigFile = resolve("test.js");
|
|
const testConfig = fs.existsSync(testConfigFile)
|
|
? require(testConfigFile)
|
|
: {};
|
|
const templateFile = resolve(
|
|
testConfig.templateFile || "template.marko"
|
|
);
|
|
|
|
const compilerConfig = {
|
|
...config,
|
|
babelConfig: {
|
|
babelrc: false,
|
|
configFile: false
|
|
},
|
|
writeVersionComment: false
|
|
};
|
|
|
|
test(() => {
|
|
let output;
|
|
try {
|
|
output = compileFileSync(templateFile, compilerConfig).code;
|
|
} catch (err) {
|
|
try {
|
|
snapshot(stripCwd(stripAnsi(err.message)), {
|
|
name: `${mode}-error`,
|
|
ext: ".txt"
|
|
});
|
|
return;
|
|
} catch {
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
snapshot(output, {
|
|
name: mode,
|
|
ext: mode === "generated" ? ".marko" : ".js"
|
|
});
|
|
});
|
|
};
|
|
}
|
|
});
|
|
|
|
function stripCwd(message) {
|
|
return message.replace(process.cwd() + "/", "");
|
|
}
|