pdf.js/external/builder/test-fixtures_esprima.js
Jonas Jenwald 4db7330677 Enable ESLint rules that no longer need to be disabled on a directory/file-basis
Given that browsers/environments without native support for both arrow functions and object shorthand properties are no longer supported in PDF.js, please refer to the compatibility information below, we can now enable a fair number of ESLint rules and also simplify/remove some `.eslintrc` files.

With the exception of the `no-alert` cases, all code changes were made automatically by using `gulp lint --fix`.

 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#browser_compatibility
2021-01-22 17:47:03 +01:00

69 lines
1.6 KiB
JavaScript

"use strict";
var p2 = require("./preprocessor2.js");
var fs = require("fs");
var path = require("path");
var errors = 0;
var baseDir = path.join(__dirname, "fixtures_esprima");
var files = fs
.readdirSync(baseDir)
.filter(function (name) {
return /-expected\./.test(name);
})
.map(function (name) {
return path.join(baseDir, name);
});
files.forEach(function (expectationFilename) {
var inFilename = expectationFilename.replace("-expected", "");
var expectation = fs
.readFileSync(expectationFilename)
.toString()
.trim()
.replace(/__filename/g, fs.realpathSync(inFilename));
var input = fs.readFileSync(inFilename).toString();
var defines = {
TRUE: true,
FALSE: false,
OBJ: { obj: { i: 1 }, j: 2 },
TEXT: "text",
};
var map = {
"import-alias": "import-name",
};
var ctx = {
defines,
map,
rootPath: __dirname + "/../..",
};
var out;
try {
out = p2.preprocessPDFJSCode(ctx, input);
} catch (e) {
out = ("Error: " + e.message).replace(/^/gm, "//");
}
if (out !== expectation) {
errors++;
console.log("Assertion failed for " + inFilename);
console.log("--------------------------------------------------");
console.log("EXPECTED:");
console.log(expectation);
console.log("--------------------------------------------------");
console.log("ACTUAL");
console.log(out);
console.log("--------------------------------------------------");
console.log();
}
});
if (errors) {
console.error("Found " + errors + " expectation failures.");
process.exit(1);
} else {
console.log("All tests completed without errors.");
process.exit(0);
}