Fixed: Preprocessor Output test adapted for Node

This commit is contained in:
Martin Carlberg
2021-09-10 15:55:01 +02:00
parent 52bd654850
commit 51ffa256ca
@@ -1,6 +1,7 @@
var FILE = require("file"),
compressor = require("minify/shrinksafe");
var fs = require("fs");
var path = require("path");
var terser = require("terser");
var FILENAMES = [
"Class/root-class",
@@ -30,6 +31,10 @@ var FILENAMES = [
{
}
async function compressor(srcCode) {
return (await terser.minify(srcCode)).code;
}
+ (void)initialize
{
var index = 0,
@@ -42,26 +47,26 @@ var FILENAMES = [
var filename = FILENAMES[index],
testSelector = sel_getUid("test" + FILENAMES[index]);
class_addMethod(self, testSelector, function(self, _cmd)
class_addMethod(self, testSelector, async function(self, _cmd)
{
var d = FILE.dirname(module.path),
filePath = FILE.join(d, filename + ".j"),
unpreprocessed = FILE.read(filePath, { charset:"UTF-8" }),
var d = path.dirname(__filename),
filePath = path.join(d, filename + ".j"),
unpreprocessed = fs.readFileSync(filePath, {encoding: "utf8"}),
preprocessed,
preprocessedInlined,
correct = FILE.read(FILE.join(d, filename + ".js")),
p = FILE.join(d, filename + "-inlined.js"),
correctInlined = FILE.exists(p) ? FILE.read(p) : correct; // Get inlined version if it exists. Otherwise use the regular one.
correct = fs.readFileSync(path.join(d, filename + ".js"), {encoding: "utf8"}),
p = path.join(d, filename + "-inlined.js"),
correctInlined = fs.existsSync(p) ? fs.readFileSync(p, {encoding: "utf8"}) : correct; // Get inlined version if it exists. Otherwise use the regular one.
[self assertNoThrow:function() {
await [self assertNoThrow: async function() {
preprocessed = ObjectiveJ.ObjJCompiler.compileToExecutable(unpreprocessed, nil, {includeMethodFunctionNames: true, includeMethodArgumentTypeSignatures: true, includeIvarTypeSignatures: true, inlineMsgSendFunctions: false, transformNamedFunctionDeclarationToAssignment: true}).code();
preprocessed = compressor.compress(preprocessed, { charset : "UTF-8", useServer : true });
correct = compressor.compress(correct, { charset : "UTF-8", useServer : true });
preprocessed = await compressor(preprocessed);
correct = await compressor(correct);
// Get an Inlined version
preprocessedInlined = ObjectiveJ.ObjJCompiler.compileToExecutable(unpreprocessed, nil, {includeMethodFunctionNames: true, includeMethodArgumentTypeSignatures: true, includeIvarTypeSignatures: true, inlineMsgSendFunctions: true, transformNamedFunctionDeclarationToAssignment:true}).code();
preprocessedInlined = compressor.compress(preprocessedInlined, { charset : "UTF-8", useServer : true });
correctInlined = compressor.compress(correctInlined, { charset : "UTF-8", useServer : true });
preprocessedInlined = await compressor(preprocessedInlined);
correctInlined = await compressor(correctInlined);
}];
[self assert:correct equals:preprocessed];