Skip to content

Commit

Permalink
Include JS tests in csdl-xml in npm test (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfhandl authored Aug 15, 2022
1 parent bbecc7f commit 5e19499
Showing 6 changed files with 27 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -29,3 +29,4 @@ obj/
Thumbs.db
UserInterfaceState.xcuserstate
*.bak
tools/csdl-xml/test/resources/*.csdl.xml
14 changes: 7 additions & 7 deletions tools/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"mochaExplorer.files": "*/test/**/*.ts",
"mochaExplorer.require": "ts-node/register",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"mochaExplorer.files": "*/test/**/*.[jt]s",
"mochaExplorer.require": "ts-node/register",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
}
30 changes: 16 additions & 14 deletions tools/csdl-xml/test/cli.test.js
Original file line number Diff line number Diff line change
@@ -3,34 +3,36 @@ const exec = require("child_process").exec;
const fs = require("fs");
const path = require("path");

describe("CLI", () => {
describe("csdl-xml CLI", () => {
it("Help", async () => {
const result = await cmd(["-h"]);
expect(result.code).to.equal(0);
expect(result.stdout).to.contain("Usage: csdl2xml");
});

it("Translate one file", async () => {
const outfile = "test/resources/jetsons-enhanced.csdl.xml";
const basefile = "test/resources/jetsons-enhanced.csdl.base.xml";
it("Translate one file specified with full path", async () => {
const outfile = `${__dirname}/resources/jetsons-enhanced.csdl.xml`;
const basefile = `${__dirname}/resources/jetsons-enhanced.csdl.base.xml`;
if (fs.existsSync(outfile)) fs.unlinkSync(outfile);
const result = await cmd(
["-p", "resources/jetsons-enhanced.csdl.json"],
"test"
["-p", `${__dirname}/resources/jetsons-enhanced.csdl.json`],
`${__dirname}/..`
);
expect(result.code).to.equal(0);
expect(result.stdout).to.equal("resources/jetsons-enhanced.csdl.xml\n");
expect(result.stdout).to.equal(
`${__dirname}/resources/jetsons-enhanced.csdl.xml\n`
);
expect(fs.existsSync(outfile)).to.equal(true);
const basexml = fs.readFileSync(basefile, "utf-8");
const xml = fs.readFileSync(outfile, "utf-8");
expect(xml).to.equal(basexml);
});

it("Translate file with includes", async () => {
const outfile = "test/resources/main.csdl.xml";
const basefile = "test/resources/main.csdl.base.xml";
it("Translate file (specified with relative path) with includes", async () => {
const outfile = `${__dirname}/resources/main.csdl.xml`;
const basefile = `${__dirname}/resources/main.csdl.base.xml`;
if (fs.existsSync(outfile)) fs.unlinkSync(outfile);
const result = await cmd(["-p", "resources/main.csdl.json"], "test");
const result = await cmd(["-p", "resources/main.csdl.json"], __dirname);
expect(result.code).to.equal(0);
expect(result.stdout).to.equal("resources/main.csdl.xml\n");
expect(fs.existsSync(outfile)).to.equal(true);
@@ -40,7 +42,7 @@ describe("CLI", () => {
});
});

describe("CLI - error cases", () => {
describe("csdl-xml CLI - error cases", () => {
it("Invalid option", async () => {
const result = await cmd(["-x"]);
expect(result.code).to.equal(0);
@@ -56,7 +58,7 @@ describe("CLI - error cases", () => {
});

it("File with syntax errors", async () => {
const result = await cmd(["-p", "resources/kaputt.csdl.json"], "test");
const result = await cmd(["-p", "resources/kaputt.csdl.json"], __dirname);
expect(result.code).to.equal(0);
expect(result.stdout).to.contain("Unexpected Schema Element");
});
@@ -65,7 +67,7 @@ describe("CLI - error cases", () => {
function cmd(args, cwd) {
return new Promise((resolve) => {
exec(
`node ${path.resolve("./lib/cli")} ${args.join(" ")}`,
`node ${path.resolve(`${__dirname}/../lib/cli`)} ${args.join(" ")}`,
{ cwd },
(error, stdout, stderr) => {
resolve({
2 changes: 1 addition & 1 deletion tools/csdl-xml/test/xmlSerializer.test.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ function stripWhitespace(inputString) {
return inputString.replace(/\s/g, "");
}

describe("Parse correct JSON CSDL", () => {
describe("csdl-xml Parse correct JSON CSDL", () => {
it("Empty Object", () => {
const xml = serializeToXml({});
assert.equal(
2 changes: 1 addition & 1 deletion tools/odataUri/src/semantic-model.ts
Original file line number Diff line number Diff line change
@@ -641,7 +641,7 @@ export class QueryOptionsVisitor
this.typeStack.push(itemType);

const orderSpec = ctx.tryGetRuleContext(0, OrderSpecContext);
console.log("order spec", orderSpec);
// console.log("order spec", orderSpec);
if (orderSpec) {
const field = orderSpec.tryGetRuleContext(0, OrderFieldContext);
const fieldNode = field && this.visitOrderField(field);
2 changes: 1 addition & 1 deletion tools/package.json
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
"postinstall": "patch-package",
"api-designer": "cd api-designer && npm start",
"api-explorer": "cd api-explorer && npm start",
"test": "c8 mocha -r ts-node/register */test/**/*.test.ts"
"test": "c8 mocha -r ts-node/register */test/**/*.test.[jt]s"
},
"devDependencies": {
"patch-package": "^6.4.7",

0 comments on commit 5e19499

Please sign in to comment.