test file loading

mason manifest
This commit is contained in:
Blue 2023-09-16 10:01:49 -03:00
parent edc489ab1a
commit d4f8b736ed
Signed by: blue
GPG Key ID: 9B203B252A63EE38
6 changed files with 89 additions and 7 deletions

34
mason.json Normal file
View File

@ -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"
}
]
}
]
}

11
node.js
View File

@ -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);

View File

@ -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")

View File

@ -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")

View File

@ -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"
];
});

1
test/text Normal file
View File

@ -0,0 +1 @@
Lorem ipsum, I guess