mirror of https://github.com/actions/toolkit
Start writing tests
parent
8a5343d54a
commit
4c6d88f93a
|
@ -0,0 +1,34 @@
|
|||
import * as config from "../src/internal/shared/config"
|
||||
import { createArtifactTwirpClient } from "../src/internal/shared/artifact-twirp-client"
|
||||
import * as core from "@actions/core"
|
||||
|
||||
jest.mock("@actions/http-client")
|
||||
|
||||
describe("artifact-http-client", () => {
|
||||
beforeAll(() => {
|
||||
// mock all output so that there is less noise when running tests
|
||||
jest.spyOn(console, "log").mockImplementation(() => {})
|
||||
jest.spyOn(core, "debug").mockImplementation(() => {})
|
||||
jest.spyOn(core, "info").mockImplementation(() => {})
|
||||
jest.spyOn(core, "warning").mockImplementation(() => {})
|
||||
})
|
||||
|
||||
it("should successfully create a client", () => {
|
||||
jest.spyOn(config, "getResultsServiceUrl").mockReturnValue("http://localhost:8080")
|
||||
jest.spyOn(config, "getRuntimeToken").mockReturnValue("token")
|
||||
const client = createArtifactTwirpClient("upload")
|
||||
expect(client).toBeDefined()
|
||||
})
|
||||
|
||||
it("should make a request", async () => {
|
||||
const client = createArtifactTwirpClient("upload")
|
||||
const artifact = client.CreateArtifact(
|
||||
{
|
||||
workflowRunBackendId: "1234",
|
||||
workflowJobRunBackendId: "5678",
|
||||
name: "artifact",
|
||||
version: 4}
|
||||
)
|
||||
expect(artifact).toBeDefined()
|
||||
})
|
||||
})
|
|
@ -1,7 +1,7 @@
|
|||
import { HttpClient, HttpClientResponse, HttpCodes } from "@actions/http-client"
|
||||
import { BearerCredentialHandler } from "@actions/http-client/lib/auth"
|
||||
import { info } from "@actions/core"
|
||||
import { ArtifactServiceClientJSON } from "src/generated"
|
||||
import { ArtifactServiceClientJSON } from "../../generated"
|
||||
import { getResultsServiceUrl, getRuntimeToken } from "./config"
|
||||
|
||||
// The twirp http client must implement this interface
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"strict": true,
|
||||
"declaration": true,
|
||||
"target": "es6",
|
||||
"target": "es2020",
|
||||
"sourceMap": true,
|
||||
"noImplicitAny": false,
|
||||
"baseUrl": "./",
|
||||
|
|
Loading…
Reference in New Issue