-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added preliminary internal unit tests
- Loading branch information
1 parent
8e33320
commit 31fc3a3
Showing
13 changed files
with
675 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Format | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/actions/prepare | ||
- run: yarn test |
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,16 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"args": ["run", "${relativeFile}"], | ||
"autoAttachChildProcesses": true, | ||
"console": "integratedTerminal", | ||
"name": "Debug Current Test File", | ||
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs", | ||
"request": "launch", | ||
"skipFiles": ["<node_internals>/**", "**/node_modules/**"], | ||
"smartStep": true, | ||
"type": "node" | ||
} | ||
], | ||
"version": "0.2.0" | ||
} |
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 was deleted.
Oops, something went wrong.
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,24 @@ | ||
import { TestComplaint } from "../environments/testEnvironmentTypes"; | ||
import { SpyCallArgs } from "../spies/spyTypes"; | ||
import { formatMethodComplaint } from "./formatMethodComplaint"; | ||
|
||
export const createComplaint = ( | ||
methodsWithCalls: [keyof Console, SpyCallArgs[]][], | ||
): TestComplaint => { | ||
const methodComplaints = methodsWithCalls.map(formatMethodComplaint).join("\n"); | ||
const s = methodsWithCalls.length === 1 ? "" : "s"; | ||
|
||
// It looks like something wrote to the console during your test! | ||
// Put a breakpoint on this line and check the methodsWithCalls variable to see details. | ||
const error = new Error( | ||
`Oh no! Your test called the following console method${s}:\n${methodComplaints}`, | ||
); | ||
|
||
return { | ||
error, | ||
methodComplaints: methodsWithCalls.map(([methodName, methodCalls]) => ({ | ||
methodCalls, | ||
methodName, | ||
})), | ||
}; | ||
}; |
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,16 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { formatComplaintCall } from "./formatComplaintCall"; | ||
|
||
describe("formatComplaintCall", () => { | ||
it.each([ | ||
[[false], "false"], | ||
[[true], "true"], | ||
[[{}], "{}"], | ||
[[{ inner: {} }], '{"inner":{}}'], | ||
[[1, "two", [3]], '1, "two", [3]'], | ||
])(`formats %p as %p`, (args, expected) => { | ||
const actual = formatComplaintCall(args); | ||
|
||
expect(actual).toBe(expected); | ||
}); | ||
}); |
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,8 @@ | ||
import { SpyCallArgs } from "../spies/spyTypes"; | ||
|
||
const formatComplaintLineArg = (arg: unknown) => { | ||
return JSON.stringify(arg) || JSON.stringify(`${arg}`); | ||
}; | ||
|
||
export const formatComplaintCall = (call: SpyCallArgs) => | ||
call.map(formatComplaintLineArg).join(", "); |
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,21 @@ | ||
import { SpyCallArgs } from "../spies/spyTypes"; | ||
import { formatComplaintCall } from "./formatComplaintCall"; | ||
|
||
const lineThreshold = 3; | ||
|
||
export const formatMethodComplaint = ([methodName, calls]: [keyof Console, SpyCallArgs[]]) => { | ||
const summary = ` * ${methodName} (${calls.length} call${calls.length === 1 ? "" : "s"})`; | ||
|
||
const lines = calls | ||
.slice(0, Math.min(calls.length, lineThreshold)) | ||
.map(formatComplaintLineWithIndex); | ||
|
||
if (calls.length > lineThreshold) { | ||
lines.push(`...${calls.length - lineThreshold} more`); | ||
} | ||
|
||
return `${summary}\n${lines.map((line) => ` > Call ${line}`).join("\n")}`; | ||
}; | ||
|
||
const formatComplaintLineWithIndex = (call: SpyCallArgs, i: number) => | ||
`${i}: ${formatComplaintCall(call)}`; |
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,3 @@ | ||
export { createComplaint } from "./createComplaint"; | ||
export { formatComplaintCall } from "./formatComplaintCall"; | ||
export { formatMethodComplaint } from "./formatMethodComplaint"; |
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,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const config_1 = require("vitest/config"); | ||
exports.default = (0, config_1.defineConfig)({ | ||
test: { | ||
clearMocks: true, | ||
exclude: ["lib", "node_modules", "src/**/*.js", "src/*/*.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
clearMocks: true, | ||
exclude: ["lib", "node_modules", "src/**/*.js", "src/*/*.js"], | ||
}, | ||
}); |
Oops, something went wrong.