mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
Initial asc browser bundle, see #25
This commit is contained in:
31
tests/bundled-asc.js
Normal file
31
tests/bundled-asc.js
Normal file
@ -0,0 +1,31 @@
|
||||
var asc = require("../dist/asc.js");
|
||||
|
||||
var stdout = asc.createMemoryStream();
|
||||
var stderr = asc.createMemoryStream();
|
||||
|
||||
process.exitCode = asc.main([
|
||||
"test.ts"
|
||||
], {
|
||||
stdout: stdout,
|
||||
stderr: stderr,
|
||||
readFile: function(filename) {
|
||||
console.log("readFile: " + filename);
|
||||
if (filename === "/test.ts") { // sic: browser path
|
||||
return "export function foo(): void {}";
|
||||
}
|
||||
throw Error("File not found: " + filename);
|
||||
},
|
||||
writeFile: function(filename, contents) {
|
||||
console.log("writeFile: " + filename);
|
||||
},
|
||||
listFiles: function(dirname) {
|
||||
console.log("listFiles: " + dirname);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
console.log("stdout >>>");
|
||||
console.log(stdout.toString());
|
||||
|
||||
console.log("stderr >>>");
|
||||
console.error(stderr.toString());
|
@ -46,8 +46,9 @@ tests.forEach(filename => {
|
||||
|
||||
const basename = filename.replace(/\.ts$/, "");
|
||||
|
||||
const stdout = createMemoryStream();
|
||||
const stderr = createMemoryStream(true);
|
||||
const stdout = asc.createMemoryStream();
|
||||
const stderr = asc.createMemoryStream(chunk => process.stderr.write(chunk.toString().replace(/^(?!$)/mg, " ")));
|
||||
stderr.isTTY = true;
|
||||
|
||||
var failed = false;
|
||||
|
||||
@ -135,28 +136,6 @@ tests.forEach(filename => {
|
||||
});
|
||||
});
|
||||
|
||||
function createMemoryStream(print) {
|
||||
var stream = [];
|
||||
if (stream.print = print)
|
||||
stream.isTTY = process.stderr.isTTY;
|
||||
stream.write = function(chunk) {
|
||||
if (typeof chunk === "string") {
|
||||
this.push(Buffer.from(chunk, "utf8"));
|
||||
} else {
|
||||
this.push(chunk);
|
||||
}
|
||||
if (stream.print)
|
||||
process.stderr.write(chunk.toString().replace(/^(?!$)/mg, " "));
|
||||
};
|
||||
stream.toBuffer = function() {
|
||||
return Buffer.concat(this);
|
||||
};
|
||||
stream.toString = function() {
|
||||
return this.toBuffer().toString("utf8");
|
||||
};
|
||||
return stream;
|
||||
}
|
||||
|
||||
if (failures) {
|
||||
process.exitCode = 1;
|
||||
console.log(chalk.red("ERROR: ") + failures + " compiler tests failed");
|
||||
|
Reference in New Issue
Block a user