Skip to content

Commit

Permalink
fix: xmldom tests failing due to timeout (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoChiesa authored Nov 4, 2024
1 parent 099d2b5 commit ce945e8
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 137 deletions.
25 changes: 1 addition & 24 deletions test/badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
228 changes: 115 additions & 113 deletions test/specs/testXmlNodeLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,130 +23,132 @@ const assert = require("assert"),
child_process = require("node:child_process"),
debug = require("debug")("apigeelint:xmldom-test");

describe("xmldom related tests", function () {
describe("path resolution verification", function () {
const path = require("node:path"),
fs = require("node:fs"),
proxyDir = path.resolve(__dirname, "../fixtures/resources/issue481"),
node_modules = path.resolve(proxyDir, "node_modules");

before(function () {
fs.rmSync(node_modules, { force: true, recursive: true });
});
after(function () {
fs.rmSync(node_modules, { force: true, recursive: true });
});

it("should resolve to a path", function (done) {
try {
const p = lintUtil.getNodeModulesPathFor("@xmldom/xmldom");
assert.ok(p);
} catch (e) {
assert.fail();
}
done();
});
describe("xmldom path resolution verification", function () {
const path = require("node:path"),
fs = require("node:fs"),
proxyDir = path.resolve(__dirname, "../fixtures/resources/issue481"),
node_modules = path.resolve(proxyDir, "node_modules");

before(function (done) {
// remove node_modules before the test runs. We want a clean install.
fs.rmSync(node_modules, { force: true, recursive: true });
done();
});

it("should find xmldom", function (done) {
this.timeout(22000);
after(function (done) {
// tidy up after the test runs.
this.timeout(8000);
fs.rmSync(node_modules, { force: true, recursive: true });
done();
});

const opts = {
cwd: proxyDir,
encoding: "utf8",
};
it("should resolve to a path", function (done) {
try {
const p = lintUtil.getNodeModulesPathFor("@xmldom/xmldom");
assert.ok(p);
} catch (e) {
assert.fail();
}
done();
});

if (debug.enabled) {
const r = child_process.spawnSync("which", ["node"], opts);
debug(`node: ` + JSON.stringify(r));
}
it("should find xmldom", function (done) {
this.timeout(22000);
const opts = {
cwd: proxyDir,
encoding: "utf8",
};

if (debug.enabled) {
const r = child_process.spawnSync("which", ["node"], opts);
debug(`node: ` + JSON.stringify(r));
}

child_process.exec("npm install", opts, (e, stdout, stderr) => {
assert.equal(e, null);
debug(stdout);
// copy current implementation over, to allow testing of it.
const srcPackageDir = path.resolve(__dirname, "../../lib/package"),
destPackageDir = path.resolve(node_modules, "apigeelint/lib/package");
// overwrite the installed apigeelint with the current (working) version
fs.cpSync(srcPackageDir, destPackageDir, { recursive: true });

child_process.exec("npm install", opts, (e, stdout, stderr) => {
assert.equal(e, null);
debug(stdout);
// copy current implementation over, to allow testing of it.
const srcPackageDir = path.resolve(__dirname, "../../lib/package"),
destPackageDir = path.resolve(node_modules, "apigeelint/lib/package");
fs.cpSync(srcPackageDir, destPackageDir, { recursive: true });

try {
// run apigeelint after npm install
const proc = child_process.spawn(
"node",
["./node_modules/apigeelint/cli.js", "-s", "sample/apiproxy"],
{ ...opts, timeout: 20000 },
);
let stdout = [],
stderr = [];
proc.stdout.on("data", (data) => {
stdout.push(data);
debug(`stdout: ${data}`);
});
proc.stderr.on("data", (data) => {
stderr.push(data);
debug(`stderr: ${data}`);
});
proc.on("close", (code) => {
debug(`child process exited with code ${code}`);
if (code != 0) {
//console.log(`stdout: ${stdout.join('\n')}`);
console.log(`stderr: ${stderr.join("\n")}`);
}
assert.equal(code, 0);
done();
});
} catch (ex1) {
console.log(ex1.stack);
assert.fail();
try {
// run apigeelint after npm install
const proc = child_process.spawn(
"node",
["./node_modules/apigeelint/cli.js", "-s", "sample/apiproxy"],
{ ...opts, timeout: 20000 },
);
let stdout = [],
stderr = [];
proc.stdout.on("data", (data) => {
stdout.push(data);
debug(`stdout: ${data}`);
});
proc.stderr.on("data", (data) => {
stderr.push(data);
debug(`stderr: ${data}`);
});
proc.on("close", (code) => {
debug(`child process exited with code ${code}`);
if (code != 0) {
console.log(`stderr: ${stderr.join("\n")}`);
}
assert.equal(code, 0, "return status code");
done();
}
});
});
} catch (ex1) {
console.log(ex1.stack);
assert.fail();
}
});
});
});

describe("element name tests", function () {
let xml;
const exampleXml = `<root attr1="hello"><!-- comment --><A><B/></A></root>`;
before(function () {
xml = new Dom().parseFromString(exampleXml);
});
describe("xmldom element name tests", function () {
let xml;
const exampleXml = `<root attr1="hello"><!-- comment --><A><B/></A></root>`;
before(function () {
xml = new Dom().parseFromString(exampleXml);
});

it("should properly name the document node", function (done) {
assert.ok(xml);
const nodeTypeString = lintUtil.xmlNodeTypeAsString(xml.nodeType);
assert.ok(nodeTypeString);
assert.equal(nodeTypeString, "DOCUMENT_NODE");
done();
});
it("should properly name the document node", function (done) {
assert.ok(xml);
const nodeTypeString = lintUtil.xmlNodeTypeAsString(xml.nodeType);
assert.ok(nodeTypeString);
assert.equal(nodeTypeString, "DOCUMENT_NODE");
done();
});

it("should properly name the root element node", function (done) {
assert.ok(xml.documentElement.nodeType);
const nodeTypeString = lintUtil.xmlNodeTypeAsString(
xml.documentElement.nodeType,
);
assert.ok(nodeTypeString);
assert.equal(nodeTypeString, "ELEMENT_NODE");
done();
});
it("should properly name the root element node", function (done) {
assert.ok(xml.documentElement.nodeType);
const nodeTypeString = lintUtil.xmlNodeTypeAsString(
xml.documentElement.nodeType,
);
assert.ok(nodeTypeString);
assert.equal(nodeTypeString, "ELEMENT_NODE");
done();
});

it("should properly name the comment node", function (done) {
const fc = xml.documentElement.firstChild;
assert.ok(fc);
const nodeTypeString = lintUtil.xmlNodeTypeAsString(fc.nodeType);
assert.ok(nodeTypeString);
assert.equal(nodeTypeString, "COMMENT_NODE");
done();
});
it("should properly name the comment node", function (done) {
const fc = xml.documentElement.firstChild;
assert.ok(fc);
const nodeTypeString = lintUtil.xmlNodeTypeAsString(fc.nodeType);
assert.ok(nodeTypeString);
assert.equal(nodeTypeString, "COMMENT_NODE");
done();
});

it("should properly name the attribute node", function (done) {
const attr = xml.documentElement.getAttributeNode("attr1");
debug(`attrs(${attr})`);
debug(`attrs(${util.format(attr)})`);
assert.ok(attr);
let nodeTypeString = lintUtil.xmlNodeTypeAsString(attr.nodeType);
debug(`nodeTypeString(${nodeTypeString})`);
assert.ok(nodeTypeString);
assert.equal(nodeTypeString, "ATTRIBUTE_NODE");
done();
});
it("should properly name the attribute node", function (done) {
const attr = xml.documentElement.getAttributeNode("attr1");
debug(`attrs(${attr})`);
debug(`attrs(${util.format(attr)})`);
assert.ok(attr);
let nodeTypeString = lintUtil.xmlNodeTypeAsString(attr.nodeType);
debug(`nodeTypeString(${nodeTypeString})`);
assert.ok(nodeTypeString);
assert.equal(nodeTypeString, "ATTRIBUTE_NODE");
done();
});
});

0 comments on commit ce945e8

Please sign in to comment.