update template viewer so we can both view a file and import it to the automation

This commit is contained in:
Elm UI Automation 2020-05-15 09:19:13 -04:00
parent 2c582df903
commit ee7398958f
5 changed files with 99 additions and 49 deletions

View File

@ -6,57 +6,85 @@ const compileToString = require("node-elm-compiler").compileToString;
// template: "./tests-rendering/automation/templates/gather-styles.html",
// target: "./tmp/test.html",
// elm: "src/Tests/Run.elm",
// replace:
// elmOptions: { cwd: "./tests-rendering" },
// }
async function compile_and_embed(config) {
const template = fs.readFileSync(config.template);
const elm_entry_module = fs.readFileSync(
path.join(config.elmOptions.cwd, config.elm),
"utf8"
);
// console.log(elm_entry_module);
const module_name = elm_entry_module
.split(/[\r\n]+/)[0]
.match(/module ([A-Za-z0-9\.]+)/i)[1];
// console.log(module_name);
// throw "Ugh";
// we embed the compiled js to avoid having to start a server to read the app.
await compileToString([config.elm], config.elmOptions).then(function (
compiled_elm_code
) {
const compiled = eval(`\`${template}\``);
// console.log(compiled_elm_code);
const compiled = fs
.readFileSync(config.template, "utf8")
.replace(/~~_compiled_elm_code_~~/, () => compiled_elm_code)
.replace(/~~_module_name_~~/, () => module_name);
fs.writeFileSync(config.target, compiled);
});
}
async function compile_to_string(config) {
const template = fs.readFileSync(config.template);
const elm_entry_module = fs.readFileSync(
path.join(config.elmOptions.cwd, config.elm),
"utf8"
);
// console.log(elm_entry_module);
const module_name = elm_entry_module
.split(/[\r\n]+/)[0]
.match(/module ([A-Za-z0-9\.]+)/i)[1];
// console.log(module_name);
// throw "Ugh";
// we embed the compiled js to avoid having to start a server to read the app.
const compiled = await compileToString([config.elm], config.elmOptions).then(
function (compiled_elm_code) {
return eval(`\`${template}\``);
return fs
.readFileSync(config.template, "utf8")
.replace(/~~_module_name_~~/g, () => module_name)
.replace(/~~_compiled_elm_code_~~/g, () => compiled_elm_code);
}
);
return compiled;
}
async function get_module_name(config) {
const elm_entry_module = fs.readFileSync(
path.join(config.cwd, config.elm),
"utf8"
);
const module_name = elm_entry_module
.split(/[\r\n]+/)[0]
.match(/module ([A-Za-z0-9\.]+)/i)[1];
return module_name;
}
async function create_runner(config) {
const elm_entry_module = fs.readFileSync(config.elm, "utf8");
let module_name = elm_entry_module
.split(/[\r\n]+/)[0]
.match(/module ([A-Za-z0-9\.]+)/i)[1];
const module_name_sentence = module_name.replace(/([A-Z])/g, " $1");
const runner = fs
.readFileSync(config.template, "utf8")
.replace(/~~_module_name_~~/g, () => module_name)
.replace(/~~_module_name_sentence_~~/g, () => module_name_sentence);
fs.writeFileSync(config.target, runner);
}
exports.compile_and_embed = compile_and_embed;
exports.create_runner = create_runner;
exports.compile_to_string = compile_to_string;

View File

@ -0,0 +1,14 @@
module Tests.Run exposing (main)
{-| _NOTE_ this is auto-generated! Notouchy!
-}
import ~~_module_name_~~
import Testable.Runner
main : Testable.Runner.TestableProgram
main =
Testable.Runner.program
[ Testable.Runner.rename "~~_module_name_sentence_~~" ~~_module_name_~~.view
]

View File

@ -2,9 +2,9 @@
<html>
<head>
<meta charset="UTF-8" />
<title>Rendering Benchmark Viewer</title>
<title>Elm UI Rendering Test</title>
<script>
${compiled_elm_code}
~~_compiled_elm_code_~~
</script>
<script>
// Helpers
@ -138,11 +138,10 @@
<script type="text/javascript">
// Starting Elm App,
var app = Elm.${module_name}.init({
var app = Elm.~~_module_name_~~.init({
node: document.getElementById("elm-home"),
});
// create a canvas for text measurements
let canvas = createHiDPICanvas(200, 100, "canvas");

View File

@ -9,16 +9,16 @@ const http = require("http");
var filepath = null;
program
.option("--run", "run all the tests")
.option("--all", "run all the tests")
.option("--debug", "run with debug on")
.arguments("<filepath>")
.action(function (p) {
filepath = path.join("./cases/open", p);
test_filepath = path.join("./tests-rendering/cases/open", p);
})
.parse(process.argv);
(async () => {
if (filepath == null && !program.run) {
if (test_filepath == null && !program.run) {
console.log("Open Cases");
console.log("");
fs.readdirSync("./tests-rendering/cases/open").forEach((file) => {
@ -29,15 +29,27 @@ program
console.log("");
return;
}
if (program.run) {
filepath = "./src/Tests/Run.elm";
if (program.all) {
filepath = "./src/Tests/All.elm";
} else {
filepath = "src/Tests/Run.elm";
build.create_runner({
elm: test_filepath,
template: "./tests-rendering/automation/templates/Run.elm",
target: "./tests-rendering/src/Tests/Run.elm",
});
}
console.log("Compiling tests");
//
// Compile and serve
let content = await build.compile_to_string({
template: "./tests-rendering/automation/templates/gather-styles.html",
elm: filepath,
elmOptions: { cwd: "./tests-rendering", debug: program.debug },
});
console.log("Finished compiling");
// console.log(content);

View File

@ -1,9 +1,6 @@
{
"type": "application",
"source-directories": [
"src",
"../src"
],
"source-directories": ["src", "../src", "cases/open"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {