Updated tests

This commit is contained in:
DaanV2
2022-07-13 21:15:38 +02:00
parent 7bfbc61eb7
commit ced5441358
4 changed files with 21 additions and 19 deletions

View File

@@ -2,8 +2,8 @@ import { expect } from "chai";
import { DummyFiles } from "../../src/main"; import { DummyFiles } from "../../src/main";
import { Files } from "./Utillity"; import { Files } from "./Utillity";
describe("Files", () => { describe("Files", function () {
it("Root", () => { it("Root", function () {
const temp = Files.RootFolder(); const temp = Files.RootFolder();
expect(temp.endsWith("lib"), "ended with lib").to.be.false; expect(temp.endsWith("lib"), "ended with lib").to.be.false;
@@ -11,13 +11,13 @@ describe("Files", () => {
expect(temp.endsWith("lib/test"), "ended with lib/test").to.be.false; expect(temp.endsWith("lib/test"), "ended with lib/test").to.be.false;
}); });
it("Test", () => { it("Test", function () {
const temp = Files.TestFolder(); const temp = Files.TestFolder();
expect(temp.endsWith("lib"), "ended with lib").to.be.false; expect(temp.endsWith("lib"), "ended with lib").to.be.false;
}); });
it("Random", () => { it("Random", function () {
expect(Files.TestFolder()).to.equal(DummyFiles.TestFolder()); expect(Files.TestFolder()).to.equal(DummyFiles.TestFolder());
}); });
}); });

View File

@@ -4,7 +4,7 @@ import * as fs from "fs";
import * as JSONC from "comment-json"; import * as JSONC from "comment-json";
import { expect } from "chai"; import { expect } from "chai";
describe.only("Validate", () => { describe.only("Validate", function () {
const folder = path.join(Files.TestFolder(), "..", "source"); const folder = path.join(Files.TestFolder(), "..", "source");
console.log(folder); console.log(folder);
const files = Files.GetFiles(folder); const files = Files.GetFiles(folder);
@@ -12,24 +12,24 @@ describe.only("Validate", () => {
files.forEach((filepath) => { files.forEach((filepath) => {
const filename = filepath.slice(folder.length); const filename = filepath.slice(folder.length);
describe(filename, () => { describe(filename, function () {
let object: JsonSchema | undefined = undefined; let object: JsonSchema | undefined = undefined;
let data: string; let data: string;
it("Can read file", () => { it("Can read file", function () {
data = fs.readFileSync(filepath, "utf8"); data = fs.readFileSync(filepath, "utf8");
}); });
it("Can parse to json", () => { it("Can parse to json", function () {
object = <JsonSchema>JSONC.parse(data); object = <JsonSchema>JSONC.parse(data);
}); });
it("Not Undefined or null", () => { it("Not Undefined or null", function () {
expect(object).to.not.be.undefined; expect(object).to.not.be.undefined;
expect(object).to.not.be.null; expect(object).to.not.be.null;
}); });
it("Checking refs", () => { describe("Checking refs", function () {
if (!object) { if (!object) {
expect.fail(); expect.fail();
return; return;
@@ -53,7 +53,9 @@ function explore_refs(data: JsonSchema, folder: string): void {
if (!ref.startsWith("#")) { if (!ref.startsWith("#")) {
const filepath = path.isAbsolute(ref) ? ref : path.join(folder, ref); const filepath = path.isAbsolute(ref) ? ref : path.join(folder, ref);
expect(fs.existsSync(filepath), `ref ${ref} exists`).to.be.true; it(`expecting ${ref} to exist from ${folder}`, function () {
expect(fs.existsSync(filepath), `ref ${ref} exists`).to.be.true;
});
} }
} }

View File

@@ -2,7 +2,7 @@ import { expect } from "chai";
import { Schema } from "../SchemaTester"; import { Schema } from "../SchemaTester";
import { Files } from "../Utillity"; import { Files } from "../Utillity";
describe("test correct files", () => { describe("test correct files", function () {
const folder = Files.CorrectFilesFolder().replace(/\\/gi, "/"); const folder = Files.CorrectFilesFolder().replace(/\\/gi, "/");
const files = Files.GetFiles(folder); const files = Files.GetFiles(folder);
const validator = Schema.GetValidator(); const validator = Schema.GetValidator();
@@ -14,11 +14,11 @@ describe("test correct files", () => {
.forEach((file) => { .forEach((file) => {
const testfolder = file.replace(folder + "/", ""); const testfolder = file.replace(folder + "/", "");
describe(testfolder, () => { describe(testfolder, function () {
const result = validator.ValidateFile(file); const result = validator.ValidateFile(file);
const schemas = validator.ls.getMatchingSchemas(result.doc, result.jdoc); const schemas = validator.ls.getMatchingSchemas(result.doc, result.jdoc);
it("validation", () => { it("validation", function () {
result.promise.then( result.promise.then(
(succes) => { (succes) => {
expect(succes.length, "Expected no errors got: " + succes.length).to.equal(0); expect(succes.length, "Expected no errors got: " + succes.length).to.equal(0);
@@ -32,7 +32,7 @@ describe("test correct files", () => {
return result.promise; return result.promise;
}); });
it("schemas", () => { it("schemas", function () {
return schemas.then( return schemas.then(
(success) => { (success) => {
expect(success.length, "Expected schemas to be returned").to.greaterThan(0); expect(success.length, "Expected schemas to be returned").to.greaterThan(0);

View File

@@ -2,7 +2,7 @@ import { expect } from "chai";
import { Schema } from "../SchemaTester"; import { Schema } from "../SchemaTester";
import { Files } from "../Utillity"; import { Files } from "../Utillity";
describe("test incorrect files", () => { describe("test incorrect files", function () {
const folder = Files.InCorrectFilesFolder().replace(/\\/gi, "/"); const folder = Files.InCorrectFilesFolder().replace(/\\/gi, "/");
const files = Files.GetFiles(folder); const files = Files.GetFiles(folder);
const validator = Schema.GetValidator(); const validator = Schema.GetValidator();
@@ -14,11 +14,11 @@ describe("test incorrect files", () => {
.forEach((file) => { .forEach((file) => {
const testfolder = file.replace(folder + "/", ""); const testfolder = file.replace(folder + "/", "");
describe(testfolder, () => { describe(testfolder, function () {
const result = validator.ValidateFile(file); const result = validator.ValidateFile(file);
const schemas = validator.ls.getMatchingSchemas(result.doc, result.jdoc); const schemas = validator.ls.getMatchingSchemas(result.doc, result.jdoc);
it("schemas", () => { it("schemas", function () {
return schemas.then( return schemas.then(
(success) => { (success) => {
expect(success.length, "Expected schemas to be returned").to.greaterThan(0); expect(success.length, "Expected schemas to be returned").to.greaterThan(0);
@@ -29,7 +29,7 @@ describe("test incorrect files", () => {
); );
}); });
it("validation", () => { it("validation", function () {
result.promise.then( result.promise.then(
(succes) => { (succes) => {
expect(succes.length, "Expected errors! but had none").to.greaterThan(0); expect(succes.length, "Expected errors! but had none").to.greaterThan(0);