git.iko.soy/typeable/elm-ui
on master help sign in
update template viewer so we can both view a file and import it to the automation
commitee7398958f10869e7dfce78ad9ab63e15de5acc0 authorElm UI Automation <automation@elm-ui.com> dateFri 15 May 2020, 09:19 (6 years ago) parent2c582df
5 files changed+99−49
tests-rendering/automation/build.js+43−15 tests-rendering/automation/templates/Run.elm+14 tests-rendering/automation/templates/gather-styles.html+3−4 tests-rendering/automation/view.js+18−6 tests-rendering/elm.json+21−24
tests-rendering/automation/build.js+43−15
@@ -6,57 +6,85 @@ const compileToString = require("node-elm-compiler").compileToString;
66// template: "./tests-rendering/automation/templates/gather-styles.html",
77// target: "./tmp/test.html",
88// elm: "src/Tests/Run.elm",
9+// replace:
910// elmOptions: { cwd: "./tests-rendering" },
1011// }
1112
1213async function compile_and_embed(config) {
13− const template = fs.readFileSync(config.template);
14−
1514 const elm_entry_module = fs.readFileSync(
1615 path.join(config.elmOptions.cwd, config.elm),
1716 "utf8"
1817 );
19− // console.log(elm_entry_module);
18+
2019 const module_name = elm_entry_module
2120 .split(/[\r\n]+/)[0]
2221 .match(/module ([A-Za-z0-9\.]+)/i)[1];
23− // console.log(module_name);
24−
25− // throw "Ugh";
2622
2723 // we embed the compiled js to avoid having to start a server to read the app.
2824 await compileToString([config.elm], config.elmOptions).then(function (
2925 compiled_elm_code
3026 ) {
31− const compiled = eval(`\`${template}\``);
27+ // console.log(compiled_elm_code);
28+ const compiled = fs
29+ .readFileSync(config.template, "utf8")
30+ .replace(/~~_compiled_elm_code_~~/, () => compiled_elm_code)
31+ .replace(/~~_module_name_~~/, () => module_name);
32+
3233 fs.writeFileSync(config.target, compiled);
3334 });
3435}
3536
3637async function compile_to_string(config) {
37− const template = fs.readFileSync(config.template);
38−
3938 const elm_entry_module = fs.readFileSync(
4039 path.join(config.elmOptions.cwd, config.elm),
4140 "utf8"
4241 );
43− // console.log(elm_entry_module);
42+
4443 const module_name = elm_entry_module
4544 .split(/[\r\n]+/)[0]
4645 .match(/module ([A-Za-z0-9\.]+)/i)[1];
47− // console.log(module_name);
48−
49− // throw "Ugh";
5046
51− // we embed the compiled js to avoid having to start a server to read the app.
5247 const compiled = await compileToString([config.elm], config.elmOptions).then(
5348 function (compiled_elm_code) {
54− return eval(`\`${template}\``);
49+ return fs
50+ .readFileSync(config.template, "utf8")
51+ .replace(/~~_module_name_~~/g, () => module_name)
52+ .replace(/~~_compiled_elm_code_~~/g, () => compiled_elm_code);
5553 }
5654 );
5755 return compiled;
5856}
5957
58+async function get_module_name(config) {
59+ const elm_entry_module = fs.readFileSync(
60+ path.join(config.cwd, config.elm),
61+ "utf8"
62+ );
63+
64+ const module_name = elm_entry_module
65+ .split(/[\r\n]+/)[0]
66+ .match(/module ([A-Za-z0-9\.]+)/i)[1];
67+ return module_name;
68+}
69+
70+async function create_runner(config) {
71+ const elm_entry_module = fs.readFileSync(config.elm, "utf8");
72+
73+ let module_name = elm_entry_module
74+ .split(/[\r\n]+/)[0]
75+ .match(/module ([A-Za-z0-9\.]+)/i)[1];
76+
77+ const module_name_sentence = module_name.replace(/([A-Z])/g, " $1");
78+
79+ const runner = fs
80+ .readFileSync(config.template, "utf8")
81+ .replace(/~~_module_name_~~/g, () => module_name)
82+ .replace(/~~_module_name_sentence_~~/g, () => module_name_sentence);
83+ fs.writeFileSync(config.target, runner);
84+}
85+
6086exports.compile_and_embed = compile_and_embed;
6187
88+exports.create_runner = create_runner;
89+
6290exports.compile_to_string = compile_to_string;
tests-rendering/automation/templates/Run.elmnew file+14
@@ -0,0 +1,14 @@
1+module Tests.Run exposing (main)
2+
3+{-| _NOTE_ this is auto-generated! Notouchy!
4+-}
5+
6+import ~~_module_name_~~
7+import Testable.Runner
8+
9+
10+main : Testable.Runner.TestableProgram
11+main =
12+ Testable.Runner.program
13+ [ Testable.Runner.rename "~~_module_name_sentence_~~" ~~_module_name_~~.view
14+ ]
tests-rendering/automation/templates/gather-styles.html+3−4
@@ -2,9 +2,9 @@
22<html>
33 <head>
44 <meta charset="UTF-8" />
5− <title>Rendering Benchmark Viewer</title>
5+ <title>Elm UI Rendering Test</title>
66 <script>
7− ${compiled_elm_code}
7+ ~~_compiled_elm_code_~~
88 </script>
99 <script>
1010 // Helpers
@@ -138,11 +138,10 @@
138138
139139 <script type="text/javascript">
140140 // Starting Elm App,
141− var app = Elm.${module_name}.init({
141+ var app = Elm.~~_module_name_~~.init({
142142 node: document.getElementById("elm-home"),
143143 });
144144
145−
146145 // create a canvas for text measurements
147146 let canvas = createHiDPICanvas(200, 100, "canvas");
148147
tests-rendering/automation/view.js+18−6
@@ -9,16 +9,16 @@ const http = require("http");
99
1010var filepath = null;
1111program
12− .option("--run", "run all the tests")
12+ .option("--all", "run all the tests")
1313 .option("--debug", "run with debug on")
1414 .arguments("<filepath>")
1515 .action(function (p) {
16− filepath = path.join("./cases/open", p);
16+ test_filepath = path.join("./tests-rendering/cases/open", p);
1717 })
1818 .parse(process.argv);
1919
2020(async () => {
21− if (filepath == null && !program.run) {
21+ if (test_filepath == null && !program.run) {
2222 console.log("Open Cases");
2323 console.log("");
2424 fs.readdirSync("./tests-rendering/cases/open").forEach((file) => {
@@ -29,15 +29,27 @@ program
2929 console.log("");
3030 return;
3131 }
32− if (program.run) {
33− filepath = "./src/Tests/Run.elm";
32+
33+ if (program.all) {
34+ filepath = "./src/Tests/All.elm";
35+ } else {
36+ filepath = "src/Tests/Run.elm";
37+ build.create_runner({
38+ elm: test_filepath,
39+ template: "./tests-rendering/automation/templates/Run.elm",
40+ target: "./tests-rendering/src/Tests/Run.elm",
41+ });
3442 }
35− console.log("Compiling tests");
43+
44+ //
45+ // Compile and serve
46+
3647 let content = await build.compile_to_string({
3748 template: "./tests-rendering/automation/templates/gather-styles.html",
3849 elm: filepath,
3950 elmOptions: { cwd: "./tests-rendering", debug: program.debug },
4051 });
52+
4153 console.log("Finished compiling");
4254 // console.log(content);
4355
tests-rendering/elm.json+21−24
@@ -1,28 +1,25 @@
11{
2− "type": "application",
3− "source-directories": [
4− "src",
5− "../src"
6− ],
7− "elm-version": "0.19.1",
8− "dependencies": {
9− "direct": {
10− "elm/browser": "1.0.2",
11− "elm/core": "1.0.0",
12− "elm/html": "1.0.0",
13− "elm/json": "1.0.0",
14− "elm/parser": "1.1.0",
15− "elm/random": "1.0.0",
16− "elm/time": "1.0.0",
17− "elm/virtual-dom": "1.0.2",
18− "elm-explorations/test": "1.1.0"
19− },
20− "indirect": {
21− "elm/url": "1.0.0"
22− }
2+ "type": "application",
3+ "source-directories": ["src", "../src", "cases/open"],
4+ "elm-version": "0.19.1",
5+ "dependencies": {
6+ "direct": {
7+ "elm/browser": "1.0.2",
8+ "elm/core": "1.0.0",
9+ "elm/html": "1.0.0",
10+ "elm/json": "1.0.0",
11+ "elm/parser": "1.1.0",
12+ "elm/random": "1.0.0",
13+ "elm/time": "1.0.0",
14+ "elm/virtual-dom": "1.0.2",
15+ "elm-explorations/test": "1.1.0"
2316 },
24− "test-dependencies": {
25− "direct": {},
26− "indirect": {}
17+ "indirect": {
18+ "elm/url": "1.0.0"
2719 }
20+ },
21+ "test-dependencies": {
22+ "direct": {},
23+ "indirect": {}
24+ }
2825}