[ESM] Convert *most* of test
-folder to use standard modules
This commit is contained in:
parent
5696c3aa3a
commit
a209ce811d
@ -634,7 +634,7 @@ function createTestSource(testsName, { bot = false, xfaOnly = false } = {}) {
|
|||||||
|
|
||||||
const PDF_TEST = process.env.PDF_TEST || "test_manifest.json";
|
const PDF_TEST = process.env.PDF_TEST || "test_manifest.json";
|
||||||
let forceNoChrome = false;
|
let forceNoChrome = false;
|
||||||
const args = ["test.js"];
|
const args = ["test.mjs"];
|
||||||
switch (testsName) {
|
switch (testsName) {
|
||||||
case "browser":
|
case "browser":
|
||||||
if (!bot) {
|
if (!bot) {
|
||||||
@ -686,7 +686,7 @@ function makeRef(done, bot) {
|
|||||||
console.log("### Creating reference images");
|
console.log("### Creating reference images");
|
||||||
|
|
||||||
let forceNoChrome = false;
|
let forceNoChrome = false;
|
||||||
const args = ["test.js", "--masterMode"];
|
const args = ["test.mjs", "--masterMode"];
|
||||||
if (bot) {
|
if (bot) {
|
||||||
const os = process.env.OS;
|
const os = process.env.OS;
|
||||||
if (/windows/i.test(os)) {
|
if (/windows/i.test(os)) {
|
||||||
@ -1985,11 +1985,11 @@ gulp.task(
|
|||||||
gulp.series("dev-sandbox")
|
gulp.series("dev-sandbox")
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
function createServer() {
|
async function createServer() {
|
||||||
console.log();
|
console.log();
|
||||||
console.log("### Starting local server");
|
console.log("### Starting local server");
|
||||||
|
|
||||||
const WebServer = require("./test/webserver.js").WebServer;
|
const { WebServer } = await import("./test/webserver.mjs");
|
||||||
const server = new WebServer();
|
const server = new WebServer();
|
||||||
server.port = 8888;
|
server.port = 8888;
|
||||||
server.start();
|
server.start();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const fs = require("fs");
|
import crypto from "crypto";
|
||||||
const crypto = require("crypto");
|
import { execSync } from "child_process";
|
||||||
const execSync = require("child_process").execSync;
|
import fs from "fs";
|
||||||
|
|
||||||
const testManifest = "test/test_manifest.json";
|
const testManifest = "test/test_manifest.json";
|
||||||
const pdfFolder = "test/pdfs/";
|
const pdfFolder = "test/pdfs/";
|
@ -15,12 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint-disable no-var */
|
/* eslint-disable no-var */
|
||||||
|
|
||||||
"use strict";
|
import crypto from "crypto";
|
||||||
|
import fs from "fs";
|
||||||
var fs = require("fs");
|
import http from "http";
|
||||||
var crypto = require("crypto");
|
import https from "https";
|
||||||
var http = require("http");
|
import { resolve as urlResolve } from "url";
|
||||||
var https = require("https");
|
|
||||||
|
|
||||||
function rewriteWebArchiveUrl(url) {
|
function rewriteWebArchiveUrl(url) {
|
||||||
// Web Archive URLs need to be transformed to add `if_` after the ID.
|
// Web Archive URLs need to be transformed to add `if_` after the ID.
|
||||||
@ -51,7 +50,7 @@ function downloadFile(file, url, callback, redirects) {
|
|||||||
callback("Too many redirects");
|
callback("Too many redirects");
|
||||||
}
|
}
|
||||||
var redirectTo = response.headers.location;
|
var redirectTo = response.headers.location;
|
||||||
redirectTo = require("url").resolve(url, redirectTo);
|
redirectTo = urlResolve(url, redirectTo);
|
||||||
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -186,5 +185,4 @@ function verifyManifestFiles(manifest, callback) {
|
|||||||
verifyNext();
|
verifyNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.downloadManifestFiles = downloadManifestFiles;
|
export { downloadManifestFiles, verifyManifestFiles };
|
||||||
exports.verifyManifestFiles = verifyManifestFiles;
|
|
@ -14,11 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
import { fileURLToPath } from "url";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import { spawn } from "child_process";
|
||||||
|
|
||||||
const fs = require("fs");
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const path = require("path");
|
|
||||||
const spawn = require("child_process").spawn;
|
|
||||||
|
|
||||||
const ttxResourcesHome = path.join(__dirname, "..", "ttx");
|
const ttxResourcesHome = path.join(__dirname, "..", "ttx");
|
||||||
|
|
||||||
@ -64,11 +65,7 @@ function runTtx(ttxResourcesHomePath, fontPath, registerOnCancel, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.translateFont = function translateFont(
|
function translateFont(content, registerOnCancel, callback) {
|
||||||
content,
|
|
||||||
registerOnCancel,
|
|
||||||
callback
|
|
||||||
) {
|
|
||||||
const buffer = Buffer.from(content, "base64");
|
const buffer = Buffer.from(content, "base64");
|
||||||
const taskId = (nextTTXTaskId++).toString();
|
const taskId = (nextTTXTaskId++).toString();
|
||||||
const fontPath = path.join(ttxResourcesHome, taskId + ".otf");
|
const fontPath = path.join(ttxResourcesHome, taskId + ".otf");
|
||||||
@ -87,4 +84,6 @@ exports.translateFont = function translateFont(
|
|||||||
fs.unlinkSync(resultPath);
|
fs.unlinkSync(resultPath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export { translateFont };
|
@ -13,9 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
import Jasmine from "jasmine";
|
||||||
|
|
||||||
const Jasmine = require("jasmine");
|
|
||||||
|
|
||||||
async function runTests(results) {
|
async function runTests(results) {
|
||||||
const jasmine = new Jasmine();
|
const jasmine = new Jasmine();
|
||||||
@ -57,4 +55,4 @@ async function runTests(results) {
|
|||||||
return jasmine.execute();
|
return jasmine.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.runTests = runTests;
|
export { runTests };
|
@ -15,18 +15,24 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint-disable no-var */
|
/* eslint-disable no-var */
|
||||||
|
|
||||||
"use strict";
|
import { copySubtreeSync, ensureDirSync, removeDirSync } from "./testutils.mjs";
|
||||||
|
import {
|
||||||
|
downloadManifestFiles,
|
||||||
|
verifyManifestFiles,
|
||||||
|
} from "./downloadutils.mjs";
|
||||||
|
import dns from "dns";
|
||||||
|
import fs from "fs";
|
||||||
|
import os from "os";
|
||||||
|
import path from "path";
|
||||||
|
import puppeteer from "puppeteer";
|
||||||
|
import readline from "readline";
|
||||||
|
import rimraf from "rimraf";
|
||||||
|
import { translateFont } from "./font/ttxdriver.mjs";
|
||||||
|
import url from "url";
|
||||||
|
import { WebServer } from "./webserver.mjs";
|
||||||
|
import yargs from "yargs";
|
||||||
|
|
||||||
var WebServer = require("./webserver.js").WebServer;
|
const rimrafSync = rimraf.sync;
|
||||||
var path = require("path");
|
|
||||||
var fs = require("fs");
|
|
||||||
var os = require("os");
|
|
||||||
var puppeteer = require("puppeteer");
|
|
||||||
var url = require("url");
|
|
||||||
var testUtils = require("./testutils.js");
|
|
||||||
const dns = require("dns");
|
|
||||||
const readline = require("readline");
|
|
||||||
const yargs = require("yargs");
|
|
||||||
|
|
||||||
// Chrome uses host `127.0.0.1` in the browser's websocket endpoint URL while
|
// Chrome uses host `127.0.0.1` in the browser's websocket endpoint URL while
|
||||||
// Firefox uses `localhost`, which before Node.js 17 also resolved to the IPv4
|
// Firefox uses `localhost`, which before Node.js 17 also resolved to the IPv4
|
||||||
@ -44,7 +50,7 @@ if (dns.setDefaultResultOrder !== undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseOptions() {
|
function parseOptions() {
|
||||||
yargs
|
const parsedArgs = yargs(process.argv)
|
||||||
.usage("Usage: $0")
|
.usage("Usage: $0")
|
||||||
.option("downloadOnly", {
|
.option("downloadOnly", {
|
||||||
default: false,
|
default: false,
|
||||||
@ -186,11 +192,7 @@ function parseOptions() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = yargs.argv;
|
const result = parsedArgs.argv;
|
||||||
if (result.help) {
|
|
||||||
yargs.showHelp();
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
result.testfilter = Array.isArray(result.testfilter)
|
result.testfilter = Array.isArray(result.testfilter)
|
||||||
? result.testfilter
|
? result.testfilter
|
||||||
: [result.testfilter];
|
: [result.testfilter];
|
||||||
@ -219,9 +221,9 @@ function monitorBrowserTimeout(session, onTimeout) {
|
|||||||
function updateRefImages() {
|
function updateRefImages() {
|
||||||
function sync(removeTmp) {
|
function sync(removeTmp) {
|
||||||
console.log(" Updating ref/ ... ");
|
console.log(" Updating ref/ ... ");
|
||||||
testUtils.copySubtreeSync(refsTmpDir, refsDir);
|
copySubtreeSync(refsTmpDir, refsDir);
|
||||||
if (removeTmp) {
|
if (removeTmp) {
|
||||||
testUtils.removeDirSync(refsTmpDir);
|
removeDirSync(refsTmpDir);
|
||||||
}
|
}
|
||||||
console.log("done");
|
console.log("done");
|
||||||
}
|
}
|
||||||
@ -325,7 +327,7 @@ function startRefTest(masterMode, showRefImages) {
|
|||||||
fs.unlinkSync(eqLog);
|
fs.unlinkSync(eqLog);
|
||||||
}
|
}
|
||||||
if (fs.existsSync(testResultDir)) {
|
if (fs.existsSync(testResultDir)) {
|
||||||
testUtils.removeDirSync(testResultDir);
|
removeDirSync(testResultDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime = Date.now();
|
startTime = Date.now();
|
||||||
@ -356,7 +358,7 @@ function startRefTest(masterMode, showRefImages) {
|
|||||||
function checkRefsTmp() {
|
function checkRefsTmp() {
|
||||||
if (masterMode && fs.existsSync(refsTmpDir)) {
|
if (masterMode && fs.existsSync(refsTmpDir)) {
|
||||||
if (options.noPrompts) {
|
if (options.noPrompts) {
|
||||||
testUtils.removeDirSync(refsTmpDir);
|
removeDirSync(refsTmpDir);
|
||||||
setup();
|
setup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -368,7 +370,7 @@ function startRefTest(masterMode, showRefImages) {
|
|||||||
"SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY [yn] ",
|
"SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY [yn] ",
|
||||||
function (answer) {
|
function (answer) {
|
||||||
if (answer.toLowerCase() === "y") {
|
if (answer.toLowerCase() === "y") {
|
||||||
testUtils.removeDirSync(refsTmpDir);
|
removeDirSync(refsTmpDir);
|
||||||
}
|
}
|
||||||
setup();
|
setup();
|
||||||
reader.close();
|
reader.close();
|
||||||
@ -483,7 +485,7 @@ function checkEq(task, results, browser, masterMode) {
|
|||||||
" != reference rendering"
|
" != reference rendering"
|
||||||
);
|
);
|
||||||
|
|
||||||
testUtils.ensureDirSync(testSnapshotDir);
|
ensureDirSync(testSnapshotDir);
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(testSnapshotDir, page + 1 + ".png"),
|
path.join(testSnapshotDir, page + 1 + ".png"),
|
||||||
testSnapshot
|
testSnapshot
|
||||||
@ -521,7 +523,7 @@ function checkEq(task, results, browser, masterMode) {
|
|||||||
browser,
|
browser,
|
||||||
taskId
|
taskId
|
||||||
);
|
);
|
||||||
testUtils.ensureDirSync(tmpSnapshotDir);
|
ensureDirSync(tmpSnapshotDir);
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(tmpSnapshotDir, page + 1 + ".png"),
|
path.join(tmpSnapshotDir, page + 1 + ".png"),
|
||||||
testSnapshot
|
testSnapshot
|
||||||
@ -811,7 +813,7 @@ async function startIntegrationTest() {
|
|||||||
onAllSessionsClosed = onAllSessionsClosedAfterTests("integration");
|
onAllSessionsClosed = onAllSessionsClosedAfterTests("integration");
|
||||||
startServer();
|
startServer();
|
||||||
|
|
||||||
const { runTests } = require("./integration-boot.js");
|
const { runTests } = await import("./integration-boot.mjs");
|
||||||
await startBrowsers(function (session) {
|
await startBrowsers(function (session) {
|
||||||
session.numRuns = 0;
|
session.numRuns = 0;
|
||||||
session.numErrors = 0;
|
session.numErrors = 0;
|
||||||
@ -844,7 +846,6 @@ function unitTestPostHandler(req, res) {
|
|||||||
});
|
});
|
||||||
req.on("end", function () {
|
req.on("end", function () {
|
||||||
if (pathname === "/ttx") {
|
if (pathname === "/ttx") {
|
||||||
var translateFont = require("./font/ttxdriver.js").translateFont;
|
|
||||||
var onCancel = null,
|
var onCancel = null,
|
||||||
ttxTimeout = 10000;
|
ttxTimeout = 10000;
|
||||||
var timeoutId = setTimeout(function () {
|
var timeoutId = setTimeout(function () {
|
||||||
@ -1021,8 +1022,7 @@ async function closeSession(browser) {
|
|||||||
});
|
});
|
||||||
if (allClosed) {
|
if (allClosed) {
|
||||||
if (tempDir) {
|
if (tempDir) {
|
||||||
const rimraf = require("rimraf");
|
rimrafSync(tempDir);
|
||||||
rimraf.sync(tempDir);
|
|
||||||
}
|
}
|
||||||
onAllSessionsClosed?.();
|
onAllSessionsClosed?.();
|
||||||
}
|
}
|
||||||
@ -1030,10 +1030,9 @@ async function closeSession(browser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ensurePDFsDownloaded(callback) {
|
function ensurePDFsDownloaded(callback) {
|
||||||
var downloadUtils = require("./downloadutils.js");
|
|
||||||
var manifest = getTestManifest();
|
var manifest = getTestManifest();
|
||||||
downloadUtils.downloadManifestFiles(manifest, function () {
|
downloadManifestFiles(manifest, function () {
|
||||||
downloadUtils.verifyManifestFiles(manifest, function (hasErrors) {
|
verifyManifestFiles(manifest, function (hasErrors) {
|
||||||
if (hasErrors) {
|
if (hasErrors) {
|
||||||
console.log(
|
console.log(
|
||||||
"Unable to verify the checksum for the files that are " +
|
"Unable to verify the checksum for the files that are " +
|
@ -14,20 +14,20 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import rimraf from "rimraf";
|
||||||
|
|
||||||
const fs = require("fs");
|
const rimrafSync = rimraf.sync;
|
||||||
const path = require("path");
|
|
||||||
const rimrafSync = require("rimraf").sync;
|
|
||||||
|
|
||||||
exports.removeDirSync = function removeDirSync(dir) {
|
function removeDirSync(dir) {
|
||||||
fs.readdirSync(dir); // Will throw if dir is not a directory
|
fs.readdirSync(dir); // Will throw if dir is not a directory
|
||||||
rimrafSync(dir, {
|
rimrafSync(dir, {
|
||||||
disableGlob: true,
|
disableGlob: true,
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.copySubtreeSync = function copySubtreeSync(src, dest) {
|
function copySubtreeSync(src, dest) {
|
||||||
const files = fs.readdirSync(src);
|
const files = fs.readdirSync(src);
|
||||||
if (!fs.existsSync(dest)) {
|
if (!fs.existsSync(dest)) {
|
||||||
fs.mkdirSync(dest);
|
fs.mkdirSync(dest);
|
||||||
@ -42,9 +42,9 @@ exports.copySubtreeSync = function copySubtreeSync(src, dest) {
|
|||||||
fs.writeFileSync(file, fs.readFileSync(srcFile));
|
fs.writeFileSync(file, fs.readFileSync(srcFile));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.ensureDirSync = function ensureDirSync(dir) {
|
function ensureDirSync(dir) {
|
||||||
if (fs.existsSync(dir)) {
|
if (fs.existsSync(dir)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -61,4 +61,6 @@ exports.ensureDirSync = function ensureDirSync(dir) {
|
|||||||
fs.mkdirSync(parts.slice(0, i).join(path.sep));
|
fs.mkdirSync(parts.slice(0, i).join(path.sep));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export { copySubtreeSync, ensureDirSync, removeDirSync };
|
@ -15,16 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint-disable no-var */
|
/* eslint-disable no-var */
|
||||||
|
|
||||||
"use strict";
|
import fs from "fs";
|
||||||
|
import http from "http";
|
||||||
var http = require("http");
|
import path from "path";
|
||||||
var path = require("path");
|
|
||||||
var fs = require("fs");
|
|
||||||
|
|
||||||
var mimeTypes = {
|
var mimeTypes = {
|
||||||
".css": "text/css",
|
".css": "text/css",
|
||||||
".html": "text/html",
|
".html": "text/html",
|
||||||
".js": "application/javascript",
|
".js": "application/javascript",
|
||||||
|
".mjs": "application/javascript",
|
||||||
".json": "application/json",
|
".json": "application/json",
|
||||||
".svg": "image/svg+xml",
|
".svg": "image/svg+xml",
|
||||||
".pdf": "application/pdf",
|
".pdf": "application/pdf",
|
||||||
@ -352,4 +351,4 @@ function crossOriginHandler(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.WebServer = WebServer;
|
export { WebServer };
|
Loading…
Reference in New Issue
Block a user