diff --git a/.gitignore b/.gitignore
index 3f50108f3..0fd83de01 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,3 +128,5 @@ yarn.lock
docs
test-lib
test-lib-es5
+src/metaInfo.ts
+package-lock.json
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 000000000..5afd88770
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "common"]
+ path = common
+ url = git@github.com:GrimoireGL/common-configurations.git
diff --git a/.jsbeautifyrc b/.jsbeautifyrc
deleted file mode 100644
index bc2949c26..000000000
--- a/.jsbeautifyrc
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-"indent_size": 2,
-"indent_char": " ",
-"indent_level": 0,
-"indent_with_tabs": false,
-"preserve_newlines": true,
-"max_preserve_newlines": 10,
-"space_after_anon_function": false,
-"brace_style": "collapse-preserve-inline",
-"keep_array_indentation": false,
-"keep_function_indentation": false,
-"space_before_conditional": true,
-"break_chained_methods": false,
-"eval_code": false,
-"unescape_strings": false,
-"wrap_line_length": 0
-}
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index d97c7c49e..000000000
--- a/.jshintrc
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "esnext":true
-}
diff --git a/README.md b/README.md
index 74670b3c9..106d228c4 100644
--- a/README.md
+++ b/README.md
@@ -5,87 +5,151 @@
[](https://github.com/jThreeJS/jThree/blob/develop/LICENSE)
[](https://david-dm.org/GrimoireGL/GrimoireJS)
[](https://david-dm.org/GrimoireGL/GrimoireJS#info=devDependencies)
+[](https://greenkeeper.io/)
## Overview
-[](https://greenkeeper.io/)
+**Grimoire.js provide a bridge between Web engineers and CG engineers**
-Why virtual DOM needs to be only for actual DOM?
-Logics like drawing formulas for canvas even needs DOM for easier way.
+There were big gap between the development flows used for each.
-* **DOM based** ・・・The way that Web engineers can work most effectively.
-* **jQuery like API** ・・・No more complex procedural WebGL logics, just operate attributes with the API.
-* **Web development friendly**・・・Use with the other Web front-end frameworks. Very easy to coop with them.
-* **No more redundant codes**・・・Include only `tag`s you actually need.
+Web engineers have typically used `event driven` javascript programs for daily works. And they mutate DOM APIs to make Web pages dynamic.
-## Download
+However, CG engineers has typically used `loop based` programs for daily works. These are mostly build with a programming language with strong type like C++ or C#. And recently CG engineers more like to use strongly structured engines like Unity.
+
+This is why these 2 engineers have so much different flow for workings. This is why it is hard to learn CG stuff by Web engineers. And CG engineers are also hard to make suitable APIs for Web engineers working with.
+
+**Grimoire.js is a javascript(Typescript) framework to solve this problem with strong architecture**
-The file you might want to download is not included this repository since even set of WebGL operations are treated as plugins.
-Basic set for using Grimoire.js is bundled and published here([unpkg](https://unpkg.com/grimoirejs-preset-basic@1.8.5/register/grimoire-preset-basic.min.js)).
-This file includes `grimoirejs`,`grimoirejs-math` and `grimoirejs-fundamental`.
+## Features
-## First Interact
+You can see several feature of Grimoire.js providing in this section.
-**HTML file**
+**We strongly recommend to see our [top page](http://grimoire.gl) to learn these features. Most of written things are same as this README.md. But our samples on the top pages are working!!.**
+
+### HTML like markup
+
+We provides a syntax like XML to compose WebGL canvas. This is kind of HTML for Web engineers.
+You can create 360 degree image viewer on browser only by writing the code below.(See official page to see working example)
```xml
-
-
-
-
-
- ", []);
+ Environment.document = window.document;
+ const scriptTags = window.document.querySelectorAll("script[type=\"text/goml\"]");
+
+ await t.throws(GomlLoader.loadFromScriptTag(scriptTags.item(0)));
+});
+
+test("Processing script[type=\"text/goml\"] tag correctly when the text content was existing", async (t) => {
+ const window = await jsdomAsync(testcase1_html, []);
+ Environment.document = window.document;
+ const scriptTags = window.document.querySelectorAll("script[type=\"text/goml\"]");
+ const s = spy();
+ const mockedParseXML = mockXMLParse(xml => {
+ s(xml.replace(/[\n\s]/g, ""));
+ });
+ await mockedParseXML.loadFromScriptTag(scriptTags.item(0));
+ t.truthy(s.calledWith(""));
+});
+
+test("Processing script[type=\"text/goml\"] tag correctly when the src attribute was existing", async (t) => {
+ const window = await jsdomAsync(testcase2_html, []);
+ Environment.document = window.document;
+ const scriptTags = window.document.querySelectorAll("script[type=\"text/goml\"]");
+ const s = spy();
+ const mockedParseXML = mockXMLParse(xml => {
+ s(xml.replace(/[\n\s]/g, ""));
+ });
+
+ await mockedParseXML.loadFromScriptTag(scriptTags.item(0));
+ t.truthy(s.calledWith(""));
+});
+
+test("Processing goml scripts from query", async(t) => {
+ const window = await jsdomAsync(testcase3_html, []);
+ Environment.document = window.document;
+ const s = spy();
+ const mockedParseXML = mockXMLParse(xml => {
+ s(xml.trim());
+ });
+ await mockedParseXML.loadFromQuery("script.call");
+ t.truthy(s.calledWith("\n"));
+});
+
+test("Processing goml scripts for page", async(t) => {
+ const window = await jsdomAsync(testcase4_html, []);
+ Environment.document = window.document;
+ const s = spy();
+ const mockedParseXML = mockXMLParse(xml => {
+ s(xml.trim());
+ });
+ await mockedParseXML.loadForPage();
+ t.truthy(s.calledWith("\n"));
+});
+
+test("all text/goml scripts tags should be loaded on loadForPage", async(t) => {
+ const s = spy();
+ const original = GrimoireInterface.addRootNode.bind(GrimoireInterface);
+ GrimoireInterface.addRootNode = (tag: HTMLScriptElement, rootNode: GomlNode) => {
+ s(tag);
+ return original(tag, rootNode);
+ };
+
+ await TestEnvManager.loadPage(testcase4_html);
+ t.truthy(s.callCount === 4);
+});
diff --git a/test/Node/GomlNode2Test.ts b/test/Core/GomlNode2Test.ts
similarity index 76%
rename from test/Node/GomlNode2Test.ts
rename to test/Core/GomlNode2Test.ts
index f8a1059be..670dfdd4f 100644
--- a/test/Node/GomlNode2Test.ts
+++ b/test/Core/GomlNode2Test.ts
@@ -1,41 +1,40 @@
-import "../AsyncSupport";
-import "../XMLDomInit";
-import test from "ava";
-import sinon from "sinon";
-import xmldom from "xmldom";
import * as _ from "lodash";
-import {
- goml,
- stringConverter,
- testComponent1,
- testComponent2,
- testComponent3,
- testComponentBase,
- testComponentOptional,
- testNode1,
- testNode2,
- testNode3,
- testNodeBase,
- conflictNode1,
- conflictNode2,
- conflictComponent1,
- conflictComponent2
-} from "./GomlParserTest_Registering";
-import GomlLoader from "../../src/Node/GomlLoader";
-import GomlNode from "../../src/Node/GomlNode";
-import Component from "../../src/Node/Component";
-import Attribute from "../../src/Node/Attribute";
-import NSIdentity from "../../src/Base/NSIdentity";
-import GrimoireComponent from "../../src/Components/GrimoireComponent";
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
+import Attribute from "../../src/Core/Attribute";
+import Component from "../../src/Core/Component";
import fs from "../fileHelper";
-import PLH from "../PageLoadingHelper";
+import GomlLoader from "../../src/Core/GomlLoader";
+import GomlNode from "../../src/Core/GomlNode";
+import GrimoireComponent from "../../src/Component/GrimoireComponent";
+import GrimoireInterface from "../../src/Core/GrimoireInterface";
+import Identity from "../../src/Core/Identity";
+import test from "ava";
+import TestEnvManager from "../TestEnvManager";
+import { assert, spy } from "sinon";
+import {
+ registerConflictComponent1,
+ registerConflictComponent2,
+ registerConflictNode1,
+ registerConflictNode2,
+ registerGoml,
+ registerStringConverter,
+ registerTestComponent1,
+ registerTestComponent2,
+ registerTestComponent3,
+ registerTestComponentBase,
+ registerTestComponentOptional,
+ registerTestNode1,
+ registerTestNode2,
+ registerTestNode3,
+ registerTestNodeBase
+} from "../DummyObjectRegisterer";
+
+TestEnvManager.init();
const tc1_goml = fs.readFile("../_TestResource/GomlNodeTest_Case1.goml");
const tc1_html = fs.readFile("../_TestResource/GomlNodeTest_Case1.html");
-PLH.mockSetup();
-PLH.mock("./GomlNodeTest_Case1.goml", tc1_goml);
+TestEnvManager.mockSetup();
+TestEnvManager.mock("./GomlNodeTest_Case1.goml", tc1_goml);
let stringConverterSpy,
testComponent1Spy,
@@ -59,7 +58,26 @@ function resetSpies() {
let rootNode: GomlNode;
test.beforeEach(async () => {
- let spys = await PLH.reset(GrimoireInterface, tc1_html);
+ GrimoireInterface.clear();
+ registerGoml();
+ registerTestNode1();
+ registerTestNode2();
+ registerTestNode3();
+ registerTestNodeBase();
+ registerConflictNode1();
+ registerConflictNode2();
+ const spys: any = {};
+ spys.stringConverterSpy = registerStringConverter();
+ spys.testComponent1Spy = registerTestComponent1();
+ spys.testComponent2Spy = registerTestComponent2();
+ spys.testComponent3Spy = registerTestComponent3();
+ spys.testComponentBaseSpy = registerTestComponentBase();
+ spys.testComponentOptionalSpy = registerTestComponentOptional();
+ spys.conflictComponent1Spy = registerConflictComponent1();
+ spys.conflictComponent2Spy = registerConflictComponent2();
+ await GrimoireInterface.resolvePlugins();
+ await TestEnvManager.loadPage(tc1_html);
+
stringConverterSpy = spys.stringConverterSpy;
testComponent1Spy = spys.testComponent1Spy;
testComponent2Spy = spys.testComponent2Spy;
@@ -106,7 +124,7 @@ test("mount should be called in ideal timing", (t) => {
const testNode3 = rootNode.children[0];
testNode3.enabled = true;
const order = [testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy];
- sinon.assert.callOrder(testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy);
+ assert.callOrder(testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy);
order.forEach(v => {
t.truthy(v.getCall(1).args[0] === "mount");
});
@@ -127,43 +145,43 @@ test("Nodes should be mounted after loading", (t) => {
});
});
test("attribute default value work correctly1", (t) => {
- t.truthy(rootNode.getAttribute("id") !== void 0);
+ t.truthy(rootNode.getAttribute("id") !== undefined);
t.truthy(rootNode.getAttribute("id") === null);
});
test("attribute watch should work correctly", (t) => {
const idAttr = rootNode.getAttributeRaw("id");
- const spy = sinon.spy();
+ const s = spy();
const watcher = (newValue, oldValue, attr) => {
// spy("watch", { newValue: newValue, oldValue: oldValue, attr: attr });
- spy(newValue);
+ s(newValue);
};
idAttr.watch(watcher);
idAttr.Value = "id";
- t.truthy(spy.getCall(0).args[0] === "id");
+ t.truthy(s.getCall(0).args[0] === "id");
- spy.reset();
+ s.reset();
rootNode.enabled = false;
idAttr.Value = "id";
- sinon.assert.notCalled(spy);
+ assert.notCalled(s);
});
test("attribute watch should work correctly2", (t) => {
const idAttr = rootNode.getAttributeRaw("id");
- const spy = sinon.spy();
+ const s = spy();
const watcher = (newValue, oldValue, attr) => {
// spy("watch", { newValue: newValue, oldValue: oldValue, attr: attr });
- spy(newValue);
+ s(newValue);
};
idAttr.watch(watcher);
idAttr.unwatch(watcher);
idAttr.Value = "id";
- sinon.assert.notCalled(spy);
+ assert.notCalled(s);
idAttr.watch(watcher, false, true);
rootNode.enabled = false;
idAttr.Value = "idid";
- t.truthy(spy.getCall(0).args[0] === "idid");
+ t.truthy(s.getCall(0).args[0] === "idid");
});
test("enabled should work correctly", (t) => {
@@ -193,7 +211,7 @@ test("enabled should work correctly", (t) => {
});
test("Broadcast message should call correct order", (t) => {
- sinon.assert.callOrder(testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy);
+ assert.callOrder(testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy);
});
test("Broadcast message with range should work correctly", (t) => {
@@ -201,10 +219,10 @@ test("Broadcast message with range should work correctly", (t) => {
resetSpies();
testNode3.enabled = true;
rootNode.broadcastMessage(1, "onTest");
- sinon.assert.called(testComponent3Spy);
- sinon.assert.notCalled(testComponent2Spy);
- sinon.assert.notCalled(testComponentOptionalSpy);
- sinon.assert.notCalled(testComponent1Spy);
+ assert.called(testComponent3Spy);
+ assert.notCalled(testComponent2Spy);
+ assert.notCalled(testComponentOptionalSpy);
+ assert.notCalled(testComponent1Spy);
});
test("Broadcast message with enabled should work correctly", (t) => {
@@ -212,40 +230,40 @@ test("Broadcast message with enabled should work correctly", (t) => {
const testNode2 = testNode3.children[0];
resetSpies();
- sinon.assert.notCalled(testComponent3Spy);
- sinon.assert.notCalled(testComponent2Spy);
- sinon.assert.notCalled(testComponentOptionalSpy);
- sinon.assert.notCalled(testComponent1Spy);
+ assert.notCalled(testComponent3Spy);
+ assert.notCalled(testComponent2Spy);
+ assert.notCalled(testComponentOptionalSpy);
+ assert.notCalled(testComponent1Spy);
resetSpies();
rootNode.broadcastMessage("onTest");
- sinon.assert.notCalled(testComponent3Spy);
- sinon.assert.notCalled(testComponent2Spy);
- sinon.assert.notCalled(testComponentOptionalSpy);
- sinon.assert.notCalled(testComponent1Spy);
+ assert.notCalled(testComponent3Spy);
+ assert.notCalled(testComponent2Spy);
+ assert.notCalled(testComponentOptionalSpy);
+ assert.notCalled(testComponent1Spy);
resetSpies();
testNode3.enabled = true;
testNode2.enabled = false;
rootNode.broadcastMessage("onTest");
- sinon.assert.called(testComponent3Spy);
- sinon.assert.notCalled(testComponent2Spy);
- sinon.assert.notCalled(testComponentOptionalSpy);
- sinon.assert.called(testComponent1Spy);
+ assert.called(testComponent3Spy);
+ assert.notCalled(testComponent2Spy);
+ assert.notCalled(testComponentOptionalSpy);
+ assert.called(testComponent1Spy);
resetSpies();
testNode2.enabled = true;
rootNode.broadcastMessage("onTest");
- sinon.assert.called(testComponent3Spy);
- sinon.assert.called(testComponent2Spy);
- sinon.assert.called(testComponentOptionalSpy);
- sinon.assert.called(testComponent1Spy);
+ assert.called(testComponent3Spy);
+ assert.called(testComponent2Spy);
+ assert.called(testComponentOptionalSpy);
+ assert.called(testComponent1Spy);
});
test("SendMessage should call correct order", (t) => {
const testNode2 = rootNode.children[0].children[0];
testNode2.sendMessage("onTest");
- sinon.assert.callOrder(testComponent2Spy, testComponentOptionalSpy);
+ assert.callOrder(testComponent2Spy, testComponentOptionalSpy);
});
test("Detach node should invoke unmount before detaching", (t) => {
@@ -254,7 +272,7 @@ test("Detach node should invoke unmount before detaching", (t) => {
resetSpies();
testNode3.detach();
const called = [testComponent2Spy, testComponentOptionalSpy, testComponent1Spy, testComponent3Spy];
- sinon.assert.callOrder.apply(sinon.assert, called);
+ assert.callOrder.apply(assert, called);
called.forEach((v) => {
t.truthy(v.getCall(0).args[0] === "unmount");
});
@@ -266,7 +284,7 @@ test("Remove() should invoke unmount before deleting", (t) => {
resetSpies();
testNode3.remove();
const called = [testComponent2Spy, testComponentOptionalSpy, testComponent1Spy, testComponent3Spy];
- sinon.assert.callOrder.apply(sinon.assert, called);
+ assert.callOrder.apply(assert, called);
called.forEach((v) => {
t.truthy(v.getCall(0).args[0] === "unmount");
});
@@ -286,8 +304,8 @@ test("broadcastMessage should not invoke message if the component is not enabled
optionalComponent.enabled = false;
rootNode.broadcastMessage("onTest");
const called = [testComponent3Spy, testComponent2Spy, testComponent1Spy];
- sinon.assert.callOrder.apply(sinon.assert, called);
- sinon.assert.notCalled(testComponentOptionalSpy);
+ assert.callOrder.apply(assert, called);
+ assert.notCalled(testComponentOptionalSpy);
});
test("broadcastMessage should not invoke message if the node is not enabled", (t) => {
@@ -298,14 +316,14 @@ test("broadcastMessage should not invoke message if the node is not enabled", (t
testNode2.enabled = false;
rootNode.broadcastMessage("onTest");
const called = [testComponent3Spy, testComponent1Spy];
- sinon.assert.callOrder.apply(sinon.assert, called);
- sinon.assert.notCalled(testComponentOptionalSpy);
- sinon.assert.notCalled(testComponent2Spy);
+ assert.callOrder.apply(assert, called);
+ assert.notCalled(testComponentOptionalSpy);
+ assert.notCalled(testComponent2Spy);
});
test("class attribute can be obatined as default", (t) => {
const testNode3 = rootNode.children[0];
- let classes = testNode3.getAttribute("class");
+ const classes = testNode3.getAttribute("class");
t.truthy(classes.length === 1);
t.truthy(classes[0] === "classTest");
});
@@ -353,7 +371,7 @@ test("get/setAttribute should work correctly 2", t => {
const c = rootNode.getComponent("GrimoireComponent");
(c as any).__addAttribute("hoge", {
converter: "String",
- default: "aaa"
+ default: "aaa",
});
const att = rootNode.getAttribute("hoge");
t.truthy(att === "aaa");
@@ -364,7 +382,7 @@ test("get/setAttribute should work correctly 3", t => {
rootNode.setAttribute("hoge", "bbb");
(c as any).__addAttribute("hoge", {
converter: "String",
- default: "aaa"
+ default: "aaa",
});
const att = rootNode.getAttribute("hoge");
t.truthy(att === "bbb");
@@ -375,7 +393,7 @@ test("get/setAttribute should work correctly 4", t => {
rootNode.setAttribute("ns1.hoge", "bbb");
(c as any).__addAttribute("hoge", {
converter: "String",
- default: "aaa"
+ default: "aaa",
});
const att = rootNode.getAttribute("hoge");
t.truthy(att === "aaa");
@@ -387,7 +405,7 @@ test("attribute buffer is valid only last set value.", t => {
rootNode.setAttribute("ns1.hoge", "ccc");
(c as any).__addAttribute("ns1.hoge", {
converter: "String",
- default: "aaa"
+ default: "aaa",
});
let att = rootNode.getAttribute("ns1.hoge");
t.truthy(att === "ccc");
@@ -395,9 +413,9 @@ test("attribute buffer is valid only last set value.", t => {
// both buffer are resolved in above __addAttribute.
(c as any).__addAttribute("hoge", {
converter: "String",
- default: "aaa"
+ default: "aaa",
});
- att = rootNode.getAttribute(NSIdentity.fromFQN(c.name.fqn + ".hoge"));
+ att = rootNode.getAttribute(Identity.fromFQN(c.name.fqn + ".hoge"));
t.truthy(att === "aaa");
rootNode.setAttribute("ns2.aaa", "1");
@@ -405,9 +423,9 @@ test("attribute buffer is valid only last set value.", t => {
rootNode.setAttribute("ns2.aaa", "3");
(c as any).__addAttribute("ns2.aaa", {
converter: "String",
- default: "aaa"
+ default: "aaa",
});
- att = rootNode.getAttribute(NSIdentity.fromFQN(c.name.fqn + ".ns2.aaa"));
+ att = rootNode.getAttribute(Identity.fromFQN(c.name.fqn + ".ns2.aaa"));
t.truthy(att === "3");
});
@@ -417,7 +435,7 @@ test("get/setAttribute should work correctly 6", t => {
rootNode.setAttribute("hoge", "ccc");
(c as any).__addAttribute("hoge", {
converter: "String",
- default: "aaa"
+ default: "aaa",
});
const att = rootNode.getAttribute("hoge");
t.truthy(att === "ccc");
@@ -427,15 +445,15 @@ test("get/setAttribute should work correctly 7", t => {
const c = rootNode.getComponent("GrimoireComponent");
(c as any).__addAttribute("ns1.hoge", {
converter: "String",
- default: "1"
+ default: "1",
});
(c as any).__addAttribute("ns2.hoge", {
converter: "String",
- default: "2"
+ default: "2",
});
(c as any).__addAttribute("hoge", {
converter: "String",
- default: "3"
+ default: "3",
});
let att = rootNode.getAttribute("ns1.hoge");
t.truthy(att === "1");
@@ -444,7 +462,7 @@ test("get/setAttribute should work correctly 7", t => {
});
att = rootNode.getAttribute("ns2.hoge");
t.truthy(att === "2");
- att = rootNode.getAttribute(NSIdentity.fromFQN(c.name.fqn + ".hoge"));
+ att = rootNode.getAttribute(Identity.fromFQN(c.name.fqn + ".hoge"));
t.truthy(att === "3");
});
test("get/setAttribute should work correctly 8", t => {
@@ -453,14 +471,14 @@ test("get/setAttribute should work correctly 8", t => {
rootNode.setAttribute("ns2.hoge", "ccc");
(c as any).__addAttribute("ns1.hoge", { // matchs hoge but not matchs ns2.hoge.
converter: "String",
- default: "1"
+ default: "1",
});
let att = rootNode.getAttribute("ns1.hoge");
t.truthy(att === "bbb");
(c as any).__addAttribute("ns2.hoge", {
converter: "String",
- default: "2"
+ default: "2",
});
t.throws(() => {
rootNode.getAttribute("hoge");
@@ -470,9 +488,9 @@ test("get/setAttribute should work correctly 8", t => {
(c as any).__addAttribute("hoge", {
converter: "String",
- default: "3"
+ default: "3",
});
- att = rootNode.getAttribute(NSIdentity.fromFQN(c.name.fqn + ".hoge"));
+ att = rootNode.getAttribute(Identity.fromFQN(c.name.fqn + ".hoge"));
t.truthy(att === "3");
});
@@ -480,7 +498,7 @@ test("addNode works correctly", (t) => {
const testNode2 = rootNode.children[0].children[0];
testNode2.addChildByName("test-node2", {
testAttr2: "ADDEDNODE",
- id: "idtest"
+ id: "idtest",
});
const child = testNode2.children[0];
t.truthy(child.name.name === "test-node2");
@@ -490,12 +508,12 @@ test("addNode works correctly", (t) => {
t.truthy(child.getComponent(GrimoireComponent).getAttribute("id") === "idtest");
});
-test("null should be \"\" as id and classname", async (t) => {
+test("null should be \"\" as id and classname", async(t) => {
const testNode2 = rootNode.children[0].children[0];
testNode2.addChildByName("test-node2", {
testAttr2: "ADDEDNODE",
id: null,
- class: null
+ class: null,
});
const child = testNode2.children[0];
t.truthy(child.name.name === "test-node2");
@@ -508,12 +526,12 @@ test("null should be \"\" as id and classname", async (t) => {
t.truthy(child.getComponent(GrimoireComponent).getAttribute("class") === null);
});
-test("null should be \"\" as id and classname", async (t) => {
+test("null should be \"\" as id and classname", async(t) => {
const testNode2 = rootNode.children[0].children[0];
testNode2.addChildByName("test-node2", {
testAttr2: "ADDEDNODE",
id: null,
- class: null
+ class: null,
});
const child = testNode2.children[0];
t.truthy(child.name.name === "test-node2");
diff --git a/test/Node/GomlNodeTest.ts b/test/Core/GomlNodeTest.ts
similarity index 55%
rename from test/Node/GomlNodeTest.ts
rename to test/Core/GomlNodeTest.ts
index 23b26c670..6594923e9 100644
--- a/test/Node/GomlNodeTest.ts
+++ b/test/Core/GomlNodeTest.ts
@@ -1,42 +1,41 @@
-import "../AsyncSupport";
-import "../XMLDomInit";
-import xmldom from "xmldom";
import test from "ava";
-import sinon from "sinon";
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
-import Constants from "../../src/Base/Constants";
-import Component from "../../src/Node/Component";
-import GomlParser from "../../src/Node/GomlParser";
-import GomlLoader from "../../src/Node/GomlLoader";
-import NSIdentity from "../../src/Base/NSIdentity";
-import GomlNode from "../../src/Node/GomlNode";
-import Attribute from "../../src/Node/Attribute";
+import { spy } from "sinon";
+import Attribute from "../../src/Core/Attribute";
+import Component from "../../src/Core/Component";
+import Constants from "../../src/Core/Constants";
+import Environment from "../../src/Core/Environment";
+import GomlLoader from "../../src/Core/GomlLoader";
+import GomlNode from "../../src/Core/GomlNode";
+import GomlParser from "../../src/Core/GomlParser";
+import GrimoireInterface from "../../src/Core/GrimoireInterface";
+import Identity from "../../src/Core/Identity";
+import TestEnvManager from "../TestEnvManager";
+import TestUtil from "../TestUtil";
-declare namespace global {
- let Node: any;
- let document: any;
- let rootNode: any;
-}
+TestEnvManager.init();
-global.Node = {
- ELEMENT_NODE: 1
-};
-
-test.beforeEach(async () => {
+test.beforeEach(async() => {
+ GrimoireInterface.debug = false;
GrimoireInterface.clear();
- const parser = new DOMParser();
- const htmlDoc = parser.parseFromString("", "text/html");
- global.document = htmlDoc;
+ TestEnvManager.loadPage("");
GrimoireInterface.registerNode("goml");
GrimoireInterface.registerNode("scenes");
GrimoireInterface.registerNode("scene");
- GrimoireInterface.registerComponent("Test", { attributes: {}, valueTest: "Test"});
- GrimoireInterface.registerComponent("Test2", { attributes: {}, valueTest: "Test2"});
+ GrimoireInterface.registerComponent({
+ componentName: "Test",
+ attributes: {},
+ valueTest: "Test",
+ });
+ GrimoireInterface.registerComponent({
+ componentName: "Test2",
+ attributes: {},
+ valueTest: "Test2",
+ });
await GrimoireInterface.resolvePlugins();
});
test("Add component works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
node.addComponent("Test");
node.addComponent("Test2");
node.addComponent("Test");
@@ -49,7 +48,7 @@ test("Add component works correctly", t => {
});
test("Remove component actually delete specified insatnce", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
node.addComponent("Test");
node.addComponent("Test2");
node.addComponent("Test");
@@ -60,7 +59,7 @@ test("Remove component actually delete specified insatnce", t => {
});
test("Remove components should delete specified all components in node", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
node.addComponent("Test");
node.addComponent("Test");
node.addComponent("Test");
@@ -70,20 +69,36 @@ test("Remove components should delete specified all components in node", t => {
});
test("addChild method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- node.addChild(node2, null, null);
- node.addChild(node2, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ node.addChild(node2, null);
+ node.addChild(node2, null);
t.truthy(node.children[0].id === node2.id);
t.truthy(node.children.length === 2);
});
-test("delete method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"), null);
- node.addChild(node2, null, null);
- node2.addChild(node3, null, null);
+test("append works correctly with string argument", t => {
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ t.truthy(node.children.length === 0);
+ node.append("");
+ t.truthy(node.children.length === 1);
+ t.truthy(node.children[0].declaration.name.fqn === "grimoirejs.goml");
+});
+
+test("append works correctly with gom argument", t => {
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ t.truthy(node.children.length === 0);
+ node.append({name: "goml"});
+ t.truthy(node.children.length === 1);
+ t.truthy(node.children[0].declaration.name.fqn === "grimoirejs.goml");
+});
+
+test("remove method works correctly", t => {
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"));
+ node.addChild(node2, null);
+ node2.addChild(node3, null);
node2.remove();
t.truthy(node.children.length === 0);
t.truthy(node2.parent === null);
@@ -93,22 +108,22 @@ test("delete method works correctly", t => {
});
test("removeChild method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"), null);
- node.addChild(node2, null, null);
- node2.addChild(node3, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"));
+ node.addChild(node2, null);
+ node2.addChild(node3, null);
node.removeChild(node2);
t.truthy(node2.deleted === true);
t.truthy(node3.deleted === true);
});
test("detachChild method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"), null);
- node.addChild(node2, null, null);
- node2.addChild(node3, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"));
+ node.addChild(node2, null);
+ node2.addChild(node3, null);
node.detachChild(node2);
t.truthy(node.children.length === 0);
t.truthy(node2.deleted === false);
@@ -117,11 +132,11 @@ test("detachChild method works correctly", t => {
});
test("detach method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"), null);
- node.addChild(node2, null, null);
- node2.addChild(node3, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"));
+ node.addChild(node2, null);
+ node2.addChild(node3, null);
node2.detach();
try {
node.detach();
@@ -140,46 +155,46 @@ test("getComponents method works correctly", t => {
attributes: {
attr1: {
converter: "String",
- default: "testAttr"
- }
- }
+ default: "testAttr",
+ },
+ },
});
GrimoireInterface.registerNode("test-node", ["TestComponent"]);
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("test-node"), null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("test-node"));
const components = node.getComponents();
t.truthy(components.length === 2);
});
test("setMounted method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"), null);
- node.addChild(node2, null, null);
- node2.addChild(node3, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ const node3 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scene"));
+ node.addChild(node2, null);
+ node2.addChild(node3, null);
node.setMounted(true);
t.truthy(node.mounted === true);
t.truthy(node2.mounted === true);
t.truthy(node3.mounted === true);
});
test("index method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
node.addChild(node2);
t.truthy(node2.index === 0);
});
test("addComponent method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- node.addChild(node2, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ node.addChild(node2, null);
GrimoireInterface.registerComponent({
componentName: "TestComponent1",
attributes: {
testAttr1: {
converter: "String",
- default: "thisistest"
- }
- }
+ default: "thisistest",
+ },
+ },
});
const component = GrimoireInterface.componentDeclarations.get("TestComponent1").generateInstance();
node._addComponentDirectly(component, true);
@@ -189,17 +204,17 @@ test("addComponent method works correctly", t => {
t.truthy(component.isDefaultComponent);
});
test("addComponent method works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- node.addChild(node2, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ node.addChild(node2, null);
GrimoireInterface.registerComponent({
componentName: "TestComponent1",
attributes: {
testAttr1: {
converter: "String",
- default: "thisistest"
- }
- }
+ default: "thisistest",
+ },
+ },
});
const component = node.addComponent("TestComponent1", { testAttr1: "testValue" });
const components = node.getComponents();
@@ -209,26 +224,26 @@ test("addComponent method works correctly", t => {
t.truthy(component.isDefaultComponent === false);
});
test("getComponent method overload works correctly", async t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- node.addChild(node2, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ node.addChild(node2, null);
GrimoireInterface.registerComponent({
componentName: "TestComponent1",
attributes: {
testAttr1: {
converter: "String",
- default: "thisistest"
- }
- }
+ default: "thisistest",
+ },
+ },
});
GrimoireInterface.registerComponent({
componentName: "TestComponent2",
attributes: {
testAttr1: {
converter: "String",
- default: "thisistest"
- }
- }
+ default: "thisistest",
+ },
+ },
}, "TestComponent1");
await GrimoireInterface.resolvePlugins();
@@ -237,45 +252,152 @@ test("getComponent method overload works correctly", async t => {
t.truthy(node.getComponent("TestComponent1").name.name === "TestComponent2");
});
test("getComponents method overload works correctly", t => {
- const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
- const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"), null);
- node.addChild(node2, null, null);
+ const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"));
+ const node2 = new GomlNode(GrimoireInterface.nodeDeclarations.get("scenes"));
+ node.addChild(node2, null);
GrimoireInterface.registerComponent({
componentName: "TestComponent1",
attributes: {
testAttr1: {
converter: "String",
- default: "thisistest"
- }
- }
+ default: "thisistest",
+ },
+ },
});
GrimoireInterface.registerComponent({
componentName: "TestComponent2",
attributes: {
testAttr1: {
converter: "String",
- default: "thisistest"
- }
- }
+ default: "thisistest",
+ },
+ },
});
node.addComponent("TestComponent1");
node.addComponent("TestComponent2");
const components = node.getComponents();
t.truthy(components.length === 3);
});
-// test("addAttribute method works correctly", t => {
-// const node = new GomlNode(GrimoireInterface.nodeDeclarations.get("goml"), null);
-// GrimoireInterface.registerComponent("TestComponent1", {
-// attributes: {
-// testAttr1: {
-// converter: "String",
-// default: "thisistest"
-// }
-// }
-// });
-// const component = GrimoireInterface.componentDeclarations.get("TestComponent1").generateInstance();
-// const attr = new Attribute("testAttr", {
-// converter: "String",
-// default: "thisistest"
-// }, component);
-// });
+
+test("async message reciever called with await", async t => {
+ const gr = Environment.GrimoireInterface;
+ const spy1 = spy();
+
+ gr.registerComponent({
+ componentName: "Aaa",
+ attributes: {},
+ $awake() {
+ spy1("awake:" + this.node.getAttribute("id"));
+ },
+ $mount() {
+ spy1("mount:" + this.node.getAttribute("id"));
+ },
+ $mounted() {
+ spy1("mounted:" + this.node.getAttribute("id"));
+ },
+ $preunmount() {
+ spy1("preunmount:" + this.node.getAttribute("id"));
+ },
+ $unmount() {
+ spy1("unmount:" + this.node.getAttribute("id"));
+ },
+ $dispose() {
+ spy1("dispose:" + this.node.getAttribute("id"));
+ },
+ });
+ gr.registerNode("a", ["Aaa"]);
+
+ await TestEnvManager.loadPage(TestUtil.GenerateGomlEmbeddedHtml(''));
+
+ const root = gr("*")("#parent").first();
+ const middle = gr("*")("#middle").first();
+ t.deepEqual(spy1.args, [
+ ["awake:parent"],
+ ["mount:parent"],
+ ["awake:middle"],
+ ["mount:middle"],
+ ["awake:child"],
+ ["mount:child"],
+ ["mounted:child"],
+ ["mounted:middle"],
+ ["mounted:parent"],
+ ]);
+
+ spy1.reset();
+
+ middle.detach();
+ t.deepEqual(spy1.args, [
+ ["preunmount:middle"],
+ ["preunmount:child"],
+ ["unmount:child"],
+ ["unmount:middle"],
+ ]);
+
+ spy1.reset();
+ root.remove();
+ t.deepEqual(spy1.args, [
+ ["preunmount:parent"],
+ ["unmount:parent"],
+ ["dispose:parent"],
+ ]);
+});
+
+test("async message reciever called with await", async t => {
+ const gr = Environment.GrimoireInterface;
+ const spy1 = spy();
+
+ gr.registerComponent({
+ componentName: "Aaa",
+ attributes: {},
+ $awake() {
+ spy1("awake:" + this.node.getAttribute("id"));
+ },
+ $mount() {
+ spy1("mount:" + this.node.getAttribute("id"));
+ },
+ $mounted() {
+ spy1("mounted:" + this.node.getAttribute("id"));
+ },
+ $preunmount() {
+ spy1("preunmount:" + this.node.getAttribute("id"));
+ },
+ $unmount() {
+ spy1("unmount:" + this.node.getAttribute("id"));
+ },
+ $dispose() {
+ spy1("dispose:" + this.node.getAttribute("id"));
+ },
+ });
+ gr.registerNode("a", ["Aaa"]);
+
+ await TestEnvManager.loadPage(TestUtil.GenerateGomlEmbeddedHtml(''));
+
+ const root = gr("*")("#parent").first();
+ const middle = gr("*")("#middle").first();
+ t.deepEqual(spy1.args, [
+ ["awake:parent"],
+ ["mount:parent"],
+ ["awake:middle"],
+ ["mount:middle"],
+ ["awake:child"],
+ ["mount:child"],
+ ["mounted:child"],
+ ["mounted:middle"],
+ ["mounted:parent"],
+ ]);
+
+ spy1.reset();
+
+ root.remove();
+ t.deepEqual(spy1.args, [
+ ["preunmount:parent"],
+ ["preunmount:middle"],
+ ["preunmount:child"],
+ ["unmount:child"],
+ ["unmount:middle"],
+ ["unmount:parent"],
+ ["dispose:child"],
+ ["dispose:middle"],
+ ["dispose:parent"],
+ ]);
+});
diff --git a/test/Core/GomlParserTest.ts b/test/Core/GomlParserTest.ts
new file mode 100644
index 000000000..09e8cef20
--- /dev/null
+++ b/test/Core/GomlParserTest.ts
@@ -0,0 +1,220 @@
+import test from "ava";
+import { assert, spy } from "sinon";
+import Environment from "../../src/Core/Environment";
+import GomlParser from "../../src/Core/GomlParser";
+import GrimoireInterface from "../../src/Core/GrimoireInterface";
+import Identity from "../../src/Core/Identity";
+import Namespace from "../../src/Core/Namespace";
+import XMLReader from "../../src/Tool/XMLReader";
+import {
+ registerConflictComponent1,
+ registerConflictComponent2,
+ registerConflictNode1,
+ registerConflictNode2,
+ registerGoml,
+ registerStringConverter,
+ registerTestComponent1,
+ registerTestComponent2,
+ registerTestComponentBase,
+ registerTestComponentOptional,
+ registerTestNode1,
+ registerTestNode2,
+ registerTestNodeBase,
+} from "../DummyObjectRegisterer";
+import fs from "../fileHelper";
+import TestEnvManager from "../TestEnvManager";
+
+TestEnvManager.init();
+
+// Get element from test case source which is located with relative path.
+function obtainElementTag(path) {
+ return XMLReader.parseXML(fs.readFile(path));
+}
+
+function registerUserPlugin() {
+ GrimoireInterface.registerNode("scenes");
+ GrimoireInterface.registerNode("scene");
+}
+
+let stringConverterSpy,
+ testComponent1Spy,
+ testComponent2Spy,
+ testComponentBaseSpy,
+ testComponentOptionalSpy,
+ conflictComponent1Spy,
+ conflictComponent2Spy;
+const gomlParserTestCasePath1 = "../_TestResource/GomlParserTest_Case1.goml";
+const gomlParserTestCasePath2 = "../_TestResource/GomlParserTest_Case2.goml";
+const gomlParserTestCasePath3 = "../_TestResource/GomlParserTest_Case3.goml";
+const gomlParserTestCasePath4 = "../_TestResource/GomlParserTest_Case4.goml";
+
+test.beforeEach(async() => {
+ GrimoireInterface.clear();
+ registerGoml();
+ registerTestNode1();
+ registerTestNode2();
+ registerTestNodeBase();
+ registerConflictNode1();
+ registerConflictNode2();
+ stringConverterSpy = registerStringConverter();
+ testComponent1Spy = registerTestComponent1();
+ testComponent2Spy = registerTestComponent2();
+ testComponentBaseSpy = registerTestComponentBase();
+ testComponentOptionalSpy = registerTestComponentOptional();
+ conflictComponent1Spy = registerConflictComponent1();
+ conflictComponent2Spy = registerConflictComponent2();
+ registerUserPlugin();
+ await GrimoireInterface.resolvePlugins();
+});
+
+test("test for parsing node hierarchy.", (t) => {
+ const element = obtainElementTag(gomlParserTestCasePath1);
+ const node = GomlParser.parse(element);
+ t.truthy(node.parent === null);
+ t.truthy(node.children.length === 1);
+ const c = node.children[0];
+ t.truthy(c.parent === node);
+ t.truthy(c.children.length === 2);
+ t.truthy(c.children[0].children.length === 0);
+ t.truthy(c.children[0].parent === c);
+ t.truthy(c.children[1].children.length === 0);
+ t.truthy(c.children[1].parent === c);
+});
+
+test("test for send/broadcastMessage and component Attribute parsing.", (t) => {
+ const element = obtainElementTag(gomlParserTestCasePath2);
+ const node = GomlParser.parse(element);
+ t.truthy(node.parent === null);
+ assert.notCalled(stringConverterSpy);
+});
+
+test("test for parse user-define component.", (t) => {
+ const element = obtainElementTag(gomlParserTestCasePath3);
+ const node = GomlParser.parse(element);
+ node.setMounted(true);
+
+ t.truthy(node.children.length === 1); // only test-node1
+ t.truthy(node.children[0].getAttribute("testAttr1") === "hugahuga"); // goml default
+ t.truthy(node.children[0].getAttribute("hoge") === "DEFAULT"); // component default
+ t.truthy(node.children[0].children.length === 1);
+ t.truthy(node.children[0].children[0].getAttribute("testAttr2") === "123");
+ node.broadcastMessage("onTest", "testArg");
+ assert.neverCalledWith(testComponent1Spy, "testArg");
+ assert.neverCalledWith(testComponent2Spy, "testArg");
+ assert.neverCalledWith(testComponentOptionalSpy, "testArg");
+ t.truthy("testArg" === testComponentBaseSpy.args[2][1]);
+});
+
+test("test for namespace parsing.", (t) => {
+ const element = obtainElementTag(gomlParserTestCasePath4);
+ const node = GomlParser.parse(element);
+ node.setMounted(true);
+ node.broadcastMessage("onTest", "testArg");
+ assert.calledWith(conflictComponent1Spy, "aaa");
+ assert.calledWith(conflictComponent2Spy, "bbb");
+});
+
+test("test for companion", (t) => {
+ const element = obtainElementTag(gomlParserTestCasePath4);
+ const node = GomlParser.parse(element);
+ const components = node.children[0].getComponents();
+ const ns1 = Identity.fromFQN("test1.ConflictComponent");
+ const ns2 = Identity.fromFQN("test2.ConflictComponent");
+ const compo1 = components.find((comp) => ns1.fqn === comp.name.fqn);
+ const compo2 = components.find((comp) => ns2.fqn === comp.name.fqn);
+ t.truthy(compo1.companion === compo2.companion);
+});
+
+test("treeInterface must be same if the node is included in same tree", (t) => {
+ const element = obtainElementTag(gomlParserTestCasePath4);
+ const node = GomlParser.parse(element);
+ const original = node["_treeInterface"];
+ node.callRecursively(v => {
+ t.truthy(original === v["_treeInterface"]);
+ });
+});
+
+const testcases = [
+ {
+ source: gomlParserTestCasePath1,
+ expected: {
+ name: "goml",
+ children: [{
+ name: "goml",
+ children: [
+ { name: "goml" },
+ { name: "goml" },
+ ],
+ }],
+ },
+ },
+ {
+ source: gomlParserTestCasePath2,
+ expected: {
+ name: "goml",
+ attributes: { testAttr: "node default Value" },
+ children: [
+ {
+ name: "goml",
+ attributes: { testAttr: "hogehoge" },
+ },
+ {
+ name: "goml",
+ },
+ ],
+ },
+ },
+ {
+ source: gomlParserTestCasePath3,
+ expected: {
+ name: "goml",
+ children: [
+ {
+ name: "test-node1",
+ attributes: { testAttr1: "hugahuga" },
+ children: [
+ {
+ name: "test-node2",
+ attributes: { testAttr2: "123", inheritAttr: "hogehoge" },
+ optionalComponents: [
+ {
+ name: "TestComponentOptional",
+ attributes: { value: "999" },
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ },
+ {
+ source: gomlParserTestCasePath4,
+ expected: {
+ name: "goml",
+ children: [
+ {
+ name: "test1.conflict-node",
+ optionalComponents: [
+ {
+ name: "test1.ConflictComponent",
+ },
+ {
+ name: "test2.ConflictComponent",
+ },
+ ],
+ },
+ {
+ name: "test2.conflict-node",
+ },
+ ],
+ },
+ },
+];
+
+testcases.forEach((testcase, i) => {
+ test(`parseToGOM works correctly (${i})`, (t) => {
+ const result = GomlParser.parseToGOM(obtainElementTag(testcase.source));
+ t.deepEqual(result, testcase.expected);
+ });
+});
diff --git a/test/@/GrimoireInterfaceTest.ts b/test/Core/GrimoireInterfaceTest.ts
similarity index 72%
rename from test/@/GrimoireInterfaceTest.ts
rename to test/Core/GrimoireInterfaceTest.ts
index 22e76db1d..97684bcaf 100644
--- a/test/@/GrimoireInterfaceTest.ts
+++ b/test/Core/GrimoireInterfaceTest.ts
@@ -1,36 +1,56 @@
-import "../AsyncSupport";
-import "../XMLDomInit";
-import xmldom from "xmldom";
import test from "ava";
-import sinon from "sinon";
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
-import Constants from "../../src/Base/Constants";
-import Component from "../../src/Node/Component";
-import GomlParser from "../../src/Node/GomlParser";
-import GomlLoader from "../../src/Node/GomlLoader";
-import NSIdentity from "../../src/Base/NSIdentity";
-import Namespace from "../../src/Base/Namespace";
-import GomlNode from "../../src/Node/GomlNode";
+import { assert, spy } from "sinon";
+import Component from "../../src/Core/Component";
+import Constants from "../../src/Core/Constants";
+import GomlLoader from "../../src/Core/GomlLoader";
+import GomlNode from "../../src/Core/GomlNode";
+import GomlParser from "../../src/Core/GomlParser";
+import GrimoireInterface from "../../src/Core/GrimoireInterface";
+import Identity from "../../src/Core/Identity";
+import Namespace from "../../src/Core/Namespace";
+import fs from "../fileHelper";
+import jsdomAsync from "../JsDOMAsync";
+import TestEnvManager from "../TestEnvManager";
-declare namespace global {
- let Node: any;
- let document: any;
-}
+TestEnvManager.init();
-global.Node = {
- ELEMENT_NODE: 1
-};
-global.document = new DOMParser().parseFromString("", "text/html");
+const tc1_html = fs.readFile("../_TestResource/GrimoireInterfaceTest_Case1.html");
-
-test.beforeEach(() => {
+test.beforeEach(async() => {
GrimoireInterface.clear();
GrimoireInterface.resolvePlugins();
});
-test("ns method should generate namespace generating function correctly", (t) => {
- const g = Namespace.define("grimoire");
- t.truthy(g.for("test").fqn === "grimoire.test");
+test("properties are initialized correctly", t => {
+ t.truthy(GrimoireInterface.nodeDeclarations.toArray().length > 0); // grimoire-node-base, template,,,
+ t.truthy(GrimoireInterface.converters.toArray().length > 0);
+ t.truthy(GrimoireInterface.componentDeclarations.toArray().length > 0); // GrimoireComponent and more
+});
+
+test("call as function works correctly", async t => {
+ GrimoireInterface.registerNode("goml");
+ GrimoireInterface.resolvePlugins();
+ await TestEnvManager.loadPage(tc1_html);
+ t.truthy(GrimoireInterface("*")("*").count === 3);
+ t.truthy(GrimoireInterface("*")("#testId1").count === 1);
+ t.truthy(GrimoireInterface("*")(".class").count === 0);
+});
+
+test("call as function works correctly", async t => {
+ GrimoireInterface.registerNode("goml");
+ GrimoireInterface.resolvePlugins();
+ await TestEnvManager.loadPage('');
+ t.truthy(GrimoireInterface("*")("*").count === 1);
+ t.truthy(GrimoireInterface("*")("goml").count === 1);
+});
+
+test("call as function works correctly", async t => {
+ GrimoireInterface.clear();
+ GrimoireInterface.registerNode("_grimoirejs.goml");
+ GrimoireInterface.resolvePlugins();
+ await TestEnvManager.loadPage('');
+ t.truthy(GrimoireInterface("*")("*").count === 1);
+ // t.truthy(GrimoireInterface("*")("goml").count === 1);// TODO fix?
});
test("registerComponent works correctly", (t) => {
@@ -38,8 +58,8 @@ test("registerComponent works correctly", (t) => {
const dec = GrimoireInterface.registerComponent({
componentName: "Name",
attributes: {
- attr: { converter: "String", default: "aaa" }
- }
+ attr: { converter: "String", default: "aaa" },
+ },
});
t.truthy(dec.attributes["attr"].default === "aaa");
t.truthy(GrimoireInterface.componentDeclarations.toArray().length === l + 1);
@@ -47,8 +67,8 @@ test("registerComponent works correctly", (t) => {
GrimoireInterface.registerComponent({
componentName: "Name",
attributes: {
- attr: { converter: "String", default: undefined }
- }
+ attr: { converter: "String", default: undefined },
+ },
});
});
@@ -63,24 +83,24 @@ test("registerComponent works correctly", (t) => {
});
});
-test("registerComponent by object works correctly", async (t) => {
+test("registerComponent by object works correctly", async(t) => {
const defaultComponentCount = GrimoireInterface.componentDeclarations.toArray().length;
GrimoireInterface.registerComponent({
componentName: "Aaa",
attributes: {
testValue: {
converter: "String",
- default: "bbb"
+ default: "bbb",
},
testOverride: {
converter: "String",
- default: "bbb"
- }
+ default: "bbb",
+ },
},
hoge: 0,
- $test: function() {
+ $test() {
this.hoge += 1;
- }
+ },
});
const aaa = GrimoireInterface.componentDeclarations.get("Aaa");
@@ -104,16 +124,16 @@ test("registerComponent by object works correctly", async (t) => {
attributes: {
testValue2: {
converter: "String",
- default: "ccc"
+ default: "ccc",
},
testOverride: {
converter: "String",
- default: "ccc"
- }
+ default: "ccc",
+ },
},
- $test2: function() {
+ $test2() {
// do nothing.
- }
+ },
}, "Aaa");
t.truthy(GrimoireInterface.componentDeclarations.toArray().length === defaultComponentCount + 2);
const bbb = GrimoireInterface.componentDeclarations.get("Bbb");
@@ -132,7 +152,7 @@ test("registerComponent by object works correctly", async (t) => {
t.truthy((bbb2 as any).$test);
t.truthy((bbb2 as any).$test2);
});
-test("registerComponent by class works correctly", async (t) => {
+test("registerComponent by class works correctly", async(t) => {
const defaultComponentCount = GrimoireInterface.componentDeclarations.toArray().length;
class Aaa extends Component {
@@ -140,12 +160,12 @@ test("registerComponent by class works correctly", async (t) => {
public static attributes = {
testValue: {
converter: "String",
- default: "bbb"
+ default: "bbb",
},
testOverride: {
converter: "String",
- default: "bbb"
- }
+ default: "bbb",
+ },
};
public hoge = 0;
public $test() {
@@ -160,12 +180,12 @@ test("registerComponent by class works correctly", async (t) => {
public static attributes = {
testValue2: {
converter: "String",
- default: "ccc"
+ default: "ccc",
},
testOverride: {
converter: "String",
- default: "ccc"
- }
+ default: "ccc",
+ },
};
public fuga = 7;
public $test2() {
@@ -218,19 +238,19 @@ test("registerComponent by class works correctly", async (t) => {
t.truthy((bbb2 as any).overridedFunc() === 7);
});
-test("registerComponent works correctly4", async (t) => {
+test("registerComponent works correctly4", async(t) => {
const defaultComponentCount = GrimoireInterface.componentDeclarations.toArray().length;
class Aaa extends Component {
public static componentName = "Aaa";
public static attributes: { [key: string]: any } = {
testValue: {
converter: "String",
- default: "bbb"
+ default: "bbb",
},
testOverride: {
converter: "String",
- default: "bbb"
- }
+ default: "bbb",
+ },
};
public hoge = 0;
public $test() {
@@ -242,12 +262,12 @@ test("registerComponent works correctly4", async (t) => {
public static attributes = {
testValue2: {
converter: "String",
- default: "bbb"
+ default: "bbb",
},
testOverride: {
converter: "String",
- default: "ccc"
- }
+ default: "ccc",
+ },
};
public fuga = 7;
public $test2() {
@@ -295,18 +315,19 @@ test("registerNode/Component works correctly.", async t => {
GrimoireInterface.registerNode("a1");
GrimoireInterface.registerNode("a2", ["Hoge"]);
GrimoireInterface.registerNode("a3", [], { hoge: 7 }, "a2");
- GrimoireInterface.registerComponent("Hoge", {
+ GrimoireInterface.registerComponent({
+ componentName: "Hoge",
attributes: {
hoge: {
converter: "Number",
- default: 9
- }
- }
+ default: 9,
+ },
+ },
});
await GrimoireInterface.resolvePlugins();
- let a1 = GrimoireInterface.nodeDeclarations.get("a1");
- let a2 = GrimoireInterface.nodeDeclarations.get("a2");
- let a3 = GrimoireInterface.nodeDeclarations.get("a3");
+ const a1 = GrimoireInterface.nodeDeclarations.get("a1");
+ const a2 = GrimoireInterface.nodeDeclarations.get("a2");
+ const a3 = GrimoireInterface.nodeDeclarations.get("a3");
t.truthy(a1.defaultComponentsActual.toArray().length === 1); // grimoireCompone
t.truthy(a2.defaultComponentsActual.toArray().length === 2); // grimoireCompone
t.truthy(a3.defaultComponentsActual.toArray().length === 2); // grimoireCompone
@@ -326,13 +347,13 @@ test("throw error on attempt registerComponent/Node by duplicate name.", t => {
});
});
-test("register and resolvePlugins works preperly", async () => {
- const spy1 = sinon.spy();
- const spy2 = sinon.spy();
- const wrapPromise: any = function(spy) {
+test("register and resolvePlugins works preperly", async() => {
+ const spy1 = spy();
+ const spy2 = spy();
+ const wrapPromise: any = function(s) {
return () => {
return new Promise(resolve => {
- spy();
+ s();
resolve(null);
});
};
@@ -342,5 +363,5 @@ test("register and resolvePlugins works preperly", async () => {
GrimoireInterface.register(spyp);
GrimoireInterface.register(spyp2);
await GrimoireInterface.resolvePlugins();
- sinon.assert.callOrder(spy1, spy2);
+ assert.callOrder(spy1, spy2);
});
diff --git a/test/Base/NamespacedDictionaryTest.ts b/test/Core/IdentityMapTest.ts
similarity index 72%
rename from test/Base/NamespacedDictionaryTest.ts
rename to test/Core/IdentityMapTest.ts
index 9eb989c1a..2f7722a76 100644
--- a/test/Base/NamespacedDictionaryTest.ts
+++ b/test/Core/IdentityMapTest.ts
@@ -1,22 +1,25 @@
-import "../AsyncSupport";
-import "../XMLDomInit";
+import fs from "../fileHelper";
+import GomlLoader from "../../src/Core/GomlLoader";
+import NodeInterface from "../../src/Core/NodeInterface";
+import NSDictionary from "../../src/Core/IdentityMap";
+import Identity from "../../src/Core/Identity";
import test from "ava";
-import sinon from "sinon";
+import TestEnvManager from "../TestEnvManager";
import xhrmock from "xhr-mock";
-import GomlLoader from "../../src/Node/GomlLoader";
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
-import NodeInterface from "../../src/Interface/NodeInterface";
-import NSIdentity from "../../src/Base/NSIdentity";
-import NSDictionary from "../../src/Base/NSDictionary";
-import fs from "../fileHelper";
+import xmldom from "xmldom";
+
+
const xml = fs.readFile("../_TestResource/NSDictionary_QueryDOM.xml");
+
+TestEnvManager.init();
+
test.beforeEach(() => {
- NSIdentity.clear();
+ Identity.clear();
});
-test("set element correctly", (t) => {
- const newKey = NSIdentity.fromFQN("hoge.test");
+test("set element correctly", t => {
+ const newKey = Identity.fromFQN("hoge.test");
const value = "Grimoire";
const theDict = new NSDictionary();
theDict.set(newKey, value);
@@ -26,8 +29,8 @@ test("set element correctly", (t) => {
});
test("set element correctly when dupelicated name was given", (t) => {
- const newKey = NSIdentity.fromFQN("test");
- const secoundKey = NSIdentity.fromFQN("ns.test");
+ const newKey = Identity.fromFQN("test");
+ const secoundKey = Identity.fromFQN("ns.test");
const v1 = "gr1";
const v2 = "gr2";
const theDict = new NSDictionary();
@@ -40,8 +43,8 @@ test("set element correctly when dupelicated name was given", (t) => {
});
test("element should be repalaced when dupelicated fqn was given", (t) => {
- const newKey = NSIdentity.fromFQN("test");
- const secoundKey = NSIdentity.fromFQN("Test");
+ const newKey = Identity.fromFQN("test");
+ const secoundKey = Identity.fromFQN("Test");
const theDict = new NSDictionary();
theDict.set(newKey, "test1");
theDict.set(secoundKey, "test2");
@@ -50,12 +53,12 @@ test("element should be repalaced when dupelicated fqn was given", (t) => {
});
test("get element with strict name", async (t) => {
- const newKey = NSIdentity.fromFQN("test");
- const secoundKey = NSIdentity.fromFQN("test.test");
+ const newKey = Identity.fromFQN("test");
+ const secoundKey = Identity.fromFQN("test.test");
const theDict = new NSDictionary();
theDict.set(newKey, "test1");
theDict.set(secoundKey, "test2");
- const domParser = new DOMParser();
+ const domParser = new xmldom.DOMParser();
const parsed = domParser.parseFromString(xml, "text/xml");
const idElement = parsed.getElementById("test");
@@ -69,12 +72,12 @@ test("get element with strict name", async (t) => {
});
test("get element with shortened namespace prefix", async (t) => {
- const newKey = NSIdentity.fromFQN("test");
- const secoundKey = NSIdentity.fromFQN("grimoirejs.test");
+ const newKey = Identity.fromFQN("test");
+ const secoundKey = Identity.fromFQN("grimoirejs.test");
const theDict = new NSDictionary();
theDict.set(newKey, "test1");
theDict.set(secoundKey, "test2");
- const domParser = new DOMParser();
+ const domParser = new xmldom.DOMParser();
const parsed = domParser.parseFromString(xml, "text/xml");
const idElement = parsed.getElementById("test2");
const attr = idElement.attributes.item(1);
@@ -86,10 +89,10 @@ test("get element with shortened namespace prefix", async (t) => {
});
});
test("get element with shortened namespace prefix", async (t) => {
- const newKey = NSIdentity.fromFQN("test");
+ const newKey = Identity.fromFQN("test");
const theDict = new NSDictionary();
theDict.set(newKey, "test");
- const domParser = new DOMParser();
+ const domParser = new xmldom.DOMParser();
const parsed = domParser.parseFromString(xml, "text/xml");
const idElement = parsed.getElementById("test2");
const attr = idElement.attributes.item(1);
@@ -98,10 +101,10 @@ test("get element with shortened namespace prefix", async (t) => {
});
test("get element with fuzzy name", async (t) => {
- const secoundKey = NSIdentity.fromFQN("grimoirejs.test");
+ const secoundKey = Identity.fromFQN("grimoirejs.test");
const theDict = new NSDictionary();
theDict.set(secoundKey, "test2");
- const domParser = new DOMParser();
+ const domParser = new xmldom.DOMParser();
const parsed = domParser.parseFromString(xml, "text/xml");
const idElement = parsed.getElementById("test2");
const attr = idElement.attributes.item(1);
@@ -112,12 +115,12 @@ test("get element with fuzzy name", async (t) => {
});
test("get element with ambiguous name should throw error", async (t) => {
- const newKey = NSIdentity.fromFQN("AATEST.test");
- const secoundKey = NSIdentity.fromFQN("AATEST2.test");
+ const newKey = Identity.fromFQN("AATEST.test");
+ const secoundKey = Identity.fromFQN("AATEST2.test");
const theDict = new NSDictionary();
theDict.set(newKey, "test1");
theDict.set(secoundKey, "test2");
- const domParser = new DOMParser();
+ const domParser = new xmldom.DOMParser();
const parsed = domParser.parseFromString(xml, "text/xml");
const idElement = parsed.getElementById("test2");
const attr = idElement.attributes.item(1);
diff --git a/test/Core/IdentitySetTest.ts b/test/Core/IdentitySetTest.ts
new file mode 100644
index 000000000..98a247698
--- /dev/null
+++ b/test/Core/IdentitySetTest.ts
@@ -0,0 +1,14 @@
+import GomlParser from "../../src/Core/GomlParser";
+import Identity from "../../src/Core/Identity";
+import IdentitySet from "../../src/Core/IdentitySet";
+import test from "ava";
+
+
+test("test parse for goml parser", (t) => {
+ const name = Identity.fromFQN("namespace1.name1");
+ const set = new IdentitySet();
+ set.push(name);
+ const array = set.toArray();
+ t.truthy(array.length === 1);
+ t.truthy(array[0].name === "name1");
+});
diff --git a/test/Core/IdentityTest.ts b/test/Core/IdentityTest.ts
new file mode 100644
index 000000000..4ec7d0053
--- /dev/null
+++ b/test/Core/IdentityTest.ts
@@ -0,0 +1,64 @@
+import Identity from "../../src/Core/Identity";
+import test from "ava";
+import TestEnvManager from "../TestEnvManager";
+
+
+TestEnvManager.init();
+
+test.beforeEach(() => {
+ Identity.clear();
+});
+
+test("generate instance works correctly", t => {
+ let inst = Identity.fromFQN("hoge");
+ t.truthy(inst.fqn === "hoge");
+ t.truthy(Identity.fromFQN("hoge") === inst); // instance is singleton for same fqn.
+});
+
+test("Not accept to get invalid name or namespace", (t) => {
+ Identity.fromFQN("hoge");
+ Identity.fromFQN("other.a.hoge");
+ Identity.fromFQN("other.b.hoge");
+ Identity.fromFQN("a.b");
+ t.throws(() => {
+ Identity.guess("aaa"); // not found
+ });
+ t.throws(() => {
+ Identity.guess("b", "a"); // not found
+ });
+ t.throws(() => {
+ Identity.guess("Wrongamespace", "WrongName"); // not found
+ });
+
+ t.truthy(Identity.guess("hoge").fqn === "hoge"); // ok because strict fqn match.
+ t.truthy(Identity.guess("a", "b").fqn === "a.b");
+ t.truthy(Identity.guess("b").fqn === "a.b");
+
+ t.throws(() => {
+ Identity.guess("a"); // not name
+ });
+ t.throws(() => {
+ let a = Identity.guess("other.hoge"); // ambiguous
+ console.log(a);
+ });
+ t.truthy(Identity.guess("a.hoge").fqn === "other.a.hoge");
+});
+
+test("Transform name and ns correctly", (t) => {
+ const i = Identity.fromFQN("ns.ns1.Sample");
+ t.truthy(i.name === "Sample");
+ t.truthy(i.ns.qualifiedName === "ns.ns1");
+});
+
+test("isMatch works correctly", t => {
+ let hoge = Identity.fromFQN("a.b.c");
+ t.truthy(hoge.isMatch("c"));
+ t.truthy(hoge.isMatch("b.c"));
+ t.truthy(hoge.isMatch("a.c"));
+ t.truthy(hoge.isMatch("a.b.c"));
+ t.truthy(!hoge.isMatch("c.c"));
+ t.truthy(!hoge.isMatch("b.a.c"));
+ t.truthy(!hoge.isMatch("b"));
+ t.truthy(!hoge.isMatch("d"));
+ t.truthy(!hoge.isMatch("a.d"));
+});
diff --git a/test/Core/NamespaceTest.ts b/test/Core/NamespaceTest.ts
new file mode 100644
index 000000000..b64f01089
--- /dev/null
+++ b/test/Core/NamespaceTest.ts
@@ -0,0 +1,66 @@
+import Component from "../../src/Core/Component";
+import Constants from "../../src/Core/Constants";
+import GomlLoader from "../../src/Core/GomlLoader";
+import GomlNode from "../../src/Core/GomlNode";
+import GomlParser from "../../src/Core/GomlParser";
+import GrimoireInterface from "../../src/Core/GrimoireInterface";
+import Namespace from "../../src/Core/Namespace";
+import test from "ava";
+import TestEnvManager from "../TestEnvManager";
+
+TestEnvManager.init();
+
+test("define/for function works correctly.", (t) => { // TODO test
+ const g = Namespace.define("grimoire");
+ t.truthy(g.for("test").fqn === "grimoire.test");
+});
+
+test("constructor is works correctly.", t => {
+ let ns = Namespace.define("a").extend("b");
+ t.truthy(ns.qualifiedName === "a.b");
+ t.truthy(ns.hierarchy.length === 2);
+
+ ns = Namespace.define("a", "b", "c");
+ t.truthy(ns.hierarchy.length === 3);
+ t.truthy(ns.qualifiedName === "a.b.c");
+
+ let ns2 = ns.for("name");
+ t.truthy(ns2.fqn === "a.b.c.name");
+});
+
+test("check some edge cases.", t => {
+ const edgeTestCase = [
+ [Namespace.define("a").extend("b"), "a.b"],
+ [Namespace.define("a.b"), "a.b"],
+ [Namespace.define(""), ""],
+ [Namespace.define("a"), "a"],
+ [Namespace.define("").extend(""), ""],
+ [Namespace.define("a").extend(""), "a"],
+ [Namespace.define("").extend("a"), "a"],
+ [Namespace.define("a.b").extend("c.d"), "a.b.c.d"],
+ ];
+
+ edgeTestCase.forEach(element => {
+ let ns = element[0] as Namespace;
+ let expected = element[1];
+ t.truthy(ns.qualifiedName === expected);
+ });
+ for (let i = 0; i < edgeTestCase.length; i++) {
+ let element = edgeTestCase[i];
+ let ns = element[0] as Namespace;
+ let expected = element[1];
+ t.truthy(ns.qualifiedName === expected, `$testcase: {i}`);
+ }
+
+ const raiseExceptionTestCase = [
+ () => Namespace.define(null),
+ () => Namespace.define("a").extend(null),
+ () => Namespace.define("a").for(null),
+ ];
+
+ for (let i = 0; i < raiseExceptionTestCase.length; i++) {
+ t.throws(() => {
+ raiseExceptionTestCase[i]();
+ });
+ }
+});
diff --git a/test/Core/NodeDeclarationTest.ts b/test/Core/NodeDeclarationTest.ts
new file mode 100644
index 000000000..91deb5a73
--- /dev/null
+++ b/test/Core/NodeDeclarationTest.ts
@@ -0,0 +1,5 @@
+import test from "ava";
+
+test("check init for attribute manager", (t) => {
+ t.truthy(true, "TODO: write test");
+});
diff --git a/test/Core/NodeInterfaceTest.ts b/test/Core/NodeInterfaceTest.ts
new file mode 100644
index 000000000..618a92c5a
--- /dev/null
+++ b/test/Core/NodeInterfaceTest.ts
@@ -0,0 +1,85 @@
+import * as _ from "lodash";
+import Environment from "../../src/Core/Environment";
+import fs from "../fileHelper";
+import GomlLoader from "../../src/Core/GomlLoader";
+import GrimoireInterface from "../../src/Core/GrimoireInterface";
+import test from "ava";
+import TestEnvManager from "../TestEnvManager";
+import xhrmock from "xhr-mock";
+import {
+ registerConflictComponent1,
+ registerConflictComponent2,
+ registerConflictNode1,
+ registerConflictNode2,
+ registerGoml,
+ registerStringConverter,
+ registerTestComponent1,
+ registerTestComponent2,
+ registerTestComponent3,
+ registerTestComponentBase,
+ registerTestComponentOptional,
+ registerTestNode1,
+ registerTestNode2,
+ registerTestNode3,
+ registerTestNodeBase
+} from "../DummyObjectRegisterer";
+
+
+const testcase1_goml = fs.readFile("../_TestResource/GomlNodeTest_Case1.goml");
+const testcase1_html = fs.readFile("../_TestResource/GomlNodeTest_Case1.html");
+
+TestEnvManager.init(testcase1_html);
+TestEnvManager.mockSetup();
+TestEnvManager.mock("./GomlNodeTest_Case1.goml", testcase1_goml);
+
+
+let stringConverterSpy,
+ testComponent1Spy,
+ testComponent2Spy,
+ testComponent3Spy,
+ testComponentBaseSpy,
+ testComponentOptionalSpy,
+ conflictComponent1Spy,
+ conflictComponent2Spy;
+
+function resetSpies() {
+ stringConverterSpy.reset();
+ testComponent1Spy.reset();
+ testComponent2Spy.reset();
+ testComponent3Spy.reset();
+ testComponentBaseSpy.reset();
+ testComponentOptionalSpy.reset();
+ conflictComponent1Spy.reset();
+ conflictComponent2Spy.reset();
+}
+test.beforeEach(async () => {
+ GrimoireInterface.clear();
+
+ registerGoml();
+ registerTestNode1();
+ registerTestNode2();
+ registerTestNode3();
+ registerTestNodeBase();
+ registerConflictNode1();
+ registerConflictNode2();
+ stringConverterSpy = registerStringConverter();
+ testComponent1Spy = registerTestComponent1();
+ testComponent2Spy = registerTestComponent2();
+ testComponent3Spy = registerTestComponent3();
+ testComponentBaseSpy = registerTestComponentBase();
+ testComponentOptionalSpy = registerTestComponentOptional();
+ conflictComponent1Spy = registerConflictComponent1();
+ conflictComponent2Spy = registerConflictComponent2();
+ await GrimoireInterface.resolvePlugins();
+ await GomlLoader.loadForPage();
+});
+
+
+test("count first single.", (t) => {
+ const ni = GrimoireInterface("script")("goml");
+ // console.log(ni.nodes)
+ // t.truthy(ni.count() === 1);
+ // t.truthy(ni.first());
+ t.truthy(true);
+ // TODO add test
+});
diff --git a/test/DummyObjectRegisterer.ts b/test/DummyObjectRegisterer.ts
new file mode 100644
index 000000000..746ced208
--- /dev/null
+++ b/test/DummyObjectRegisterer.ts
@@ -0,0 +1,232 @@
+import GrimoireInterface from "../src/Core/GrimoireInterface";
+import Namespace from "../src/Core/Namespace";
+import { spy } from "sinon";
+
+export function registerTestComponent1() {
+ const s = spy();
+ GrimoireInterface.registerComponent({
+ componentName: "TestComponent1",
+ attributes: {
+ testAttr1: {
+ converter: "Str",
+ default: null
+ },
+ hoge: {
+ converter: "Str",
+ default: "DEFAULT"
+ }
+ },
+ $onTest: function (arg) {
+ s("onTest", arg);
+ },
+ $mount: function (arg) {
+ s("mount", arg);
+ },
+ $unmount: function (arg) {
+ s("unmount", arg);
+ },
+ $awake: function (arg) {
+ s("awake", arg);
+ }
+ });
+ return s;
+}
+
+export function registerTestComponent2() {
+ const s = spy();
+ GrimoireInterface.registerComponent({
+ componentName: "TestComponent2",
+ attributes: {
+ testAttr2: {
+ converter: "Str",
+ default: "tc2default"
+ }
+ },
+ $onTest: function (arg) {
+ s("onTest", arg);
+ },
+ $mount: function (arg) {
+ s("mount", arg);
+ },
+ $unmount: function (arg) {
+ s("unmount", arg);
+ },
+ $awake: function (arg) {
+ s("awake", arg);
+ }
+ });
+ return s;
+}
+
+export function registerTestComponent3() {
+ const s = spy();
+ GrimoireInterface.registerComponent({
+ componentName: "TestComponent3",
+ attributes: {
+ testAttr3: {
+ converter: "Str",
+ default: "tc2default"
+ },
+ hogehoge: {
+ converter: "Str",
+ default: "hoge"
+ },
+ hoge: {
+ converter: "Str",
+ default: "hoge"
+ }
+ },
+ $onTest: function (arg) {
+ s("onTest", arg);
+ },
+ $mount: function (arg) {
+ s("mount", arg);
+ },
+ $unmount: function (arg) {
+ s("unmount", arg);
+ },
+ $awake: function (arg) {
+ s("awake", arg);
+ }
+ });
+ return s;
+}
+
+export function registerTestComponentBase() {
+ const s = spy();
+ GrimoireInterface.registerComponent({
+ componentName: "TestComponentBase",
+ attributes: {
+ inheritAttr: {
+ converter: "Str",
+ default: "base"
+ }
+ },
+ $onTest: function (arg) {
+ s("onTest", arg);
+ },
+ $mount: function (arg) {
+ s("mount", arg);
+ },
+ $unmount: function (arg) {
+ s("unmount", arg);
+ },
+ $awake: function (arg) {
+ s("awake", arg);
+ }
+ });
+ return s;
+}
+
+export function registerTestComponentOptional() {
+ const s = spy();
+ GrimoireInterface.registerComponent({
+ componentName: "TestComponentOptional",
+ attributes: {
+ value: {
+ converter: "Str",
+ default: "optional"
+ }
+ },
+ $onTest: function (arg) {
+ s("onTest", arg);
+ },
+ $mount: function (arg) {
+ s("mount", arg);
+ },
+ $unmount: function (arg) {
+ s("unmount", arg);
+ },
+ $awake: function (arg) {
+ s("awake", arg);
+ }
+ });
+ return s;
+}
+
+export function registerConflictComponent1() {
+ const s = spy();
+ const ns = Namespace.define("test1");
+ GrimoireInterface.registerComponent({
+ componentName: ns.for("ConflictComponent"),
+ attributes: {
+ value: {
+ converter: "Str",
+ default: "aaa"
+ }
+ },
+ $onTest: function () {
+ s(this.attributes.get("value").Value);
+ }
+ });
+ return s;
+}
+
+export function registerConflictComponent2() {
+ const s = spy();
+ const ns = Namespace.define("test2");
+ GrimoireInterface.registerComponent({
+ componentName: ns.for("ConflictComponent"),
+ attributes: {
+ value: {
+ converter: "Str",
+ default: "bbb"
+ }
+ },
+ $onTest: function () {
+ s(this.attributes.get("value").Value);
+ }
+ });
+ return s;
+}
+
+
+
+// Nodes
+export function registerGoml() {
+ GrimoireInterface.registerNode("goml");
+}
+
+export function registerTestNode1() {
+ GrimoireInterface.registerNode("test-node1", ["TestComponent1"]);
+}
+
+export function registerTestNode2() {
+ GrimoireInterface.registerNode("test-node2", ["TestComponent2"], null, "test-node-base");
+}
+
+export function registerTestNode3() {
+ GrimoireInterface.registerNode("test-node3", ["TestComponent3"], { hoge: "AAA" });
+}
+
+export function registerTestNodeBase() {
+ GrimoireInterface.registerNode("test-node-base", ["TestComponentBase"]);
+}
+
+export function registerConflictNode1() {
+ const ns = Namespace.define("test1");
+ GrimoireInterface.registerNode(ns.for("conflict-node"), ["TestComponent2"], {
+ attr1: "nodeA"
+ }, null, null);
+}
+
+export function registerConflictNode2() {
+ const ns = Namespace.define("test2");
+ GrimoireInterface.registerNode(ns.for("conflict-node"), ["TestComponent2"], {
+ attr1: "nodeB"
+ }, null, null);
+}
+
+
+// Converters
+export function registerStringConverter() {
+ const s = spy();
+ GrimoireInterface.registerConverter("Str", (arg) => {
+ s(arg);
+ if (typeof arg === "string" || !arg) {
+ return arg;
+ }
+ throw new Error("Not Implemented:" + arg);
+ });
+ return s;
+}
diff --git a/test/Interfaces/NodeInterfaceTest.ts b/test/Interfaces/NodeInterfaceTest.ts
deleted file mode 100644
index 09e3ea872..000000000
--- a/test/Interfaces/NodeInterfaceTest.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-import "../AsyncSupport";
-import "../XMLDomInit";
-import test from "ava";
-import sinon from "sinon";
-import xmldom from "xmldom";
-import xhrmock from "xhr-mock";
-import * as _ from "lodash";
-import {
- goml,
- stringConverter,
- testComponent1,
- testComponent2,
- testComponent3,
- testComponentBase,
- testComponentOptional,
- testNode1,
- testNode2,
- testNode3,
- testNodeBase,
- conflictNode1,
- conflictNode2,
- conflictComponent1,
- conflictComponent2
-} from "../Node/GomlParserTest_Registering";
-import GomlLoader from "../../src/Node/GomlLoader";
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
-import fs from "../fileHelper";
-
-const testcase1_goml = fs.readFile("../_TestResource/GomlNodeTest_Case1.goml");
-const testcase1_html = fs.readFile("../_TestResource/GomlNodeTest_Case1.html");
-
-xhrmock.setup();
-xhrmock.get("./GomlNodeTest_Case1.goml", (req, res) => {
- return res.status(200).body(testcase1_goml);
-});
-
-let stringConverterSpy,
- testComponent1Spy,
- testComponent2Spy,
- testComponent3Spy,
- testComponentBaseSpy,
- testComponentOptionalSpy,
- conflictComponent1Spy,
- conflictComponent2Spy;
-
-function resetSpies() {
- stringConverterSpy.reset();
- testComponent1Spy.reset();
- testComponent2Spy.reset();
- testComponent3Spy.reset();
- testComponentBaseSpy.reset();
- testComponentOptionalSpy.reset();
- conflictComponent1Spy.reset();
- conflictComponent2Spy.reset();
-}
-declare namespace global {
- let document: any;
- let Node: any;
-}
-
-test.beforeEach(async () => {
- GrimoireInterface.clear();
- const parser = new DOMParser();
- const htmlDoc = parser.parseFromString(testcase1_html, "text/html");
- global.document = htmlDoc;
- global.document.querySelectorAll = function(selector) {
- return global.document.getElementsByTagName("script");
- };
- global.Node = {
- ELEMENT_NODE: 1
- };
- goml();
- testNode1();
- testNode2();
- testNode3();
- testNodeBase();
- conflictNode1();
- conflictNode2();
- stringConverterSpy = stringConverter();
- testComponent1Spy = testComponent1();
- testComponent2Spy = testComponent2();
- testComponent3Spy = testComponent3();
- testComponentBaseSpy = testComponentBase();
- testComponentOptionalSpy = testComponentOptional();
- conflictComponent1Spy = conflictComponent1();
- conflictComponent2Spy = conflictComponent2();
- await GrimoireInterface.resolvePlugins();
- await GomlLoader.loadForPage();
- global["rootNode"] = _.values(GrimoireInterface.rootNodes)[0];
- global["rootNode"].element.ownerDocument = global["document"];
-});
-
-test("count first single.", (t) => {
- const ni = GrimoireInterface("script")("goml");
- // console.log(ni.nodes)
- // t.truthy(ni.count() === 1);
- // t.truthy(ni.first());
- t.truthy(true);
-
-});
diff --git a/test/Node/GomlLoaderTest.ts b/test/Node/GomlLoaderTest.ts
deleted file mode 100644
index e13d503d9..000000000
--- a/test/Node/GomlLoaderTest.ts
+++ /dev/null
@@ -1,143 +0,0 @@
-import "../AsyncSupport";
-import "../XMLDomInit";
-import prequire from "proxyquire";
-import jsdomAsync from "../JsDOMAsync";
-import test from "ava";
-import sinon from "sinon";
-import xhrmock from "xhr-mock";
-import XMLReader from "../../src/Base/XMLReader";
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
-import GomlParser from "../../src/Node/GomlParser";
-import fs from "../fileHelper";
-import {
- goml,
- stringConverter,
- testComponent1,
- testComponent2,
- testComponent3,
- testComponentBase,
- testComponentOptional,
- testNode1,
- testNode2,
- testNode3,
- testNodeBase,
- conflictNode1,
- conflictNode2,
- conflictComponent1,
- conflictComponent2
-} from "./GomlParserTest_Registering";
-
-declare namespace global {
- let Node: any;
- let document: any;
-}
-
-const testcase1_html = fs.readFile("../_TestResource/GomlLoaderTest_Case1.html");
-const testcase2_html = fs.readFile("../_TestResource/GomlLoaderTest_Case2.html");
-const testcase3_html = fs.readFile("../_TestResource/GomlLoaderTest_Case3.html");
-const testcase4_html = fs.readFile("../_TestResource/GomlLoaderTest_Case4.html");
-
-
-
-xhrmock.setup();
-xhrmock.get("http://grimoire.gl/index.goml", (req, res) => {
- return res.status(200).body("\n");
-});
-xhrmock.get("http://grimoire.gl/index2.goml", (req, res) => {
- return res.status(200).body("\n");
-});
-xhrmock.get("http://grimoire.gl/index3.goml", (req, res) => {
- return res.status(200).body("\n");
-});
-
-function mockXMLParse(func) {
- return prequire("../../src/Node/GomlLoader", {
- "../Base/XMLReader": {
- default: {
- parseXML: (srcHtml) => {
- func(srcHtml);
- return XMLReader.parseXML(srcHtml);
- }
- }
- }
- }).default;
-}
-
-test.beforeEach(async () => {
- GrimoireInterface.clear();
- global.Node = {
- ELEMENT_NODE: 1
- };
- goml();
- testNode1();
- testNode2();
- testComponent1();
- testComponent2();
- testNodeBase();
- testComponentBase();
-
- await GrimoireInterface.resolvePlugins();
-});
-
-test("Processing script[type=\"text/goml\"] tag correctly when the text content was existing", async (t) => {
- const window = await jsdomAsync(testcase1_html, []);
- global.document = window.document;
- const scriptTags = window.document.querySelectorAll("script[type=\"text/goml\"]");
- const spy = sinon.spy();
- const mockedParseXML = mockXMLParse(xml => {
- spy(xml.replace(/[\n\s]/g, ""));
- });
- await mockedParseXML.loadFromScriptTag(scriptTags.item(0));
- t.truthy(spy.calledWith(``));
-});
-
-test("Processing script[type=\"text/goml\"] and call parse related methods in correct order", async (t) => {
- const src = testcase1_html;
- const window = await jsdomAsync(src, []);
- global.document = window.document;
- const scriptTags = window.document.querySelectorAll("script[type=\"text/goml\"]");
- const spy = sinon.spy();
- const mockedParseXML = mockXMLParse(xml => {
- spy(xml.replace(/[\n\s]/g, ""));
- });
- await mockedParseXML.loadFromScriptTag(scriptTags.item(0));
- t.truthy(spy.calledWith(``));
-});
-
-test("Processing script[type=\"text/goml\"] tag correctly when the src attribute was existing", async (t) => {
- const src = testcase2_html;
- const window = await jsdomAsync(src, []);
- global.document = window.document;
- const scriptTags = window.document.querySelectorAll("script[type=\"text/goml\"]");
- const spy = sinon.spy();
- const mockedParseXML = mockXMLParse(xml => {
- spy(xml.replace(/[\n\s]/g, ""));
- });
-
- await mockedParseXML.loadFromScriptTag(scriptTags.item(0));
- t.truthy(spy.calledWith(``));
-});
-
-test("Processing goml scripts from query", async (t) => {
- const src = testcase3_html;
- const window = await jsdomAsync(src, []);
- global.document = window.document;
- const spy = sinon.spy();
- const mockedParseXML = mockXMLParse(xml => {
- spy(xml.trim());
- });
- await mockedParseXML.loadFromQuery("script.call");
- t.truthy(spy.calledWith("\n"));
-});
-
-test("Processing goml scripts for page", async (t) => {
- const src = testcase4_html;
- const window = await jsdomAsync(src, []);
- global.document = window.document;
- const spy = sinon.spy();
- const mockedParseXML = mockXMLParse(xml => {
- spy(xml.trim());
- });
- await mockedParseXML.loadForPage();
- t.truthy(spy.calledWith("\n"));
-});
diff --git a/test/Node/GomlParserTest.ts b/test/Node/GomlParserTest.ts
deleted file mode 100644
index 55041b1f2..000000000
--- a/test/Node/GomlParserTest.ts
+++ /dev/null
@@ -1,162 +0,0 @@
-require("babel-polyfill");
-import "../XMLDomInit";
-import test from "ava";
-import sinon from "sinon";
-import GomlParser from "../../src/Node/GomlParser";
-import xmldom from "xmldom";
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
-import NSIdentity from "../../src/Base/NSIdentity";
-import Namespace from "../../src/Base/Namespace";
-import fs from "../fileHelper";
-import {
- goml,
- stringConverter,
- testComponent1,
- testComponent2,
- testComponentBase,
- testComponentOptional,
- testNode1,
- testNode2,
- testNodeBase,
- conflictNode1,
- conflictNode2,
- conflictComponent1,
- conflictComponent2
-} from "./GomlParserTest_Registering";
-
-declare namespace global {
- let Node: any;
- let document: any;
- let rootNode: any;
-}
-
-
-// Get element from test case source which is located with relative path.
-function obtainElementTag(path) {
- const DOMParser = xmldom.DOMParser;
- global.Node = {
- ELEMENT_NODE: 1
- };
- const parser = new DOMParser();
- return parser.parseFromString(fs.readFile(path), "text/xml").documentElement;
-}
-
-let stringConverterSpy,
- testComponent1Spy,
- testComponent2Spy,
- testComponentBaseSpy,
- testComponentOptionalSpy,
- conflictComponent1Spy,
- conflictComponent2Spy;
-
-test.beforeEach(async () => {
- GrimoireInterface.clear();
- const parser = new DOMParser();
- const htmlDoc = parser.parseFromString("", "text/html");
- global.document = htmlDoc;
- goml();
- testNode1();
- testNode2();
- testNodeBase();
- conflictNode1();
- conflictNode2();
- stringConverterSpy = stringConverter();
- testComponent1Spy = testComponent1();
- testComponent2Spy = testComponent2();
- testComponentBaseSpy = testComponentBase();
- testComponentOptionalSpy = testComponentOptional();
- conflictComponent1Spy = conflictComponent1();
- conflictComponent2Spy = conflictComponent2();
- registerUserPlugin();
- await GrimoireInterface.resolvePlugins();
-});
-
-const gomlParserTestCasePath1 = "../_TestResource/GomlParserTest_Case1.goml";
-const gomlParserTestCasePath2 = "../_TestResource/GomlParserTest_Case2.goml";
-const gomlParserTestCasePath3 = "../_TestResource/GomlParserTest_Case3.goml";
-const gomlParserTestCasePath4 = "../_TestResource/GomlParserTest_Case4.goml";
-
-
-function registerUserPlugin() {
- GrimoireInterface.registerNode("scenes");
- GrimoireInterface.registerNode("scene");
-}
-
-test("aaa", t => {
- GrimoireInterface.nodeDeclarations.forEach(nm => {
- t.truthy(nm.resolvedDependency);
- });
-});
-test("bbb", async t => {
- await GrimoireInterface.resolvePlugins();
- GrimoireInterface.nodeDeclarations.forEach(nm => {
- t.truthy(nm.resolvedDependency);
- });
-});
-
-test("test for parsing node hierarchy.", (t) => {
- const element = obtainElementTag(gomlParserTestCasePath1);
- const node = GomlParser.parse(element);
- t.truthy(node.parent === null);
- t.truthy(node.children.length === 1);
- const c = node.children[0];
- t.truthy(c.parent === node);
- t.truthy(c.children.length === 2);
- t.truthy(c.children[0].children.length === 0);
- t.truthy(c.children[0].parent === c);
- t.truthy(c.children[1].children.length === 0);
- t.truthy(c.children[1].parent === c);
-});
-
-test("test for send/broadcastMessage and component Attribute parsing.", (t) => {
- const element = obtainElementTag(gomlParserTestCasePath2);
- const node = GomlParser.parse(element);
- t.truthy(node.parent === null);
- sinon.assert.notCalled(stringConverterSpy);
-});
-
-test("test for parse user-define component.", (t) => {
- const element = obtainElementTag(gomlParserTestCasePath3);
- const node = GomlParser.parse(element);
- node.setMounted(true);
-
- t.truthy(node.children.length === 1); // only test-node1
- t.truthy(node.children[0].getAttribute("testAttr1") === "hugahuga"); // goml default
- t.truthy(node.children[0].getAttribute("hoge") === "DEFAULT"); // component default
- t.truthy(node.children[0].children.length === 1);
- t.truthy(node.children[0].children[0].getAttribute("testAttr2") === "123");
- node.broadcastMessage("onTest", "testArg");
- sinon.assert.neverCalledWith(testComponent1Spy, "testArg");
- sinon.assert.neverCalledWith(testComponent2Spy, "testArg");
- sinon.assert.neverCalledWith(testComponentOptionalSpy, "testArg");
- t.truthy("testArg" === testComponentBaseSpy.args[2][1]);
-});
-
-test("test for namespace parsing.", (t) => {
- const element = obtainElementTag(gomlParserTestCasePath4);
- const node = GomlParser.parse(element);
- node.setMounted(true);
- node.broadcastMessage("onTest", "testArg");
- sinon.assert.calledWith(conflictComponent1Spy, "aaa");
- sinon.assert.calledWith(conflictComponent2Spy, "bbb");
-});
-
-test("test for companion", (t) => {
- const element = obtainElementTag(gomlParserTestCasePath4);
- const node = GomlParser.parse(element);
- const components = node.children[0].getComponents();
- const ns1 = NSIdentity.fromFQN("test1.ConflictComponent");
- const ns2 = NSIdentity.fromFQN("test2.ConflictComponent");
- const compo1 = components.find((comp) => ns1.fqn === comp.name.fqn);
- const compo2 = components.find((comp) => ns2.fqn === comp.name.fqn);
- t.truthy(compo1.companion === compo2.companion);
-});
-
-test("treeInterface must be same if the node is included in same tree", (t) => {
- const element = obtainElementTag(gomlParserTestCasePath4);
- const node = GomlParser.parse(element);
- const original = node["_treeInterface"];
- node.callRecursively(v => {
- t.truthy(original === v["_treeInterface"]);
- });
-});
diff --git a/test/Node/GomlParserTest_Registering.ts b/test/Node/GomlParserTest_Registering.ts
deleted file mode 100644
index f7f1addc8..000000000
--- a/test/Node/GomlParserTest_Registering.ts
+++ /dev/null
@@ -1,231 +0,0 @@
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
-import sinon from "sinon";
-
-export function testComponent1() {
- const spy = sinon.spy();
- GrimoireInterface.registerComponent({
- componentName: "TestComponent1",
- attributes: {
- testAttr1: {
- converter: "Str",
- default: null
- },
- hoge: {
- converter: "Str",
- default: "DEFAULT"
- }
- },
- $onTest: function(arg) {
- spy("onTest", arg);
- },
- $mount: function(arg) {
- spy("mount", arg);
- },
- $unmount: function(arg) {
- spy("unmount", arg);
- },
- $awake: function(arg) {
- spy("awake", arg);
- }
- });
- return spy;
-}
-
-export function testComponent2() {
- const spy = sinon.spy();
- GrimoireInterface.registerComponent({
- componentName: "TestComponent2",
- attributes: {
- testAttr2: {
- converter: "Str",
- default: "tc2default"
- }
- },
- $onTest: function(arg) {
- spy("onTest", arg);
- },
- $mount: function(arg) {
- spy("mount", arg);
- },
- $unmount: function(arg) {
- spy("unmount", arg);
- },
- $awake: function(arg) {
- spy("awake", arg);
- }
- });
- return spy;
-}
-
-export function testComponent3() {
- const spy = sinon.spy();
- GrimoireInterface.registerComponent({
- componentName: "TestComponent3",
- attributes: {
- testAttr3: {
- converter: "Str",
- default: "tc2default"
- },
- hogehoge: {
- converter: "Str",
- default: "hoge"
- },
- hoge: {
- converter: "Str",
- default: "hoge"
- }
- },
- $onTest: function(arg) {
- spy("onTest", arg);
- },
- $mount: function(arg) {
- spy("mount", arg);
- },
- $unmount: function(arg) {
- spy("unmount", arg);
- },
- $awake: function(arg) {
- spy("awake", arg);
- }
- });
- return spy;
-}
-
-export function testComponentBase() {
- const spy = sinon.spy();
- GrimoireInterface.registerComponent({
- componentName: "TestComponentBase",
- attributes: {
- inheritAttr: {
- converter: "Str",
- default: "base"
- }
- },
- $onTest: function(arg) {
- spy("onTest", arg);
- },
- $mount: function(arg) {
- spy("mount", arg);
- },
- $unmount: function(arg) {
- spy("unmount", arg);
- },
- $awake: function(arg) {
- spy("awake", arg);
- }
- });
- return spy;
-}
-
-export function testComponentOptional() {
- const spy = sinon.spy();
- GrimoireInterface.registerComponent({
- componentName: "TestComponentOptional",
- attributes: {
- value: {
- converter: "Str",
- default: "optional"
- }
- },
- $onTest: function(arg) {
- spy("onTest", arg);
- },
- $mount: function(arg) {
- spy("mount", arg);
- },
- $unmount: function(arg) {
- spy("unmount", arg);
- },
- $awake: function(arg) {
- spy("awake", arg);
- }
- });
- return spy;
-}
-
-export function conflictComponent1() {
- const spy = sinon.spy();
- const ns = GrimoireInterface.ns("test1");
- GrimoireInterface.registerComponent({
- componentName: ns("ConflictComponent"),
- attributes: {
- value: {
- converter: "Str",
- default: "aaa"
- }
- },
- $onTest: function() {
- spy(this.attributes.get("value").Value);
- }
- });
- return spy;
-}
-
-export function conflictComponent2() {
- const spy = sinon.spy();
- const ns = GrimoireInterface.ns("test2");
- GrimoireInterface.registerComponent({
- componentName: ns("ConflictComponent"),
- attributes: {
- value: {
- converter: "Str",
- default: "bbb"
- }
- },
- $onTest: function() {
- spy(this.attributes.get("value").Value);
- }
- });
- return spy;
-}
-
-
-
-// Nodes
-export function goml() {
- GrimoireInterface.registerNode("goml");
-}
-
-export function testNode1() {
- GrimoireInterface.registerNode("test-node1", ["TestComponent1"]);
-}
-
-export function testNode2() {
- GrimoireInterface.registerNode("test-node2", ["TestComponent2"], null, "test-node-base");
-}
-
-export function testNode3() {
- GrimoireInterface.registerNode("test-node3", ["TestComponent3"], { hoge: "AAA" });
-}
-
-export function testNodeBase() {
- GrimoireInterface.registerNode("test-node-base", ["TestComponentBase"]);
-}
-
-export function conflictNode1() {
- const ns = GrimoireInterface.ns("test1");
- GrimoireInterface.registerNode(ns("conflict-node"), ["TestComponent2"], {
- attr1: "nodeA"
- }, null, null);
-}
-
-export function conflictNode2() {
- const ns = GrimoireInterface.ns("test2");
- GrimoireInterface.registerNode(ns("conflict-node"), ["TestComponent2"], {
- attr1: "nodeB"
- }, null, null);
-}
-
-
-// Converters
-export function stringConverter() {
- const spy = sinon.spy();
- GrimoireInterface.registerConverter("Str", (arg) => {
- spy(arg);
- if (typeof arg === "string" || !arg) {
- return arg;
- }
- throw new Error("Not Implemented:" + arg);
- });
- return spy;
-}
diff --git a/test/Node/NamespacedSetTest.ts b/test/Node/NamespacedSetTest.ts
deleted file mode 100644
index 0ac860350..000000000
--- a/test/Node/NamespacedSetTest.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import "../XMLDomInit";
-import test from "ava";
-import GomlParser from "../../src/Node/GomlParser";
-import xmldom from "xmldom";
-import NSSet from "../../src/Base/NSSet";
-import NSIdentity from "../../src/Base/NSIdentity";
-
-
-test("test parse for goml parser", (t) => {
- const name = NSIdentity.fromFQN("namespace1.name1");
- const set = new NSSet();
- set.push(name);
- const array = set.toArray();
- t.truthy(array.length === 1);
- t.truthy(array[0].name === "name1");
-});
diff --git a/test/PageLoadingHelper.ts b/test/PageLoadingHelper.ts
deleted file mode 100644
index 3ab362c7d..000000000
--- a/test/PageLoadingHelper.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import GrimoireInterface from "../src/Interface/GrimoireInterface";
-import GomlLoader from "../src/Node/GomlLoader";
-import xhrmock from "xhr-mock";
-
-import {
- goml,
- stringConverter,
- testComponent1,
- testComponent2,
- testComponent3,
- testComponentBase,
- testComponentOptional,
- testNode1,
- testNode2,
- testNode3,
- testNodeBase,
- conflictNode1,
- conflictNode2,
- conflictComponent1,
- conflictComponent2
-} from "./Node/GomlParserTest_Registering";
-
-declare namespace global {
- let Node: any;
- let document: any;
-}
-
-export default class PageLoadingHelper {
- public static async reset(gr: typeof GrimoireInterface, html: string): Promise {
- gr.clear();
- const parser = new DOMParser();
- const htmlDoc = parser.parseFromString(html, "text/html");
-
- global.document = htmlDoc;
- global.document.querySelectorAll = function() {
- return global.document.getElementsByTagName("script");
- };
- global.Node = {
- ELEMENT_NODE: 1
- };
- goml();
- testNode1();
- testNode2();
- testNode3();
- testNodeBase();
- conflictNode1();
- conflictNode2();
- const spys: any = {};
- spys.stringConverterSpy = stringConverter();
- spys.testComponent1Spy = testComponent1();
- spys.testComponent2Spy = testComponent2();
- spys.testComponent3Spy = testComponent3();
- spys.testComponentBaseSpy = testComponentBase();
- spys.testComponentOptionalSpy = testComponentOptional();
- spys.conflictComponent1Spy = conflictComponent1();
- spys.conflictComponent2Spy = conflictComponent2();
- await gr.resolvePlugins();
- await GomlLoader.loadForPage();
- return spys;
- }
-
- public static mockSetup(): void {
- xhrmock.setup();
- }
- public static mock(path: string, content: string): void {
- xhrmock.get(path, (req, res) => {
- let aa = res.status(200).body(content);
- return aa;
- });
- }
-}
diff --git a/test/TestEnvManager.ts b/test/TestEnvManager.ts
new file mode 100644
index 000000000..b47f951ff
--- /dev/null
+++ b/test/TestEnvManager.ts
@@ -0,0 +1,47 @@
+import "babel-polyfill";
+import xhrmock from "xhr-mock";
+import xmlserializer from "xmlserializer";
+import Environment from "../src/Core/Environment";
+import GomlLoader from "../src/Core/GomlLoader";
+import GomlParser from "../src/Core/GomlParser";
+import GrimoireInterface from "../src/Core/GrimoireInterface";
+import Identity from "../src/Core/Identity";
+import IdentityMap from "../src/Core/IdentityMap";
+import IAttributeConverterDeclaration from "../src/Interface/IAttributeConverterDeclaration";
+import XMLReader from "../src/Tool/XMLReader";
+import jsdomAsync from "./JsDOMAsync";
+
+export default class TestEnvManager {
+
+ public static async init(html = "") {
+ const window = await jsdomAsync(html, []);
+ Environment.DomParser = new window.DOMParser();
+
+ Environment.document = window.document;
+ Environment.Node = {
+ ELEMENT_NODE: 1,
+ };
+ Environment.XMLSerializer = xmlserializer;
+ }
+
+ public static mockSetup(): void {
+ xhrmock.setup();
+ }
+ public static mock(path: string, content: string): void {
+ xhrmock.get(path, (req, res) => {
+ return res.status(200).body(content);
+ });
+ }
+
+ public static async loadPage(html: string) {
+ const window = await jsdomAsync(html, []);
+ Environment.document = window.document;
+ await GomlLoader.loadForPage();
+ }
+
+ public static loadGoml(goml: string) {
+ const doc = XMLReader.parseXML(goml);
+ const rootNode = GomlParser.parse(doc);
+ GrimoireInterface.addRootNode(null, rootNode);
+ }
+}
diff --git a/test/TestUtil.ts b/test/TestUtil.ts
new file mode 100644
index 000000000..5d6091a69
--- /dev/null
+++ b/test/TestUtil.ts
@@ -0,0 +1,58 @@
+import Attribute from "../src/Core/Attribute";
+import Component from "../src/Core/Component";
+import ComponentDeclaration from "../src/Core/ComponentDeclaration";
+import GomlNode from "../src/Core/GomlNode";
+import GomlParser from "../src/Core/GomlParser";
+import GrimoireInterface from "../src/Core/GrimoireInterface";
+import Identity from "../src/Core/Identity";
+import IAttributeDeclaration from "../src/Interface/IAttributeDeclaration";
+import ITreeInitializedInfo from "../src/Interface/ITreeInitializedInfo";
+import Ensure from "../src/Tool/Ensure";
+import XMLReader from "../src/Tool/XMLReader";
+
+export default class TestUtil {
+
+ public static DummyComponentDeclaration(): ComponentDeclaration {
+ return new ComponentDeclaration(Identity.fromFQN("aaa"), {
+ attributes: {
+
+ },
+ });
+ }
+ public static DummyComponent(): Component {
+ const dec = TestUtil.DummyComponentDeclaration();
+ return dec.generateInstance();
+ }
+
+ public static DummyAttribute(name: Identity, component: Component, declaration: IAttributeDeclaration): Attribute {
+ const attr = new Attribute();
+ attr.name = name;
+ attr.component = component;
+ attr.declaration = declaration;
+ const converterName = Ensure.tobeCnverterIdentity(declaration.converter);
+ attr.converter = GrimoireInterface.converters.get(converterName);
+ attr.component.attributes.set(attr.name, attr);
+ attr.converter.verify(attr);
+ return attr;
+ }
+
+ public static DummyTreeInit(goml: string): GomlNode {
+ const doc = XMLReader.parseXML(goml);
+ const rootNode = GomlParser.parse(doc);
+
+ rootNode.setMounted(true);
+ rootNode.broadcastMessage("treeInitialized", {
+ ownerScriptTag: null,
+ id: rootNode.id,
+ } as ITreeInitializedInfo);
+ rootNode.sendInitializedMessage({
+ ownerScriptTag: null,
+ id: rootNode.id,
+ } as ITreeInitializedInfo);
+ return rootNode;
+ }
+
+ public static GenerateGomlEmbeddedHtml(goml: string): string {
+ return ``;
+ }
+}
diff --git a/test/Base/EnsureTest.ts b/test/Tools/EnsureTest.ts
similarity index 59%
rename from test/Base/EnsureTest.ts
rename to test/Tools/EnsureTest.ts
index bfad59b3a..cbaea0212 100644
--- a/test/Base/EnsureTest.ts
+++ b/test/Tools/EnsureTest.ts
@@ -1,17 +1,16 @@
-import "../XMLDomInit";
import test from "ava";
-import Ensure from "../../src/Base/Ensure";
-import GrimoireInterface from "../../src/Interface/GrimoireInterface";
-import NSDictionary from "../../src/Base/NSDictionary";
-import NSIdentity from "../../src/Base/NSIdentity";
-import Namespace from "../../src/Base/Namespace";
+import GrimoireInterface from "../../src/Core/GrimoireInterface";
+import Identity from "../../src/Core/Identity";
+import IdentityMap from "../../src/Core/IdentityMap";
+import Namespace from "../../src/Core/Namespace";
+import Ensure from "../../src/Tool/Ensure";
test.beforeEach(() => {
- NSIdentity.clear();
+ Identity.clear();
});
test("Ensure passed argument should be transformed as NSIdentity", (t) => {
- NSIdentity.fromFQN("grimoirejs.HELLO");
+ Identity.fromFQN("grimoirejs.HELLO");
t.truthy(Ensure.tobeNSIdentity("HELLO").fqn === "grimoirejs.HELLO");
t.truthy(Ensure.tobeNSIdentity(Namespace.define("test").for("WORLD")).fqn === "test.WORLD");
});
@@ -19,14 +18,14 @@ test("Ensure passed argument should be transformed as NSIdentity", (t) => {
test("Ensure passed argument are transformed into number", (t) => {
t.truthy(Ensure.tobeNumber("9") === 9);
t.truthy(Ensure.tobeNumber(9) === 9);
- let a: any = () => {/*do nothing*/ };
+ const a: any = () => {/*do nothing*/ };
t.throws(() => Ensure.tobeNumber(a));
});
test("Ensure passed argument are transformed into string", (t) => {
t.truthy(Ensure.tobeString("9") === "9");
t.truthy(Ensure.tobeString(9) === "9");
- let a: any = () => {/*do nothing*/ };
+ const a: any = () => {/*do nothing*/ };
t.throws(() => Ensure.tobeString(a));
});
@@ -34,8 +33,8 @@ test("Ensure passed array are transformed into NSIdentity[]", (t) => {
let transformed = Ensure.tobeNSIdentityArray(undefined);
const g = Namespace.define("test");
t.truthy(transformed.length === 0);
- NSIdentity.fromFQN("HELLO");
- NSIdentity.fromFQN("grimoire.WORLD");
+ Identity.fromFQN("HELLO");
+ Identity.fromFQN("grimoire.WORLD");
transformed = Ensure.tobeNSIdentityArray(["HELLO", "WORLD"]);
t.truthy(transformed[0].fqn === "HELLO");
t.truthy(transformed[1].fqn === "grimoire.WORLD");
@@ -45,22 +44,22 @@ test("Ensure passed array are transformed into NSIdentity[]", (t) => {
});
test("Ensure passed object are transformed into NSDictionary", (t) => {
- let transformed = Ensure.tobeNSDictionary(void 0);
- t.truthy(transformed instanceof NSDictionary);
- let obj = {};
- obj[NSIdentity.fromFQN("Hello").fqn] = "test1";
- obj[NSIdentity.fromFQN("World").fqn] = "test2";
- transformed = Ensure.tobeNSDictionary(obj);
- t.truthy(transformed instanceof NSDictionary);
+ let transformed = Ensure.tobeIdentityMap(undefined);
+ t.truthy(transformed instanceof IdentityMap);
+ const obj = {};
+ obj[Identity.fromFQN("Hello").fqn] = "test1";
+ obj[Identity.fromFQN("World").fqn] = "test2";
+ transformed = Ensure.tobeIdentityMap(obj);
+ t.truthy(transformed instanceof IdentityMap);
t.truthy(transformed.get("Hello") === "test1");
t.truthy(transformed.get("World") === "test2");
});
test("Ensure name tobe fqn if name start with _", t => {
t.truthy(Ensure.tobeFQN("aaa") == null);
- t.truthy(Ensure.tobeFQN("_aaa") == "aaa");
+ t.truthy(Ensure.tobeFQN("_aaa") === "aaa");
t.truthy(Ensure.tobeFQN("aaa.fff") == null);
- t.truthy(Ensure.tobeFQN("_aaa.fff") == "aaa.fff");
- t.truthy(Ensure.tobeFQN(NSIdentity.fromFQN("aaa.bbb")) == "aaa.bbb");
- t.truthy(Ensure.tobeFQN(NSIdentity.fromFQN("aaa")) == "aaa");
-})
+ t.truthy(Ensure.tobeFQN("_aaa.fff") === "aaa.fff");
+ t.truthy(Ensure.tobeFQN(Identity.fromFQN("aaa.bbb")) === "aaa.bbb");
+ t.truthy(Ensure.tobeFQN(Identity.fromFQN("aaa")) === "aaa");
+});
diff --git a/test/Tools/IdResolverTest.ts b/test/Tools/IdResolverTest.ts
new file mode 100644
index 000000000..3191ed33b
--- /dev/null
+++ b/test/Tools/IdResolverTest.ts
@@ -0,0 +1,73 @@
+import Component from "../../src/Core/Component";
+import Constants from "../../src/Core/Constants";
+import GomlLoader from "../../src/Core/GomlLoader";
+import GomlNode from "../../src/Core/GomlNode";
+import GomlParser from "../../src/Core/GomlParser";
+import GrimoireInterface from "../../src/Core/GrimoireInterface";
+import IdResolver from "../../src/Tool/IdResolver";
+import Namespace from "../../src/Core/Namespace";
+import Identity from "../../src/Core/Identity";
+import test from "ava";
+import TestEnvManager from "../TestEnvManager";
+
+TestEnvManager.init();
+
+test("get() works correctly.", t => {
+ const r = new IdResolver();
+ r.add(Identity.fromFQN("c.b.a"));
+ t.truthy(r.get(Namespace.define("a")).length === 1);
+ t.truthy(r.get(Namespace.define("b.a")).length === 1);
+ t.truthy(r.get(Namespace.define("c.a")).length === 1);
+ t.truthy(r.get(Namespace.define("c.b.a")).length === 1);
+});
+
+test("Not accept to get invalid name or namespace", (t) => {
+ let r = new IdResolver();
+
+ r.add(Identity.fromFQN("a"));
+ r = new IdResolver();
+
+ // console.log("a");
+ t.truthy(r.add(Identity.fromFQN("a")));
+ t.truthy(r.count === 1);
+ t.truthy(!r.add(Identity.fromFQN("a")));
+ t.truthy(r.count === 1);
+ // console.log("f");
+ r.add(Namespace.define("z").for("b"));
+ r.add(Namespace.define("y.b").hierarchy);
+ r.add(Identity.fromFQN("c"));
+ t.truthy(r.count === 4);
+ t.truthy(r.get(Namespace.define("a")).length === 1);
+ t.truthy(r.get(Namespace.define("b")).length === 2);
+
+ let id = Identity.fromFQN("a.b.c");
+ t.truthy(id.name === "c");
+ t.truthy(id.ns.qualifiedName === "a.b");
+ id = Identity.guess("b.c");
+ t.truthy(id.fqn === "a.b.c");
+
+
+});
+
+test("Not accept to get invalid name or namespace", (t) => {
+ const r = new IdResolver();
+ // console.log(r);
+ r.add(Identity.fromFQN("a"));
+ r.add(Identity.fromFQN("hoge.b"));
+ r.add(Identity.fromFQN("hage.huga.c"));
+ r.add(Identity.fromFQN("hage.a"));
+ t.truthy(r.get(Namespace.define("a")).length === 2);
+
+});
+
+test("resolve works correctly", (t) => {
+ const r = new IdResolver();
+ r.add(Identity.fromFQN("hoge.a"));
+ r.add(Identity.fromFQN("hoge.b"));
+ r.add(Identity.fromFQN("hage.huga.c"));
+ r.add(Identity.fromFQN("hage.huga.a"));
+ t.truthy(r.get(Namespace.define("a")).length === 2);
+ t.truthy(r.get(Namespace.define("b")).length === 1);
+ t.truthy(r.resolve(Namespace.define("c")) === "hage.huga.c");
+
+});
diff --git a/test/Base/UtilityTest.ts b/test/Tools/UtilityTest.ts
similarity index 50%
rename from test/Base/UtilityTest.ts
rename to test/Tools/UtilityTest.ts
index ca04d2bed..a52293fa5 100644
--- a/test/Base/UtilityTest.ts
+++ b/test/Tools/UtilityTest.ts
@@ -1,6 +1,5 @@
-import "../XMLDomInit";
import test from "ava";
-import Utility from "../../src/Base/Utility";
+import Utility from "../../src/Tool/Utility";
test("isCamelCase works correctly.", t => {
t.truthy(Utility.isCamelCase("NameName123"));
@@ -11,10 +10,10 @@ test("isCamelCase works correctly.", t => {
});
test("isSnakeCase works correctly.", t => {
- t.truthy(Utility.isSnakeCase("name-name-123"));
- t.truthy(Utility.isSnakeCase("nm"));
- t.truthy(Utility.isSnakeCase("--"));
- t.truthy(!Utility.isSnakeCase("nameName"));
- t.truthy(!Utility.isSnakeCase("Name_Name"));
- t.truthy(!Utility.isSnakeCase("1nameName"));
+ t.truthy(Utility.isKebabCase("name-name-123"));
+ t.truthy(Utility.isKebabCase("nm"));
+ t.truthy(Utility.isKebabCase("--"));
+ t.truthy(!Utility.isKebabCase("nameName"));
+ t.truthy(!Utility.isKebabCase("Name_Name"));
+ t.truthy(!Utility.isKebabCase("1nameName"));
});
diff --git a/test/Tools/XMLReaderTest.ts b/test/Tools/XMLReaderTest.ts
new file mode 100644
index 000000000..ec3803e7c
--- /dev/null
+++ b/test/Tools/XMLReaderTest.ts
@@ -0,0 +1,16 @@
+import test from "ava";
+import XMLReader from "../../src/Tool/XMLReader";
+import fs from "../fileHelper";
+import TestEnvManager from "../TestEnvManager";
+
+TestEnvManager.init();
+
+const xml = fs.readFile("../_TestResource/XMLReader_Case1.xml");
+
+test("parseXML behaves correctly", t => {
+ const parsedDocument = XMLReader.parseXML(xml);
+ t.truthy(parsedDocument.localName === "goml");
+ t.throws(() => {
+ XMLReader.parseXML(">");
+ });
+});
diff --git a/test/XMLDomInit.ts b/test/XMLDomInit.ts
deleted file mode 100644
index b8958c35b..000000000
--- a/test/XMLDomInit.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-import xmldom from "xmldom";
-global["DOMParser"] = xmldom.DOMParser;
diff --git a/test/_TestResource/Example_01.html b/test/_TestResource/Example_01.html
new file mode 100644
index 000000000..b2e35f028
--- /dev/null
+++ b/test/_TestResource/Example_01.html
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/test/_TestResource/Goml_01.goml b/test/_TestResource/Goml_01.goml
new file mode 100644
index 000000000..7b0b4e673
--- /dev/null
+++ b/test/_TestResource/Goml_01.goml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/test/_TestResource/Goml_02.goml b/test/_TestResource/Goml_02.goml
new file mode 100644
index 000000000..3ca9afd25
--- /dev/null
+++ b/test/_TestResource/Goml_02.goml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/test/_TestResource/GrimoireInterfaceTest_Case1.html b/test/_TestResource/GrimoireInterfaceTest_Case1.html
index 81281f41c..a323f54e4 100644
--- a/test/_TestResource/GrimoireInterfaceTest_Case1.html
+++ b/test/_TestResource/GrimoireInterfaceTest_Case1.html
@@ -1,43 +1,45 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
Hello world! This is HTML5 Boilerplate.
+
+
Hello world! This is HTML5 Boilerplate.
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
diff --git a/tsconfig.json b/tsconfig.json
index 12ffdbfa0..939a2f005 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -8,10 +8,10 @@
"declarationDir": "./ref",
"noImplicitReturns": true,
"noUnusedParameters": true,
- "noUnusedLocals":true,
+ "noUnusedLocals": true,
"strict": true
},
"include": [
"src/**/*.ts"
]
-}
+}
\ No newline at end of file
diff --git a/tslint.json b/tslint.json
index bd638a51e..8b4267c5b 100644
--- a/tslint.json
+++ b/tslint.json
@@ -1,61 +1,7 @@
{
- "rulesDirectory":[],
+ "extends": "./common/tslint.json",
+ "rulesDirectory": [],
"rules": {
- "class-name": true,
- "comment-format": [true, "check-space"],
- "curly": true,
- "eofline": true,
- "indent": [true, "spaces"],
- "label-position": true,
- "member-access": true,
- "member-ordering": [true,
- "public-before-private",
- "static-before-instance",
- "variables-before-functions"
- ],
- "no-arg": true,
- "no-console": [true,
- "debug",
- "time",
- "timeEnd",
- "trace"
- ],
- "no-construct": true,
- "no-debugger": true,
- "no-duplicate-variable": true,
- "no-empty": true,
- "no-eval": true,
- "no-inferrable-types": true,
- "no-shadowed-variable": true,
- "no-switch-case-fall-through": true,
- "no-trailing-whitespace": true,
- "no-unused-expression": true,
- "no-use-before-declare": true,
- "no-var-keyword": true,
- "one-line": [true,
- "check-open-brace",
- "check-catch",
- "check-else",
- "check-whitespace"
- ],
- "quotemark": [true, "double", "avoid-escape"],
- "radix": true,
- "semicolon": true,
- "triple-equals": [true, "allow-null-check"],
- "typedef-whitespace": [true, {
- "call-signature": "nospace",
- "index-signature": "nospace",
- "parameter": "nospace",
- "property-declaration": "nospace",
- "variable-declaration": "nospace"
- }],
- "variable-name": false,
- "whitespace": [true,
- "check-branch",
- "check-decl",
- "check-operator",
- "check-separator",
- "check-type"
- ]
+ "no-unused-variable": false
}
-}
+}
\ No newline at end of file
diff --git a/webpack.config.js b/webpack.config.js
index 7c2d1555a..27ab7ab83 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -54,7 +54,7 @@ const getBuildTask = (fileName, plugins, needPolyfill) => {
loaders: [{
test: /\.ts$/,
exclude: /node_modules/,
- loader: "babel-loader?presets[]=es2015,presets[]=stage-2!ts-loader"
+ loader: "babel-loader?presets[]=env,presets[]=stage-2!ts-loader"
}]
},
resolve: {
@@ -65,41 +65,42 @@ const getBuildTask = (fileName, plugins, needPolyfill) => {
}
};
-module.exports = (env) => {
+module.exports = (env = {}) => {
+ // This line might need to be modified for each plugin build environment.
+ // If the plugin containing grimoirejs directly(calling require("grimoirejs/register")),
+ // browser build and production build should contain babel-polyfill.
+ // Make sure this is not require("grimoirejs")
let includeCore = true;
- // if this package was preset including core or core package,
- // Script for browser needs babel-polyfill
- let polyfills = includeCore ? [true, false, true] : [false, false, false];
- env = env || {};
+ //
+ //
+ //
+ if (!env.browser && !env.npm && !env.prod) {
+ env.browser = true;
+ }
+ const productPlugins = [new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.AggressiveMergingPlugin()];
let buildTasks = [];
- let isDefault = !env.browser && !env.npm && !env.prod;
let skipIndex = false;
let cauldron = new CauldronPlugin();
if (env.browser || env.prod) {
- const plugins = [cauldron];
+ const plugins = [];
// if needs index also and it was not including core, index.js must be copied from fnPrefix.js
// since these are completely same build task. Yeah, optimization.
if (!includeCore && (env.prod || env.npm)) {
plugins.push(new CopyPlugin(`./register/${fnPrefix}.js`, './register/index.js'));
plugins.push(new CopyPlugin(`./register/${fnPrefix}.js.map`, './register/index.js.map'));
skipIndex = true;
+ console.log(`${index}.js will be generated for NPM environment by copy`);
}
- buildTasks.push(getBuildTask(`${fnPrefix}.js`, plugins, polyfills[0]));
+ buildTasks.push(getBuildTask(`${fnPrefix}.js`, [cauldron, ...plugins], includeCore));
+ console.log(`${fnPrefix}.js will be generated for browser environment`);
}
- if (!skipIndex && (isDefault || env.npm || env.prod)) {
- buildTasks.push(getBuildTask("index.js", [cauldron], polyfills[1]));
+ if (!skipIndex && (env.npm || env.prod)) {
+ buildTasks.push(getBuildTask("index.js", [cauldron], false));
+ console.log(`index.js will be generated for NPM environment`);
}
if (env.prod) {
- buildTasks.push(getBuildTask(fnPrefix + ".min.js", [
- cauldron,
- new webpack.optimize.UglifyJsPlugin({
- compress: {
- warnings: false
- }
- }),
- new webpack.optimize.OccurrenceOrderPlugin(),
- new webpack.optimize.AggressiveMergingPlugin()
- ], polyfills[2]));
+ buildTasks.push(getBuildTask(fnPrefix + ".min.js", [cauldron, ...productPlugins], includeCore));
+ console.log(`${fnPrefix}.min.js will be generated for browser environment`);
}
return buildTasks;
};