Skip to content

Commit

Permalink
fix: replace myUtil with lintUtil.js,and cleanup xmldom test
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoChiesa committed Nov 2, 2024
1 parent 974da52 commit 8689c7c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/package/plugins/PO038-kvm-mapname.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const xpath = require("xpath"),
util = require("util"),
ruleId = require("../myUtil.js").getRuleId(),
ruleId = require("../lintUtil.js").getRuleId(),
debug = require("debug")("apigeelint:" + ruleId);

const plugin = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/resources/issue481/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 31 additions & 28 deletions test/specs/testXmlNodeLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,29 @@
limitations under the License.
*/

/* global describe, before, it, __dirname */
/* global require, describe, before, after, it, __dirname */

const assert = require("assert"),
Dom = require("@xmldom/xmldom").DOMParser,
lintUtil = require("../../lib/package/lintUtil.js"),
util = require("node:util"),
child_process = require("node:child_process"),
xpath = require("xpath"),
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");
Expand All @@ -38,39 +49,34 @@ describe("xmldom related tests", function () {

it("should find xmldom", function (done) {
this.timeout(22000);
const path = require("node:path"),
fs = require("node:fs");

const proxyDir = path.resolve(
__dirname,
"../fixtures/resources/issue481",
),
packageDir = path.resolve(__dirname, "../../lib/package"),
opts = {
cwd: proxyDir,
encoding: "utf8",
};
const node_modules = path.resolve(proxyDir, "node_modules");
fs.rmSync(node_modules, { force: true, recursive: true });

const results1 = child_process.spawnSync("which", ["node"], opts);
debug(JSON.stringify(results1));
const nodePath = results1.stdout.trim();
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 dest = path.resolve(node_modules, "apigeelint", "lib", "package");
fs.cpSync(packageDir, dest, { recursive: true });
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(
nodePath,
"node",
["./node_modules/apigeelint/cli.js", "-s", "sample/apiproxy"],
{ ...opts, timeout: 20000 },
);
let stdout = [], stderr = [];
let stdout = [],
stderr = [];
proc.stdout.on("data", (data) => {
stdout.push(data);
debug(`stdout: ${data}`);
Expand All @@ -81,14 +87,13 @@ describe("xmldom related tests", function () {
});
proc.on("close", (code) => {
debug(`child process exited with code ${code}`);
if (code != 0){
if (code != 0) {
//console.log(`stdout: ${stdout.join('\n')}`);
console.log(`stderr: ${stderr.join('\n')}`);
console.log(`stderr: ${stderr.join("\n")}`);
}
assert.equal(code, 0);
done();
});

} catch (ex1) {
console.log(ex1.stack);
assert.fail();
Expand Down Expand Up @@ -143,7 +148,5 @@ describe("xmldom related tests", function () {
assert.equal(nodeTypeString, "ATTRIBUTE_NODE");
done();
});


});
});

0 comments on commit 8689c7c

Please sign in to comment.