Skip to content

Commit

Permalink
fix mocha/ line errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed May 13, 2024
1 parent e492b73 commit 094d568
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 33 deletions.
1 change: 1 addition & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = [
"prettier/prettier": ["error"],
"mocha/no-skipped-tests": ["error"],
"mocha/no-exclusive-tests": ["error"],
"mocha/max-top-level-suites": ["off"],
},
},
];
16 changes: 13 additions & 3 deletions src/ajv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import { testCacheName, setUp, tearDown } from "./test-helpers.js";

describe("_ajvFactory", function () {
describe("schema drafts compatibility", function () {
const testCache = new Cache(flatCache.load(testCacheName), 3000);
beforeEach(() => setUp());
afterEach(() => tearDown());
let testCache;

before(function () {
testCache = new Cache(flatCache.load(testCacheName), 3000);
});

beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

it("should support draft-04", function () {
const ajv = _ajvFactory(
Expand Down
48 changes: 39 additions & 9 deletions src/cache.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import { testCacheName, setUp, tearDown } from "./test-helpers.js";

describe("Cache", function () {
describe("fetch function", function () {
const testCache = new Cache(flatCache.load(testCacheName), 3000);
beforeEach(() => setUp());
afterEach(() => tearDown());
let testCache;

before(function () {
testCache = new Cache(flatCache.load(testCacheName), 3000);
});

beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

it("should use cached response if valid", async function () {
nock("https://www.foobar.com").get("/baz").reply(200, { cached: false });
Expand Down Expand Up @@ -38,9 +48,19 @@ describe("Cache", function () {
});

describe("cyclic detection", function () {
const testCache = new Cache(flatCache.load(testCacheName), 3000);
beforeEach(() => setUp());
afterEach(() => tearDown());
let testCache;

before(function () {
testCache = new Cache(flatCache.load(testCacheName), 3000);
});

beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

it("throws if callLimit is exceeded", async function () {
const mock = nock("https://www.foobar.com")
Expand All @@ -63,9 +83,19 @@ describe("Cache", function () {
});

describe("expire function", function () {
const testCache = new Cache(flatCache.load(testCacheName), 3000);
beforeEach(() => setUp());
afterEach(() => tearDown());
let testCache;

before(function () {
testCache = new Cache(flatCache.load(testCacheName), 3000);
});

beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

it("should delete expired and malformed cache objects", async function () {
const now = Date.now();
Expand Down
17 changes: 14 additions & 3 deletions src/catalogs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,20 @@ describe("getMatchForFilename", function () {
},
},
];
const testCache = new Cache(flatCache.load(testCacheName), 3000);
beforeEach(() => setUp());
afterEach(() => tearDown());

let testCache;

before(function () {
testCache = new Cache(flatCache.load(testCacheName), 3000);
});

beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

it("returns a schema when one match found", async function () {
assert.deepStrictEqual(
Expand Down
57 changes: 43 additions & 14 deletions src/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { dump as dumpToYaml } from "js-yaml";

describe("CLI", function () {
// Mock the catalog validation schema
beforeEach(() => {
beforeEach(function () {
nock.disableNetConnect();
nock("https://json.schemastore.org")
.persist()
Expand Down Expand Up @@ -52,8 +52,11 @@ describe("CLI", function () {
properties: { num: { type: "number" } },
};

beforeEach(() => setUp());
afterEach(() => {
beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
nock.cleanAll();
});
Expand Down Expand Up @@ -460,10 +463,18 @@ describe("CLI", function () {
type: "object",
properties: { num: { type: "number" } },
};
const yamlSchema = dumpToYaml(schema);

beforeEach(() => setUp());
afterEach(() => {
let yamlSchema;

before(function () {
yamlSchema = dumpToYaml(schema);
});

beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
nock.cleanAll();
});
Expand Down Expand Up @@ -570,8 +581,13 @@ describe("CLI", function () {
});

describe("error handling, single file", function () {
beforeEach(() => setUp());
afterEach(() => tearDown());
beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

it("should return 1 if invalid response from schemastore", async function () {
const mock = nock("https://www.schemastore.org")
Expand Down Expand Up @@ -880,8 +896,13 @@ describe("CLI", function () {
});

describe("multiple file processing", function () {
beforeEach(() => setUp());
afterEach(() => tearDown());
beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

it("should return 0 if all files are valid", async function () {
return cli({
Expand Down Expand Up @@ -951,8 +972,13 @@ describe("CLI", function () {
});

describe("output formats", function () {
beforeEach(() => setUp());
afterEach(() => tearDown());
beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

it("should log errors in text format when format is text", async function () {
return cli({
Expand Down Expand Up @@ -1019,8 +1045,11 @@ describe("CLI", function () {
});

describe("external reference resolver", function () {
beforeEach(() => setUp());
afterEach(() => {
beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
nock.cleanAll();
});
Expand Down
14 changes: 10 additions & 4 deletions src/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ describe("preProcessConfig", function () {
});

describe("getConfig", function () {
beforeEach(() => setUp());
afterEach(() => {
beforeEach(function () {
setUp();
});

afterEach(function () {
tearDown();
});

Expand Down Expand Up @@ -273,8 +276,11 @@ describe("getConfig", function () {
describe("validateConfig", function () {
const messages = {};

beforeEach(() => setUp(messages));
afterEach(() => {
beforeEach(function () {
setUp(messages);
});

afterEach(function () {
tearDown();
});

Expand Down

0 comments on commit 094d568

Please sign in to comment.