From 094d56861e9d158f5c0182a40b52e27db1783b13 Mon Sep 17 00:00:00 2001 From: chris48s Date: Mon, 13 May 2024 11:10:30 +0100 Subject: [PATCH] fix mocha/ line errors --- eslint.config.cjs | 1 + src/ajv.spec.js | 16 ++++++++++--- src/cache.spec.js | 48 ++++++++++++++++++++++++++++++------- src/catalogs.spec.js | 17 ++++++++++--- src/cli.spec.js | 57 +++++++++++++++++++++++++++++++++----------- src/config.spec.js | 14 +++++++---- 6 files changed, 120 insertions(+), 33 deletions(-) diff --git a/eslint.config.cjs b/eslint.config.cjs index 830a6832..7ce4ef19 100644 --- a/eslint.config.cjs +++ b/eslint.config.cjs @@ -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"], }, }, ]; diff --git a/src/ajv.spec.js b/src/ajv.spec.js index 171d5b5f..f23bd2ed 100644 --- a/src/ajv.spec.js +++ b/src/ajv.spec.js @@ -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( diff --git a/src/cache.spec.js b/src/cache.spec.js index f60b122e..68c833f9 100644 --- a/src/cache.spec.js +++ b/src/cache.spec.js @@ -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 }); @@ -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") @@ -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(); diff --git a/src/catalogs.spec.js b/src/catalogs.spec.js index 238ce825..d0860869 100644 --- a/src/catalogs.spec.js +++ b/src/catalogs.spec.js @@ -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( diff --git a/src/cli.spec.js b/src/cli.spec.js index 87c917c0..afb7616c 100644 --- a/src/cli.spec.js +++ b/src/cli.spec.js @@ -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() @@ -52,8 +52,11 @@ describe("CLI", function () { properties: { num: { type: "number" } }, }; - beforeEach(() => setUp()); - afterEach(() => { + beforeEach(function () { + setUp(); + }); + + afterEach(function () { tearDown(); nock.cleanAll(); }); @@ -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(); }); @@ -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") @@ -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({ @@ -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({ @@ -1019,8 +1045,11 @@ describe("CLI", function () { }); describe("external reference resolver", function () { - beforeEach(() => setUp()); - afterEach(() => { + beforeEach(function () { + setUp(); + }); + + afterEach(function () { tearDown(); nock.cleanAll(); }); diff --git a/src/config.spec.js b/src/config.spec.js index 0c7f3767..ea4adbd6 100644 --- a/src/config.spec.js +++ b/src/config.spec.js @@ -175,8 +175,11 @@ describe("preProcessConfig", function () { }); describe("getConfig", function () { - beforeEach(() => setUp()); - afterEach(() => { + beforeEach(function () { + setUp(); + }); + + afterEach(function () { tearDown(); }); @@ -273,8 +276,11 @@ describe("getConfig", function () { describe("validateConfig", function () { const messages = {}; - beforeEach(() => setUp(messages)); - afterEach(() => { + beforeEach(function () { + setUp(messages); + }); + + afterEach(function () { tearDown(); });