API Reference
stacker/testing
Provides utilities for testing handlers.
test()
Defines a test case.
test(name: string, callback: () => void): void
- name: The name of the test case.
- callback: The callback function containing the test logic.
Examples
import { type GitHubEvent, GitHubReasons } from "stacker/github";
import { test, equal, evalGitHubEvent } from "stacker/testing";
// Base event for tests
const baseEvent: GitHubEvent = {
title: "Issue",
url: "https://github.com/placeholder/placeholder/issues/1",
reason: "",
type: "Issue",
repository: {
fullName: "placeholder/placeholder",
name: "placeholder",
url: "https://github.com/placeholder/placeholder",
private: false,
description: "A placeholder repository",
fork: false,
owner: {
login: "placeholder",
url: "https://github.com/placeholder",
type: "User",
siteAdmin: false
}
}
};
test("Grafana repository with Subscribed reason", () => {
const event: GitHubEvent = {
...baseEvent,
reason: GitHubReasons.Subscribed,
repository: {
...baseEvent.repository,
owner: { ...baseEvent.repository.owner, login: "grafana" },
fullName: "grafana/k6",
name: "k6"
}
};
const { stacks } = evalGitHubEvent(event);
equal(stacks, ["work"]);
});
Functions
evalGitHubEvent()
Will run any event you pass thought your handlers and return the result.
evalGitHubEvent(event: GitHubEvent): GitHubEvalResult
- event: The GitHub event to evaluate.
equal()
Asserts that two values are equal.
equal(a: any, b: any): void
- a: The first value.
- b: The second value.
genGitHubEvent()
Wrapper that can help generate GitHub notifications for testing.
genGitHubEvent(params: { title: string; reason: string; type: string; repository: { name: string; owner: string; isPrivate: boolean; isFork: boolean; } }): GitHubEvent
- params:
- title: The title of the event.
- reason: The reason for the event.
- type: The type of the event.
- repository:
- name: The name of the repository.
- owner: The owner of the repository.
- isPrivate: Whether the repository is private.
- isFork: Whether the repository is a fork.
Wrapper that can help evaluate GitHub notifications for testing
Types
GitHubEvalResult
Represents the result of evaluating a GitHub event.
interface GitHubEvalResult {
stacks: string[];
}