Feature/jest2 (#322)
* Adding more tests * adding jest * fixing tests * fixing linting * removing 1 slash less * fixing more tests * fixing last test * more last fixes
This commit is contained in:
@@ -1,45 +1,23 @@
|
||||
import { expect } from "chai";
|
||||
import { Github } from "../github";
|
||||
import { Schema } from "../schema-tester";
|
||||
import { Files } from "../utillity";
|
||||
|
||||
describe("test correct files", function () {
|
||||
const folder = Files.CorrectFilesFolder().replace(/\\/gi, "/");
|
||||
const files = Files.GetFiles(folder);
|
||||
const files = Files.GetFiles(folder).filter((f) => f.endsWith(".json"));
|
||||
const validator = Schema.GetValidator();
|
||||
|
||||
expect(files.length, "No files were returned").to.greaterThan(0);
|
||||
expect(files.length).toBeGreaterThan(0);
|
||||
|
||||
files
|
||||
.filter((f) => f.endsWith(".json"))
|
||||
.forEach((file) => {
|
||||
const testfolder = file.replace(folder + "/", "");
|
||||
test.each(files)("File should have a schema & validate correctly: %s", async (file) => {
|
||||
const result = validator.ValidateFile(file);
|
||||
const schemas = validator.ls.getMatchingSchemas(result.doc, result.jdoc);
|
||||
|
||||
it(`File should have a schema & validate correctly: ${testfolder}`, async function () {
|
||||
const result = validator.ValidateFile(file);
|
||||
const schemas = validator.ls.getMatchingSchemas(result.doc, result.jdoc);
|
||||
const succes = await result.promise;
|
||||
|
||||
result.promise.then(
|
||||
(succes) => {
|
||||
expect(succes.length, "Expected no errors got: " + succes.length).to.equal(0);
|
||||
succes.forEach((item) => console.log(item.message));
|
||||
},
|
||||
(fail) => {
|
||||
Github.createError("Failed on validating", { file: file });
|
||||
expect.fail("Failed to validate");
|
||||
}
|
||||
);
|
||||
schemas.then(
|
||||
(success) => {
|
||||
expect(success.length, "Expected schemas to be returned").to.greaterThan(0);
|
||||
},
|
||||
(fail) => {
|
||||
Github.createError("Failed on retrieving schemas", { file: file });
|
||||
expect.fail("failed on retrieving schemas");
|
||||
}
|
||||
);
|
||||
expect(succes).toHaveLength(0);
|
||||
succes.forEach((item) => console.log(item.message));
|
||||
|
||||
return Promise.all([result.promise, schemas]);
|
||||
});
|
||||
});
|
||||
const s = await schemas;
|
||||
expect(s.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,44 +1,20 @@
|
||||
import { expect } from "chai";
|
||||
import { Github } from "../github";
|
||||
import { Schema } from "../schema-tester";
|
||||
import { Files } from "../utillity";
|
||||
|
||||
describe("test incorrect files", function () {
|
||||
const folder = Files.InCorrectFilesFolder().replace(/\\/gi, "/");
|
||||
const files = Files.GetFiles(folder);
|
||||
const files = Files.GetFiles(folder).filter((f) => f.endsWith(".json"));
|
||||
const validator = Schema.GetValidator();
|
||||
|
||||
expect(files.length, "No files were returned").to.greaterThan(0);
|
||||
expect(files.length).toBeGreaterThan(0);
|
||||
|
||||
files
|
||||
.filter((f) => f.endsWith(".json"))
|
||||
.forEach((file) => {
|
||||
const testfolder = file.replace(folder + "/", "");
|
||||
test.each(files)("File should invalidate & have a schema: %s", async (file) => {
|
||||
const result = validator.ValidateFile(file);
|
||||
const schemas = validator.ls.getMatchingSchemas(result.doc, result.jdoc);
|
||||
|
||||
it(`File should invalidate & have a schema: ${testfolder}`, async function () {
|
||||
const result = validator.ValidateFile(file);
|
||||
const schemas = validator.ls.getMatchingSchemas(result.doc, result.jdoc);
|
||||
|
||||
result.promise.then(
|
||||
(succes) => {
|
||||
expect(succes.length, "Expected errors! but had none").to.greaterThan(0);
|
||||
},
|
||||
() => {
|
||||
Github.createError("No errors where found", { file: file });
|
||||
expect.fail("Failed to validate");
|
||||
}
|
||||
);
|
||||
schemas.then(
|
||||
(success) => {
|
||||
expect(success.length, "Expected schemas to be returned").to.greaterThan(0);
|
||||
},
|
||||
() => {
|
||||
Github.createError("Found no schema", { file: file });
|
||||
expect.fail("failed on retrieving schemas");
|
||||
}
|
||||
);
|
||||
|
||||
return Promise.all([schemas, result]);
|
||||
});
|
||||
});
|
||||
const success = await result.promise;
|
||||
expect(success.length).toBeGreaterThan(0);
|
||||
const s = await schemas;
|
||||
expect(s.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user