diff --git a/packages/subapp-server/lib/fastify-plugin.js b/packages/subapp-server/lib/fastify-plugin.js
index 4dc971b9e..6d418366a 100644
--- a/packages/subapp-server/lib/fastify-plugin.js
+++ b/packages/subapp-server/lib/fastify-plugin.js
@@ -49,7 +49,7 @@ module.exports = {
request
});
- const data = context.result;
+ const data = context.result;
const status = data.status;
if (data instanceof Error) {
diff --git a/packages/subapp-server/package.json b/packages/subapp-server/package.json
index 954f05f92..496de8389 100644
--- a/packages/subapp-server/package.json
+++ b/packages/subapp-server/package.json
@@ -28,8 +28,7 @@
],
"dependencies": {
"@hapi/boom": "^7.4.1",
- "@xarc/webapp": "../../packages/xarc-webapp",
- "@xarc/jsx-renderer": "^1.0.0",
+ "@xarc/webapp": "^1.0.0",
"filter-scan-dir": "^1.0.9",
"http-status-codes": "^1.3.0",
"optional-require": "^1.0.0",
@@ -49,7 +48,7 @@
},
"fyn": {
"dependencies": {
- "@xarc/webapp": "../../packages/xarc-webapp",
+ "@xarc/webapp": "../xarc-webapp",
"subapp-util": "../subapp-util",
"@xarc/jsx-renderer": "../xarc-jsx-renderer"
}
diff --git a/packages/xarc-jsx-renderer/package.json b/packages/xarc-jsx-renderer/package.json
index 1957c2338..949c11f39 100644
--- a/packages/xarc-jsx-renderer/package.json
+++ b/packages/xarc-jsx-renderer/package.json
@@ -70,7 +70,7 @@
"trailingComma": "none"
},
"dependencies": {
- "@xarc/render-context": "../xarc-render-context",
+ "@xarc/render-context": "^1.0.0",
"lodash": "^4.17.15",
"munchy": "^1.0.7",
"optional-require": "^1.0.0",
diff --git a/packages/xarc-jsx-renderer/tsconfig.json b/packages/xarc-jsx-renderer/tsconfig.json
index f28c571de..42cfc55c6 100644
--- a/packages/xarc-jsx-renderer/tsconfig.json
+++ b/packages/xarc-jsx-renderer/tsconfig.json
@@ -15,10 +15,5 @@
"strictFunctionTypes": true,
"jsx": "react"
},
- "include": [
- "src",
- "../xarc-render-context/src/symbols.ts",
- "../xarc-render-context/src/TokenModule.ts",
- "../xarc-render-context/src/load-handler.ts"
- ]
+ "include": ["src"]
}
diff --git a/packages/xarc-simple-renderer/package.json b/packages/xarc-simple-renderer/package.json
index 76d6fc0ac..a355dd58d 100644
--- a/packages/xarc-simple-renderer/package.json
+++ b/packages/xarc-simple-renderer/package.json
@@ -36,7 +36,7 @@
"typedoc": "^0.17.4",
"typescript": "^3.8.3",
"xstdout": "^0.1.1",
- "@xarc/render-context": "../../packages/xarc-render-context"
+ "@xarc/render-context": "^1.0.0"
},
"mocha": {
"require": [
@@ -79,5 +79,10 @@
"functions": 100,
"lines": 100,
"cache": false
+ },
+ "fyn": {
+ "devDependencies": {
+ "@xarc/render-context": "../xarc-render-context"
+ }
}
}
diff --git a/packages/xarc-webapp/package.json b/packages/xarc-webapp/package.json
index 92d74ad9c..1af88278b 100644
--- a/packages/xarc-webapp/package.json
+++ b/packages/xarc-webapp/package.json
@@ -17,10 +17,10 @@
"webapp"
],
"dependencies": {
- "@xarc/jsx-renderer": "file:../xarc-jsx-renderer",
+ "@xarc/jsx-renderer": "^1.0.0",
"@xarc/module-dev": "^2.1.1",
- "@xarc/render-context": "file:../xarc-render-context",
- "@xarc/simple-renderer": "file:../xarc-simple-renderer",
+ "@xarc/render-context": "^1.0.0",
+ "@xarc/simple-renderer": "^1.0.0",
"ts-node": "^8.10.2",
"typescript": "^3.9.5",
"xclap": "^0.2.51",
diff --git a/packages/xarc-webapp/src/webapp.ts b/packages/xarc-webapp/src/webapp.ts
index 0554e89f8..6885a9eea 100644
--- a/packages/xarc-webapp/src/webapp.ts
+++ b/packages/xarc-webapp/src/webapp.ts
@@ -62,7 +62,7 @@ function initializeTemplate(
asyncTemplate.initializeRenderer();
} else {
const templateFullPath = resolvePath(tmplFile);
- const template = resolvePath(tmplFile);
+ const template = require(templateFullPath);
asyncTemplate = new JsxRenderer({
templateFullPath: Path.dirname(templateFullPath),
template: _.get(template, "default", template),
diff --git a/packages/xarc-webapp/test/data/bad-content.js b/packages/xarc-webapp/test/data/bad-content.js
new file mode 100644
index 000000000..2bc93b984
--- /dev/null
+++ b/packages/xarc-webapp/test/data/bad-content.js
@@ -0,0 +1,3 @@
+/* eslint-disable */
+
+require("foo-blah");
diff --git a/packages/xarc-webapp/test/data/chunk-selector.js b/packages/xarc-webapp/test/data/chunk-selector.js
new file mode 100644
index 000000000..fe9a3b56c
--- /dev/null
+++ b/packages/xarc-webapp/test/data/chunk-selector.js
@@ -0,0 +1,32 @@
+"use strict";
+
+const FOO_BUNDLE = {
+ css: "foo",
+ js: "foo"
+};
+const BAR_BUNDLE = {
+ css: "bar",
+ js: "bar"
+};
+const DEFAULT_BUNDLE = {
+ css: "home",
+ js: "home"
+};
+const MULTI_BUNDLE = {
+ css: ["foo", "bar"],
+ js: "home"
+};
+
+module.exports = request => {
+ if (request.path.endsWith("/foo")) {
+ return FOO_BUNDLE;
+ } else if (request.path.endsWith("/bar")) {
+ return BAR_BUNDLE;
+ } else if (request.path.endsWith("/multi-chunk")) {
+ return MULTI_BUNDLE;
+ } else if (request.path.endsWith("/empty")) {
+ return {};
+ }
+
+ return DEFAULT_BUNDLE;
+};
diff --git a/packages/xarc-webapp/test/data/critical.css b/packages/xarc-webapp/test/data/critical.css
new file mode 100644
index 000000000..563d20e99
--- /dev/null
+++ b/packages/xarc-webapp/test/data/critical.css
@@ -0,0 +1,3 @@
+body {
+ color: green;
+}
diff --git a/packages/xarc-webapp/test/data/foo.js b/packages/xarc-webapp/test/data/foo.js
new file mode 100644
index 000000000..80e295b96
--- /dev/null
+++ b/packages/xarc-webapp/test/data/foo.js
@@ -0,0 +1 @@
+module.exports = "hello";
diff --git a/packages/xarc-webapp/test/data/icon-stats-empty.json b/packages/xarc-webapp/test/data/icon-stats-empty.json
new file mode 100644
index 000000000..6d6f06a49
--- /dev/null
+++ b/packages/xarc-webapp/test/data/icon-stats-empty.json
@@ -0,0 +1,3 @@
+{
+ "empty": true
+}
diff --git a/packages/xarc-webapp/test/data/icon-stats-test-pwa.json b/packages/xarc-webapp/test/data/icon-stats-test-pwa.json
new file mode 100644
index 000000000..1e2974dc3
--- /dev/null
+++ b/packages/xarc-webapp/test/data/icon-stats-test-pwa.json
@@ -0,0 +1,7 @@
+{
+ "html": [
+ "",
+ "",
+ ""
+ ]
+}
diff --git a/packages/xarc-webapp/test/data/index-1.html b/packages/xarc-webapp/test/data/index-1.html
new file mode 100644
index 000000000..25061af8c
--- /dev/null
+++ b/packages/xarc-webapp/test/data/index-1.html
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test html-1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/index-2.html b/packages/xarc-webapp/test/data/index-2.html
new file mode 100644
index 000000000..ccac1bb1f
--- /dev/null
+++ b/packages/xarc-webapp/test/data/index-2.html
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test html-2
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/perf-1.html b/packages/xarc-webapp/test/data/perf-1.html
new file mode 100644
index 000000000..7044a06d7
--- /dev/null
+++ b/packages/xarc-webapp/test/data/perf-1.html
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test perf 1 html
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/stats-test-multibundle.json b/packages/xarc-webapp/test/data/stats-test-multibundle.json
new file mode 100644
index 000000000..b0c3b1bc9
--- /dev/null
+++ b/packages/xarc-webapp/test/data/stats-test-multibundle.json
@@ -0,0 +1,71 @@
+{
+ "assetsByChunkName": {
+ "foo": [
+ "foo.bundle.f07a873ce87fc904a6a5.js",
+ "foo.style.f07a873ce87fc904a6a5.css"
+ ],
+ "bar": [
+ "bar.bundle.f07a873ce87fc904a6a5.js",
+ "bar.style.f07a873ce87fc904a6a5.css"
+ ],
+ "home": [
+ "home.bundle.f07a873ce87fc904a6a5.js",
+ "home.style.f07a873ce87fc904a6a5.css"
+ ]
+ },
+ "assets": [{
+ "name": "foo.style.f07a873ce87fc904a6a5.css",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "foo"
+ ]
+ }, {
+ "name": "foo.bundle.f07a873ce87fc904a6a5.js",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "foo"
+ ]
+ }, {
+ "name": "bar.style.f07a873ce87fc904a6a5.css",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "bar"
+ ]
+ }, {
+ "name": "bar.bundle.f07a873ce87fc904a6a5.js",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "bar"
+ ]
+ }, {
+ "name": "home.style.f07a873ce87fc904a6a5.css",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "home"
+ ]
+ }, {
+ "name": "home.bundle.f07a873ce87fc904a6a5.js",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "home"
+ ]
+ }]
+}
diff --git a/packages/xarc-webapp/test/data/stats-test-one-bundle.json b/packages/xarc-webapp/test/data/stats-test-one-bundle.json
new file mode 100644
index 000000000..42edae47e
--- /dev/null
+++ b/packages/xarc-webapp/test/data/stats-test-one-bundle.json
@@ -0,0 +1,27 @@
+{
+ "assetsByChunkName": {
+ "bundle": [
+ "bundle.f07a873ce87fc904a6a5.js",
+ "style.f07a873ce87fc904a6a5.css"
+ ]
+ },
+ "assets": [{
+ "name": "style.f07a873ce87fc904a6a5.css",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "main"
+ ]
+ }, {
+ "name": "bundle.f07a873ce87fc904a6a5.js",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "main"
+ ]
+ }]
+}
diff --git a/packages/xarc-webapp/test/data/stats-test-pwa.json b/packages/xarc-webapp/test/data/stats-test-pwa.json
new file mode 100644
index 000000000..e937fef13
--- /dev/null
+++ b/packages/xarc-webapp/test/data/stats-test-pwa.json
@@ -0,0 +1,36 @@
+{
+ "assetsByChunkName": {
+ "bundle": [
+ "bundle.f07a873ce87fc904a6a5.js",
+ "style.f07a873ce87fc904a6a5.css"
+ ],
+ "bar": [
+ "bar.bundle.f07a873ce87fc904a6a5.js",
+ "bar.style.f07a873ce87fc904a6a5.css"
+ ]
+ },
+ "assets": [{
+ "name": "style.f07a873ce87fc904a6a5.css",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "bundle"
+ ]
+ }, {
+ "name": "bundle.f07a873ce87fc904a6a5.js",
+ "size": 888,
+ "chunks": [
+ 0
+ ],
+ "chunkNames": [
+ "bundle"
+ ]
+ }, {
+ "name": "manifest.json",
+ "size": 888,
+ "chunks": [],
+ "chunkNames": []
+ }]
+}
diff --git a/packages/xarc-webapp/test/data/style2.css b/packages/xarc-webapp/test/data/style2.css
new file mode 100644
index 000000000..6446ebfd4
--- /dev/null
+++ b/packages/xarc-webapp/test/data/style2.css
@@ -0,0 +1,3 @@
+.test {
+ color: red;
+}
diff --git a/packages/xarc-webapp/test/data/template1.html b/packages/xarc-webapp/test/data/template1.html
new file mode 100644
index 000000000..f2d6bb644
--- /dev/null
+++ b/packages/xarc-webapp/test/data/template1.html
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/template2.html b/packages/xarc-webapp/test/data/template2.html
new file mode 100644
index 000000000..5de95e820
--- /dev/null
+++ b/packages/xarc-webapp/test/data/template2.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/template3.html b/packages/xarc-webapp/test/data/template3.html
new file mode 100644
index 000000000..33c0be87c
--- /dev/null
+++ b/packages/xarc-webapp/test/data/template3.html
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/template4.html b/packages/xarc-webapp/test/data/template4.html
new file mode 100644
index 000000000..adfea1d08
--- /dev/null
+++ b/packages/xarc-webapp/test/data/template4.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/template5.html b/packages/xarc-webapp/test/data/template5.html
new file mode 100644
index 000000000..7856e3bdc
--- /dev/null
+++ b/packages/xarc-webapp/test/data/template5.html
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/template6.html b/packages/xarc-webapp/test/data/template6.html
new file mode 100644
index 000000000..72f9c17e9
--- /dev/null
+++ b/packages/xarc-webapp/test/data/template6.html
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/template7.html b/packages/xarc-webapp/test/data/template7.html
new file mode 100644
index 000000000..f08f0f36e
--- /dev/null
+++ b/packages/xarc-webapp/test/data/template7.html
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/template8.html b/packages/xarc-webapp/test/data/template8.html
new file mode 100644
index 000000000..60e9a22eb
--- /dev/null
+++ b/packages/xarc-webapp/test/data/template8.html
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/data/test-content.js b/packages/xarc-webapp/test/data/test-content.js
new file mode 100644
index 000000000..ae795d49f
--- /dev/null
+++ b/packages/xarc-webapp/test/data/test-content.js
@@ -0,0 +1,5 @@
+module.exports = {
+ "status": 200,
+ "html": "Test1 Electrode
",
+ "prefetch": "console.log('test1');"
+};
diff --git a/packages/xarc-webapp/test/data/test-content17.js b/packages/xarc-webapp/test/data/test-content17.js
new file mode 100644
index 000000000..463551e68
--- /dev/null
+++ b/packages/xarc-webapp/test/data/test-content17.js
@@ -0,0 +1,5 @@
+module.exports = {
+ "status": 200,
+ "html": "Test1 Electrode17
",
+ "prefetch": "console.log('test1');"
+};
diff --git a/packages/xarc-webapp/test/data/test-dll-assets.json b/packages/xarc-webapp/test/data/test-dll-assets.json
new file mode 100644
index 000000000..03de32b27
--- /dev/null
+++ b/packages/xarc-webapp/test/data/test-dll-assets.json
@@ -0,0 +1,5 @@
+{
+ "foo": {
+ "bar": [1]
+ }
+}
diff --git a/packages/xarc-webapp/test/fixtures/async-error.js b/packages/xarc-webapp/test/fixtures/async-error.js
new file mode 100644
index 000000000..a84cb4dc2
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/async-error.js
@@ -0,0 +1,10 @@
+"use strict";
+
+module.exports = () => {
+ return {
+ process: function(context) {
+ context.output.add("\nfrom async error module");
+ return Promise.reject("error from test/fixtures/async-error");
+ }
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/async-ok.js b/packages/xarc-webapp/test/fixtures/async-ok.js
new file mode 100644
index 000000000..1d5db1518
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/async-ok.js
@@ -0,0 +1,10 @@
+"use strict";
+
+module.exports = () => {
+ return {
+ process: function(context) {
+ context.output.add("\nfrom async ok module");
+ return Promise.resolve();
+ }
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/custom-1.js b/packages/xarc-webapp/test/fixtures/custom-1.js
new file mode 100644
index 000000000..91b977aa4
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/custom-1.js
@@ -0,0 +1,10 @@
+"use strict";
+
+module.exports = function setup() {
+ return {
+ name: "custom-1",
+ process: function(context) {
+ context.output.add("from custom-1
");
+ }
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/custom-call.js b/packages/xarc-webapp/test/fixtures/custom-call.js
new file mode 100644
index 000000000..d9e636021
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/custom-call.js
@@ -0,0 +1,14 @@
+"use strict";
+
+function setup() {
+ return {
+ name: "custom-call",
+ process: function() {
+ return Promise.resolve(`_call process from custom-call token fixture`);
+ }
+ };
+}
+
+module.exports = {
+ setup
+};
diff --git a/packages/xarc-webapp/test/fixtures/custom-count.js b/packages/xarc-webapp/test/fixtures/custom-count.js
new file mode 100644
index 000000000..d8f08698a
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/custom-count.js
@@ -0,0 +1,7 @@
+let count = 0;
+module.exports = () => {
+ count++;
+ return {
+ process: () => `${count}`
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/custom-fail.js b/packages/xarc-webapp/test/fixtures/custom-fail.js
new file mode 100644
index 000000000..771c2752e
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/custom-fail.js
@@ -0,0 +1 @@
+throw new Error("fail");
diff --git a/packages/xarc-webapp/test/fixtures/custom-null.js b/packages/xarc-webapp/test/fixtures/custom-null.js
new file mode 100644
index 000000000..afb179f85
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/custom-null.js
@@ -0,0 +1,3 @@
+module.exports = () => {
+ return null;
+};
diff --git a/packages/xarc-webapp/test/fixtures/dynamic-index-1.html b/packages/xarc-webapp/test/fixtures/dynamic-index-1.html
new file mode 100644
index 000000000..641884356
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/dynamic-index-1.html
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DYNAMIC_INDEX_1
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/fixtures/dynamic-index-2.html b/packages/xarc-webapp/test/fixtures/dynamic-index-2.html
new file mode 100644
index 000000000..9d449da06
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/dynamic-index-2.html
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DYNAMIC_INDEX_2
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/fixtures/non-render-error.js b/packages/xarc-webapp/test/fixtures/non-render-error.js
new file mode 100644
index 000000000..004c071e1
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/non-render-error.js
@@ -0,0 +1,11 @@
+"use strict";
+
+module.exports = () => {
+ return {
+ name: "non-render-error",
+ beforeRender: () => {
+ throw new Error("error from test/fixtures/non-render-error");
+ },
+ tokens: {}
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/perf-1-handler.js b/packages/xarc-webapp/test/fixtures/perf-1-handler.js
new file mode 100644
index 000000000..ca41e548d
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/perf-1-handler.js
@@ -0,0 +1,31 @@
+"use strict";
+
+module.exports = () => {
+ return {
+ "user-token-1": () => {
+ return "user-token-1
";
+ },
+
+ "user-token-2": context => {
+ context.output.add("user-token-2
");
+ },
+
+ "user-spot-token": context => {
+ const spot = context.output.reserve();
+ process.nextTick(() => {
+ spot.add("user-spot-1;");
+ spot.add("user-spot-2;");
+ spot.add("user-spot-3
");
+ spot.close();
+ });
+ },
+
+ "user-promise-token": context => {
+ context.output.add("user-promise-token
");
+ },
+
+ PAGE_TITLE: () => {
+ return "user-handler-title";
+ }
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/react-helmet-handler.js b/packages/xarc-webapp/test/fixtures/react-helmet-handler.js
new file mode 100644
index 000000000..6f0b28326
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/react-helmet-handler.js
@@ -0,0 +1,35 @@
+"use strict";
+
+const Helmet = require("react-helmet").Helmet;
+
+const emptyTitleRegex = /]*><\/title>/;
+
+module.exports = handlerContext => {
+ const routeOptions = handlerContext.user.routeOptions;
+ const iconStats = handlerContext.user.routeData.iconStats;
+
+ return {
+ HEAD_INITIALIZE: context => {
+ context.user.helmet = Helmet.renderStatic();
+ },
+
+ PAGE_TITLE: context => {
+ const helmet = context.user.helmet;
+ const helmetTitleScript = helmet.title.toString();
+ const helmetTitleEmpty = helmetTitleScript.match(emptyTitleRegex);
+
+ return helmetTitleEmpty ? `${routeOptions.pageTitle}` : helmetTitleScript;
+ },
+
+ REACT_HELMET_SCRIPTS: context => {
+ const scriptsFromHelmet = ["link", "style", "script", "noscript"]
+ .map(tagName => context.user.helmet[tagName].toString())
+ .join("");
+ return `${scriptsFromHelmet}`;
+ },
+
+ META_TAGS: context => {
+ return context.user.helmet.meta.toString() + iconStats;
+ }
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/return-undefined.js b/packages/xarc-webapp/test/fixtures/return-undefined.js
new file mode 100644
index 000000000..d1823ec85
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/return-undefined.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = () => {
+ return {
+ process: function() {}
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/string-only.js b/packages/xarc-webapp/test/fixtures/string-only.js
new file mode 100644
index 000000000..76a7a8aea
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/string-only.js
@@ -0,0 +1,9 @@
+"use strict";
+
+module.exports = () => {
+ return {
+ process: function() {
+ return "\nfrom string only module";
+ }
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/template-processor-1.js b/packages/xarc-webapp/test/fixtures/template-processor-1.js
new file mode 100644
index 000000000..15d6c3e46
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/template-processor-1.js
@@ -0,0 +1,5 @@
+"use strict";
+
+module.exports = function() {
+ return "template-processor-1";
+};
diff --git a/packages/xarc-webapp/test/fixtures/template-processor-2.js b/packages/xarc-webapp/test/fixtures/template-processor-2.js
new file mode 100644
index 000000000..115948f57
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/template-processor-2.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ templateProcessor: function() {
+ return "template-processor-2";
+ }
+};
diff --git a/packages/xarc-webapp/test/fixtures/template-processor-3.js b/packages/xarc-webapp/test/fixtures/template-processor-3.js
new file mode 100644
index 000000000..eb785eb37
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/template-processor-3.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ oops: function() {
+ return "template-processor-3";
+ }
+};
diff --git a/packages/xarc-webapp/test/fixtures/test-render-context.html b/packages/xarc-webapp/test/fixtures/test-render-context.html
new file mode 100644
index 000000000..51f62a08b
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/test-render-context.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/xarc-webapp/test/fixtures/token-handler.js b/packages/xarc-webapp/test/fixtures/token-handler.js
new file mode 100644
index 000000000..464b94a25
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/token-handler.js
@@ -0,0 +1,50 @@
+"use strict";
+
+/* eslint-disable no-magic-numbers */
+
+module.exports = () => {
+ return {
+ "user-token-1": () => {
+ return "user-token-1
";
+ },
+
+ "user-token-2": context => {
+ context.output.add("user-token-2
");
+ },
+
+ "user-spot-token": context => {
+ const spot = context.output.reserve();
+ spot.add("user-spot-1;");
+ setTimeout(() => {
+ spot.add("user-spot-2;");
+ setTimeout(() => {
+ spot.add("user-spot-3
");
+ spot.close();
+ }, 20);
+ }, 10);
+ },
+
+ "user-promise-token": context => {
+ return new Promise(resolve => {
+ setTimeout(() => {
+ context.output.add("user-promise-token
");
+ resolve();
+ }, 10);
+ });
+ },
+
+ "user-header-token": context => {
+ context.user.response.headers = {
+ "x-foo-bar": "hello-world"
+ };
+ },
+
+ PAGE_TITLE: () => {
+ return "user-handler-title";
+ },
+
+ TEST_DYNAMIC_2: () => {
+ return "RETURN_BY_TEST_DYANMIC_2";
+ }
+ };
+};
diff --git a/packages/xarc-webapp/test/fixtures/wants-next.js b/packages/xarc-webapp/test/fixtures/wants-next.js
new file mode 100644
index 000000000..0449f4868
--- /dev/null
+++ b/packages/xarc-webapp/test/fixtures/wants-next.js
@@ -0,0 +1,9 @@
+"use strict";
+
+module.exports = () => {
+ return {
+ process: function(context) {
+ context.output.add("\nfrom wants next module");
+ }
+ };
+};
diff --git a/packages/xarc-webapp/test/jsx-templates/.babelrc b/packages/xarc-webapp/test/jsx-templates/.babelrc
new file mode 100644
index 000000000..24b086f24
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/.babelrc
@@ -0,0 +1,13 @@
+{
+ "presets": [
+ [
+ "@babel/preset-env",
+ {
+ "targets": {
+ "node": "8"
+ }
+ }
+ ],
+ "@babel/preset-react"
+ ]
+}
diff --git a/packages/xarc-webapp/test/jsx-templates/index-1.jsx b/packages/xarc-webapp/test/jsx-templates/index-1.jsx
new file mode 100644
index 000000000..287eb304f
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/index-1.jsx
@@ -0,0 +1,48 @@
+/* @jsx createElement */
+
+const { IndexPage, createElement, Token, Require } = require("../../lib/jsx");
+
+const Template = (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test html-1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+);
+
+export default Template;
diff --git a/packages/xarc-webapp/test/jsx-templates/index-2.jsx b/packages/xarc-webapp/test/jsx-templates/index-2.jsx
new file mode 100644
index 000000000..9b42c1a3a
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/index-2.jsx
@@ -0,0 +1,42 @@
+/* @jsx createElement */
+
+const { IndexPage, createElement, Token } = require("../../lib/jsx");
+
+const TestAsync = async () => {
+ return `Hello from async tag JSX-2
`;
+};
+
+const Template = (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test jsx-2
+
+
+
+
+
+
+
+
+
+
+
+);
+
+export default Template;
diff --git a/packages/xarc-webapp/test/jsx-templates/index-3.jsx b/packages/xarc-webapp/test/jsx-templates/index-3.jsx
new file mode 100644
index 000000000..bc78d0647
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/index-3.jsx
@@ -0,0 +1,25 @@
+/* @jsx createElement */
+
+const { IndexPage, createElement, Token, Require } = require("../../lib/jsx");
+
+const Test = (props, context) => {
+ context.status = 204;
+ return `Hello Test JSX-3
`;
+};
+
+const Template = (
+
+
+
+
+
+
+
+
+
+
+
+
+);
+
+export default Template;
diff --git a/packages/xarc-webapp/test/jsx-templates/index-intercept.jsx b/packages/xarc-webapp/test/jsx-templates/index-intercept.jsx
new file mode 100644
index 000000000..a827a4a63
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/index-intercept.jsx
@@ -0,0 +1,28 @@
+/* @jsx createElement */
+
+const { IndexPage, createElement, Token, Require } = require("../../lib/jsx");
+
+const Test = (props, context) => {
+ context.intercept({
+ responseHandler: (request, h) => {
+ return h.response("context intercept handler").takeover();
+ }
+ });
+};
+
+const Template = (
+
+
+
+
+
+
+
+
+
+
+
+
+);
+
+export default Template;
diff --git a/packages/xarc-webapp/test/jsx-templates/style.css b/packages/xarc-webapp/test/jsx-templates/style.css
new file mode 100644
index 000000000..266cef311
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/style.css
@@ -0,0 +1,3 @@
+.test {
+ background: black;
+}
diff --git a/packages/xarc-webapp/test/jsx-templates/test-token.js b/packages/xarc-webapp/test/jsx-templates/test-token.js
new file mode 100644
index 000000000..da720f10d
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/test-token.js
@@ -0,0 +1,7 @@
+module.exports = function setup(setupContext, token) {
+ const props = token.props;
+
+ return {
+ process: () => props.name
+ };
+};
diff --git a/packages/xarc-webapp/test/jsx-templates/test1.jsx b/packages/xarc-webapp/test/jsx-templates/test1.jsx
new file mode 100644
index 000000000..57db9e93f
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/test1.jsx
@@ -0,0 +1,140 @@
+/* @jsx createElement */
+
+import { IndexPage, createElement, Token, Require, Literal, Component } from "../../lib/jsx";
+
+const getBogelFontUrl = () => {
+ return "bogel";
+};
+
+const MyTest = (props, context) => {
+ return (
+ 50}>
+
+ my test
+
+ );
+};
+
+class TestComponent1 extends Component {
+ constructor(props, context) {
+ super(props, context);
+ }
+
+ render() {
+ return from test component1{this.props.test1}
;
+ }
+}
+
+function AsyncComponent(props, context, scope) {
+ return new Promise(resolve => {
+ setTimeout(() => {
+ scope.output.add(`${props.indent}async component ${props.key}\n`);
+ resolve(async component children: {props.children}
);
+ }, props.delay);
+ });
+}
+
+function ChildrenNesting(props) {
+ return (
+
+ component nesting children
+ {props.children}
+
+ );
+}
+
+const Template = () => (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test nested async components 1
+
+
+ test nested async components 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+);
+
+export default Template;
diff --git a/packages/xarc-webapp/test/jsx-templates/test2.jsx b/packages/xarc-webapp/test/jsx-templates/test2.jsx
new file mode 100644
index 000000000..8c8a7a3de
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/test2.jsx
@@ -0,0 +1,96 @@
+/* @jsx createElement */
+
+import { IndexPage, createElement, Token, Require, Literal, Component } from "../../lib/jsx";
+
+const getBogelFontUrl = () => {
+ return "bogel";
+};
+
+const MyTest = (props, context) => {
+ return (
+ 50}>
+
+ my test
+
+ );
+};
+
+class TestComponent1 extends Component {
+ constructor(props, context) {
+ super(props, context);
+ }
+
+ render() {
+ return from test component1{this.props.test1}
;
+ }
+}
+
+function AsyncComponent(props, context, scope) {
+ return new Promise((resolve, reject) => {
+ setTimeout(() => {
+ if (props.fail) {
+ reject(new Error("test async component fail"));
+ } else {
+ scope.output.add(`${props.indent}async component ${props.key}\n`);
+ resolve();
+ }
+ }, props.delay);
+ });
+}
+
+function NestAsyncComponent() {
+ return (
+
+ test nested async components failed
+
+ );
+}
+
+const Template = (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test nested async components 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+);
+
+export default Template;
diff --git a/packages/xarc-webapp/test/jsx-templates/test3.jsx b/packages/xarc-webapp/test/jsx-templates/test3.jsx
new file mode 100644
index 000000000..87af8c238
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/test3.jsx
@@ -0,0 +1,53 @@
+/* @jsx createElement */
+
+import { IndexPage, createElement, Token, Require, Literal, Component } from "../../lib/jsx";
+
+function Component1(props) {
+ return (
+
+ component1 {props.key} {props.children}
+
+ );
+}
+
+function AsyncChildren(props) {
+ return new Promise(resolve =>
+ setTimeout(() => {
+ resolve(
+
+ async component {props.key} children: {props.children}
+
+ );
+ }, 10)
+ );
+}
+
+function NestChildren(props) {
+ return (
+
+ nesting children
+ {props.children}
+
+ inside component1
+
+
+ );
+}
+
+export default (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+);
diff --git a/packages/xarc-webapp/test/jsx-templates/test4.jsx b/packages/xarc-webapp/test/jsx-templates/test4.jsx
new file mode 100644
index 000000000..5314acb47
--- /dev/null
+++ b/packages/xarc-webapp/test/jsx-templates/test4.jsx
@@ -0,0 +1,11 @@
+/* @jsx createElement */
+
+import { IndexPage, createElement, Require } from "../../lib/jsx";
+
+export default (
+
+
+
+
+
+);
diff --git a/packages/xarc-webapp/test/spec/webapp.spec.ts b/packages/xarc-webapp/test/spec/webapp.spec.ts
index 4f110e499..14258b3d0 100644
--- a/packages/xarc-webapp/test/spec/webapp.spec.ts
+++ b/packages/xarc-webapp/test/spec/webapp.spec.ts
@@ -39,55 +39,3 @@ describe("resolveContent", function () {
});
});
-describe("makeRouteHandler", () => {
- it("should not add default handler if it's already included in options", () => {
- const htmlFile = Path.resolve("../test/jsx-template/index-1.jsx");
- const defaultReactHandler = Path.join(__dirname, "../../src/react/token-handlers");
- const intercept = xstdout.intercept(false);
- const handleRoute = Webapp.makeRouteHandler({
- htmlFile,
- tokenHandlers: [
- {
- name: "internal-test-handler",
- beforeRender: context => {
- expect(typeof context).to.equal("undefined");
- context.handleError = () => {};
- },
- afterRender: context => {
- expect(context.user, "should have context.user").to.not.equal(false);
- },
- tokens: {
- "internal-test": () => "\ninternal-test",
- "test-not-found": () => "\nnot found",
- "non-func-token": ""
- }
- },
- defaultReactHandler
- ],
- __internals: { assets: {}, chunkSelector: () => ({}) }
- });
-
- const promise = handleRoute({ request: {}, content: { status: 200, html: "" } });
-
- return promise
- .then(context => {
- intercept.restore();
- const expected = `
-from wants next module
-from async ok module
-from async error module
-from string only module
-internal-test
-from async error module
-from wants next module
-not found
-from string only module
-from async ok module`;
- expect(context.result).to.equal(expected);
- })
- .catch(err => {
- intercept.restore();
- throw err;
- });
- });
-});