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
ee73989Elm UI Automation
tests-rendering/automation/build.js+43−15
@@ -6,57 +6,85 @@ const compileToString = require("node-elm-compiler").compileToString;
6// template: "./tests-rendering/automation/templates/gather-styles.html",
6// template: "./tests-rendering/automation/templates/gather-styles.html",
7// target: "./tmp/test.html",
7// target: "./tmp/test.html",
8// elm: "src/Tests/Run.elm",
8// elm: "src/Tests/Run.elm",
9+// replace:
9// elmOptions: { cwd: "./tests-rendering" },
10// elmOptions: { cwd: "./tests-rendering" },
10// }
11// }
11
12
12async function compile_and_embed(config) {
13async function compile_and_embed(config) {
13− const template = fs.readFileSync(config.template);
14−
15 const elm_entry_module = fs.readFileSync(
14 const elm_entry_module = fs.readFileSync(
16 path.join(config.elmOptions.cwd, config.elm),
15 path.join(config.elmOptions.cwd, config.elm),
17 "utf8"
16 "utf8"
18 );
17 );
19− // console.log(elm_entry_module);
18+
20 const module_name = elm_entry_module
19 const module_name = elm_entry_module
21 .split(/[\r\n]+/)[0]
20 .split(/[\r\n]+/)[0]
22 .match(/module ([A-Za-z0-9\.]+)/i)[1];
21 .match(/module ([A-Za-z0-9\.]+)/i)[1];
23− // console.log(module_name);
24−
25− // throw "Ugh";
26
22
27 // we embed the compiled js to avoid having to start a server to read the app.
23 // we embed the compiled js to avoid having to start a server to read the app.
28 await compileToString([config.elm], config.elmOptions).then(function (
24 await compileToString([config.elm], config.elmOptions).then(function (
29 compiled_elm_code
25 compiled_elm_code
30 ) {
26 ) {
27+ // console.log(compiled_elm_code);
31− const compiled = eval(`\`${template}\``);
28+ const compiled = fs
29+ .readFileSync(config.template, "utf8")
30+ .replace(/~~_compiled_elm_code_~~/, () => compiled_elm_code)
31+ .replace(/~~_module_name_~~/, () => module_name);
32+
32 fs.writeFileSync(config.target, compiled);
33 fs.writeFileSync(config.target, compiled);
33 });
34 });
34}
35}
35
36
36async function compile_to_string(config) {
37async function compile_to_string(config) {
37− const template = fs.readFileSync(config.template);
38−
39 const elm_entry_module = fs.readFileSync(
38 const elm_entry_module = fs.readFileSync(
40 path.join(config.elmOptions.cwd, config.elm),
39 path.join(config.elmOptions.cwd, config.elm),
41 "utf8"
40 "utf8"
42 );
41 );
43− // console.log(elm_entry_module);
42+
44 const module_name = elm_entry_module
43 const module_name = elm_entry_module
45 .split(/[\r\n]+/)[0]
44 .split(/[\r\n]+/)[0]
46 .match(/module ([A-Za-z0-9\.]+)/i)[1];
45 .match(/module ([A-Za-z0-9\.]+)/i)[1];
47− // console.log(module_name);
48−
49− // throw "Ugh";
50
46
51− // we embed the compiled js to avoid having to start a server to read the app.
52 const compiled = await compileToString([config.elm], config.elmOptions).then(
47 const compiled = await compileToString([config.elm], config.elmOptions).then(
53 function (compiled_elm_code) {
48 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);
55 }
53 }
56 );
54 );
57 return compiled;
55 return compiled;
58}
56}
59
57
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+
60exports.compile_and_embed = compile_and_embed;
86exports.compile_and_embed = compile_and_embed;
61
87
88+exports.create_runner = create_runner;
89+
62exports.compile_to_string = compile_to_string;
90exports.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 @@
2<html>
2<html>
3 <head>
3 <head>
4 <meta charset="UTF-8" />
4 <meta charset="UTF-8" />
5− <title>Rendering Benchmark Viewer</title>
5+ <title>Elm UI Rendering Test</title>
6 <script>
6 <script>
7− ${compiled_elm_code}
7+ ~~_compiled_elm_code_~~
8 </script>
8 </script>
9 <script>
9 <script>
10 // Helpers
10 // Helpers
@@ -138,11 +138,10 @@
138
138
139 <script type="text/javascript">
139 <script type="text/javascript">
140 // Starting Elm App,
140 // Starting Elm App,
141− var app = Elm.${module_name}.init({
141+ var app = Elm.~~_module_name_~~.init({
142 node: document.getElementById("elm-home"),
142 node: document.getElementById("elm-home"),
143 });
143 });
144
144
145−
146 // create a canvas for text measurements
145 // create a canvas for text measurements
147 let canvas = createHiDPICanvas(200, 100, "canvas");
146 let canvas = createHiDPICanvas(200, 100, "canvas");
148
147
tests-rendering/automation/view.js+18−6
@@ -9,16 +9,16 @@ const http = require("http");
9
9
10var filepath = null;
10var filepath = null;
11program
11program
12− .option("--run", "run all the tests")
12+ .option("--all", "run all the tests")
13 .option("--debug", "run with debug on")
13 .option("--debug", "run with debug on")
14 .arguments("<filepath>")
14 .arguments("<filepath>")
15 .action(function (p) {
15 .action(function (p) {
16− filepath = path.join("./cases/open", p);
16+ test_filepath = path.join("./tests-rendering/cases/open", p);
17 })
17 })
18 .parse(process.argv);
18 .parse(process.argv);
19
19
20(async () => {
20(async () => {
21− if (filepath == null && !program.run) {
21+ if (test_filepath == null && !program.run) {
22 console.log("Open Cases");
22 console.log("Open Cases");
23 console.log("");
23 console.log("");
24 fs.readdirSync("./tests-rendering/cases/open").forEach((file) => {
24 fs.readdirSync("./tests-rendering/cases/open").forEach((file) => {
@@ -29,15 +29,27 @@ program
29 console.log("");
29 console.log("");
30 return;
30 return;
31 }
31 }
32+
32− if (program.run) {
33+ if (program.all) {
33− filepath = "./src/Tests/Run.elm";
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+ });
34 }
42 }
35− console.log("Compiling tests");
43+
44+ //
45+ // Compile and serve
46+
36 let content = await build.compile_to_string({
47 let content = await build.compile_to_string({
37 template: "./tests-rendering/automation/templates/gather-styles.html",
48 template: "./tests-rendering/automation/templates/gather-styles.html",
38 elm: filepath,
49 elm: filepath,
39 elmOptions: { cwd: "./tests-rendering", debug: program.debug },
50 elmOptions: { cwd: "./tests-rendering", debug: program.debug },
40 });
51 });
52+
41 console.log("Finished compiling");
53 console.log("Finished compiling");
42 // console.log(content);
54 // console.log(content);
43
55
tests-rendering/elm.json+21−24
@@ -1,28 +1,25 @@
1{
1{
2− "type": "application",
2+ "type": "application",
3− "source-directories": [
3+ "source-directories": ["src", "../src", "cases/open"],
4− "src",
5− "../src"
6− ],
7− "elm-version": "0.19.1",
4+ "elm-version": "0.19.1",
8− "dependencies": {
5+ "dependencies": {
9− "direct": {
6+ "direct": {
10− "elm/browser": "1.0.2",
7+ "elm/browser": "1.0.2",
11− "elm/core": "1.0.0",
8+ "elm/core": "1.0.0",
12− "elm/html": "1.0.0",
9+ "elm/html": "1.0.0",
13− "elm/json": "1.0.0",
10+ "elm/json": "1.0.0",
14− "elm/parser": "1.1.0",
11+ "elm/parser": "1.1.0",
15− "elm/random": "1.0.0",
12+ "elm/random": "1.0.0",
16− "elm/time": "1.0.0",
13+ "elm/time": "1.0.0",
17− "elm/virtual-dom": "1.0.2",
14+ "elm/virtual-dom": "1.0.2",
18− "elm-explorations/test": "1.1.0"
15+ "elm-explorations/test": "1.1.0"
19− },
20− "indirect": {
21− "elm/url": "1.0.0"
22− }
23 },
16 },
24− "test-dependencies": {
25− "direct": {},
26− "indirect": {}
17+ "indirect": {
18+ "elm/url": "1.0.0"
27 }
19 }
20+ },
21+ "test-dependencies": {
22+ "direct": {},
23+ "indirect": {}
24+ }
28}
25}