test: noImplicitAny

This commit is contained in:
marocchino 2021-08-14 09:48:10 +09:00
parent 2532386159
commit 1f3d2a6328
No known key found for this signature in database
GPG key ID: AFF521DBDB122570
2 changed files with 39 additions and 59 deletions

View file

@ -1,12 +1,13 @@
import {
findPreviousComment,
createComment,
updateComment,
deleteComment
} from "../src/comment"
import {getOctokit} from "@actions/github"
import * as core from "@actions/core"
import {
createComment,
deleteComment,
findPreviousComment,
updateComment
} from "../src/comment"
jest.mock("@actions/core", () => ({
warning: jest.fn()
}))
@ -48,28 +49,17 @@ it("findPreviousComment", async () => {
body: "previous message\n<!-- Sticky Pull Request CommentTypeB -->"
}
]
const octokit: any = {
graphql: jest.fn(() =>
Promise.resolve({
viewer: authenticatedUser
})
),
rest: {
issues: {
listComments: jest.fn(() =>
Promise.resolve({
data: [
commentWithCustomHeader,
otherUserComment,
comment,
headerFirstComment,
...otherComments
]
})
)
}
}
}
const octokit = getOctokit("github-token")
jest.spyOn(octokit, "graphql").mockResolvedValue({viewer: authenticatedUser})
jest.spyOn(octokit.rest.issues, "listComments").mockResolvedValue({
data: [
commentWithCustomHeader,
otherUserComment,
comment,
headerFirstComment,
...otherComments
]
} as any)
expect(await findPreviousComment(octokit, repo, 123, "")).toBe(comment)
expect(await findPreviousComment(octokit, repo, 123, "TypeA")).toBe(
@ -86,16 +76,12 @@ it("findPreviousComment", async () => {
})
describe("updateComment", () => {
let octokit
const octokit = getOctokit("github-token")
beforeEach(() => {
octokit = {
rest: {
issues: {
updateComment: jest.fn(() => Promise.resolve())
}
}
}
jest
.spyOn<any, string>(octokit.rest.issues, "updateComment")
.mockResolvedValue("")
})
it("with comment body", async () => {
@ -143,16 +129,12 @@ describe("updateComment", () => {
})
describe("createComment", () => {
let octokit
const octokit = getOctokit("github-token")
beforeEach(() => {
octokit = {
rest: {
issues: {
createComment: jest.fn(() => Promise.resolve())
}
}
}
jest
.spyOn<any, string>(octokit.rest.issues, "createComment")
.mockResolvedValue("")
})
it("with comment body or previousBody", async () => {
@ -183,13 +165,11 @@ describe("createComment", () => {
})
it("deleteComment", async () => {
const octokit: any = {
rest: {
issues: {
deleteComment: jest.fn(() => Promise.resolve())
}
}
}
const octokit = getOctokit("github-token")
jest
.spyOn(octokit.rest.issues, "deleteComment")
.mockReturnValue(undefined as any)
expect(await deleteComment(octokit, repo, 456)).toBeUndefined()
expect(octokit.rest.issues.deleteComment).toBeCalledWith({
comment_id: 456,

View file

@ -1,12 +1,12 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"exclude": ["node_modules", "**/*.test.ts"]
}