-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jake Lauer
authored and
Jake Lauer
committed
Jul 21, 2024
1 parent
760714b
commit dedf27b
Showing
20 changed files
with
620 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Ignore issues with self-signed certs | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
|
||
module.exports = { | ||
// Search the whole tree | ||
recursive: true, | ||
// Match the following extensions | ||
extension: ["js"], | ||
// Skip over shit | ||
ignore: ["**/node_modules/**/*", "**/dist/**/*"], | ||
// TBH I don't know why this is required, but removing it breaks things and it's not in the docs for Mocha. | ||
// Seems as though this determines the search pattern, but then why do I also have to specify extensions? | ||
spec: ["**/*.test.js"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
declare module 'quibble' { | ||
export type QuibbleConfig = { | ||
defaultFakeCreator: (request: string) => any; | ||
}; | ||
|
||
type Quibble = { | ||
<T = any>(request: string, stub?: any): T; | ||
config(userConfig: Partial<QuibbleConfig>): QuibbleConfig; | ||
ignoreCallsFromThisFile(file?: string): void; | ||
reset(hard?: boolean): void; | ||
absolutify(relativePath: string, parentFileName?: string): string; | ||
esm<TMockedType extends Record<string, any> = Record<string, any>>( | ||
specifier: string, | ||
namedExportStubs?:Partial<TMockedType>, | ||
defaultExportStub?: any | ||
): Promise<void>; | ||
listMockedModules(): string[]; | ||
isLoaderLoaded(): boolean; | ||
esmImportWithPath(specifier: string): Promise<{ | ||
modulePath: string; | ||
moduleUrl: string; | ||
module: any; | ||
}>; | ||
}; | ||
|
||
const quibble: Quibble; | ||
const _default: Quibble; | ||
export { quibble, _default as default }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,70 @@ | ||
import { expect } from "chai"; | ||
import { | ||
beforeEach, describe, it, | ||
describe, it, afterEach, | ||
} from "mocha"; | ||
import sinon from "sinon"; | ||
import * as loggerModule from "theseus-logger"; | ||
import proxyquire from "proxyquire"; | ||
import type * as StrictnessType from "../strictness.js"; | ||
import quibble from "quibble"; | ||
|
||
const strictness = proxyquire<typeof StrictnessType>("../strictness", { | ||
"theseus-logger": { | ||
getTheseusLogger: () => {}, | ||
}, | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports | ||
type LoggerMock = typeof import("theseus-logger"); | ||
|
||
describe("fail function", () => | ||
{ | ||
let logSpy: { warn: sinon.SinonSpy; error: sinon.SinonSpy; debug: sinon.SinonSpy }; | ||
let fail: any; | ||
const logSpy = { | ||
warn: sinon.spy(), | ||
error: sinon.spy(), | ||
debug: sinon.spy(), | ||
}; | ||
|
||
beforeEach(() => | ||
await quibble.esm<LoggerMock>("theseus-logger", { | ||
getTheseusLogger: (name: string) => | ||
{ | ||
logSpy = { | ||
warn: sinon.spy(), | ||
error: sinon.spy(), | ||
debug: sinon.spy(), | ||
}; | ||
|
||
// Use proxyquire to mock 'theseus-logger' module | ||
fail = strictness.fail; | ||
console.log("Mock getTheseusLogger called with name:", name); | ||
return logSpy as any; | ||
}, | ||
}); | ||
|
||
sinon.stub(loggerModule, "getTheseusLogger").returns(logSpy as any); | ||
}); | ||
const { fail } = await import("../strictness.js"); | ||
|
||
afterEach(function () | ||
describe("fail function", () => | ||
{ | ||
afterEach(() => | ||
{ | ||
sinon.restore(); | ||
logSpy.warn.resetHistory(); | ||
logSpy.error.resetHistory(); | ||
logSpy.debug.resetHistory(); | ||
}); | ||
|
||
it("calls log.debug when strict is undefined or false", () => | ||
{ | ||
fail(undefined, "Test message"); | ||
expect(logSpy.debug.calledOnceWith("Test message")).to.be.true; | ||
|
||
fail( | ||
{ | ||
strict: false, | ||
}, | ||
"Test message", | ||
); | ||
expect(logSpy.debug.calledTwice).to.be.true; | ||
fail({ | ||
strict: false, | ||
}, "Test message"); | ||
expect(logSpy.debug).to.be.calledTwice; | ||
}); | ||
|
||
it("calls log.warn when strict is 'warn'", () => | ||
{ | ||
fail( | ||
{ | ||
strict: "warn", | ||
}, | ||
"Warning message", | ||
); | ||
fail({ | ||
strict: "warn", | ||
}, "Warning message"); | ||
expect(logSpy.warn.calledOnceWith("Warning message")).to.be.true; | ||
}); | ||
|
||
it("throws an error and calls log.error when strict is true and multiple parameters are provided", () => | ||
{ | ||
expect(() => | ||
fail( | ||
{ | ||
strict: true, | ||
}, | ||
"Error message", | ||
"Extra info", | ||
), | ||
).to.throw("Extra info"); | ||
expect(() => fail({ | ||
strict: true, | ||
}, "Error message", "Extra info")).to.throw("Error message"); | ||
expect(logSpy.error.calledOnceWith("Error message", "Extra info")).to.be.true; | ||
}); | ||
|
||
it("throws an error with the correct message when strict is true and only one parameter is provided", () => | ||
{ | ||
expect(() => | ||
fail( | ||
{ | ||
strict: true, | ||
}, | ||
"Error message", | ||
), | ||
).to.throw("Error message"); | ||
expect(() => fail({ | ||
strict: true, | ||
}, "Error message")).to.throw("Error message"); | ||
}); | ||
}); |
Oops, something went wrong.