diff --git a/mason.json b/mason.json new file mode 100644 index 0000000..a2c809a --- /dev/null +++ b/mason.json @@ -0,0 +1,34 @@ +{ + "version": "0.0.1", + "name": "mimicry", + "dependencies": [], + "build": [ + { + "files": [ + "dependency.js", + "errors.js", + "loadingFile.js", + "module.js", + "queue.js" + ] + }, + { + "targets": ["browser"], + "files": [ + { + "source": "browser.js", + "target": "mimicry.js" + } + ] + }, + { + "targets": ["node"], + "files": [ + { + "source": "node.js", + "target": "mimicry.js" + } + ] + } + ] +} \ No newline at end of file diff --git a/node.js b/node.js index 0260319..81faf1f 100644 --- a/node.js +++ b/node.js @@ -1,5 +1,6 @@ "use strict"; const path = require('path'); +const fs = require('fs'); const {BasicError, LoadError, FileError} = require("./errors") const LoadingFile = require("./loadingFile"); @@ -368,6 +369,7 @@ function executeLoad (/*String*/path, /*LoadingFile*/loadingFile) { //getByXHR(path, boundLoad, boundError, "arraybuffer", this._config.seed); break; case Type.text: + fs.readFile(path, "utf8", onFileRead.bind(this, path)); //getByXHR(path, boundLoad, boundError, "text", this._config.seed); break; } @@ -401,6 +403,15 @@ function onLoaded(/*String*/path, /*any*/value) { notifyProgressSubscribers.call(this); } +function onFileRead (/*String*/path, err, value) { + if (err) { + this._errors.set(path, err); + onError.call(this, path) + } else { + onLoaded.call(this, path, value); + } +} + function onError (/*String*/path) { const loading = this._loadingFiles.get(path); let error = this._errors.get(path); diff --git a/test/index.js b/test/index.js index fbbd78e..7fc6f75 100644 --- a/test/index.js +++ b/test/index.js @@ -24,15 +24,32 @@ function test () { log("Error instantiating Mimicry"); return; } + mimicry.addErrorHandler((err) => { + log(err); + }) try { mimicry.module(["module"], function (global, [module]) { log("Mimicry empty module successfully resolved"); log("The background now is supposed to be bluish if you're testing in browser") - if (module === true) + + if (module instanceof Array) { log("Value returned from additional module is correct"); - else + + let allGood = true; + for (let i = 0; i < module.length; ++i) { + if (!module[i]) { + log("Component number " + i + " returned from additional module is incorrect"); + allGood = false; + } + } + + if (allGood) + log("All components returned from additional module are correct"); + + } else { log("Value returned from additional module is \"" + module + "\", which is incorrect"); + } const json = mimicry.getAsset("simple"); if (json instanceof Object && json.I === "am") diff --git a/test/main.js b/test/main.js index 2e9667a..ad90001 100644 --- a/test/main.js +++ b/test/main.js @@ -24,10 +24,24 @@ function test () { mimicry.module(["module"], function (global, [module]) { log("Mimicry empty module successfully resolved"); log("The background now is supposed to be bluish if you're testing in browser") - if (module === true) + + if (module instanceof Array) { log("Value returned from additional module is correct"); - else + + let allGood = true; + for (let i = 0; i < module.length; ++i) { + if (!module[i]) { + log("Component number " + i + " returned from additional module is incorrect"); + allGood = false; + } + } + + if (allGood) + log("All components returned from additional module are correct"); + + } else { log("Value returned from additional module is \"" + module + "\", which is incorrect"); + } const json = mimicry.getAsset("simple"); if (json instanceof Object && json.I === "am") diff --git a/test/module.js b/test/module.js index 934bb24..ec26b75 100644 --- a/test/module.js +++ b/test/module.js @@ -2,7 +2,12 @@ mimicry.module([ "terminalModule", "simple", Mimicry.Type.json, - "background", Mimicry.Type.css -], function (global, [terminalModule, simple]) { - return terminalModule === "terminal" && simple.a[4] === 115; + "background", Mimicry.Type.css, + "text", Mimicry.Type.text +], function (global, [terminalModule, simple, background, text]) { + return [ + terminalModule === "terminal", + simple.a[4] === 115, + text === "Lorem ipsum, I guess" + ]; }); \ No newline at end of file diff --git a/test/text b/test/text new file mode 100644 index 0000000..86c02c7 --- /dev/null +++ b/test/text @@ -0,0 +1 @@ +Lorem ipsum, I guess \ No newline at end of file