Skip to content

Commit

Permalink
feat: replace placeholder content with plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Nov 17, 2023
1 parent 930a64b commit 7f6c932
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
21 changes: 10 additions & 11 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/**
* Sums up two numbers.
*
* @param {number} a The first number to add.
* @param {number} b The second number to add.
* @returns {number} The resulting sum of the two numbers.
* Called by semantic-release during the verification step
*
* @param {*} pluginConfig The semantic-release plugin config
* @param {*} context The context provided by semantic-release
*/
export declare function add(a: number, b: number): number
export declare function verifyConditions(pluginConfig: any, context: any): void

/**
* Sums up a list of numbers.
*
* @param {number[]} numbers An array of numbers to add.
* @returns {number} The resulting sum of all the numbers.
* Called by semantic-release during the prepare step
*
* @param {*} pluginConfig The semantic-release plugin config
* @param {*} context The context provided by semantic-release
*/
export declare function add(numbers: number[]): number
export declare function prepare(pluginConfig: any, context: any): void
21 changes: 10 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
export function add(a, b) {
if (Array.isArray(a)) {
return a.reduce((sum, val) => sum + val, 0);
} else if (
arguments.length === 2 &&
typeof a === "number" &&
typeof b === "number"
) {
return a + b;
}
/* eslint-disable no-unused-vars */

throw new Error("Invalid input");
let verified;
let prepared;

export async function verifyConditions(pluginConfig, context) {
verified = true;
}

export async function prepare(pluginConfig, context) {
prepared = true;
}
21 changes: 7 additions & 14 deletions tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { add } from "../lib/index";
import { prepare, verifyConditions } from "../lib/index";

describe("add", () => {
describe("verifyConditions", () => {
it("should be defined", () => {
expect(add).toBeDefined();
});

it("should sum up two numbers", () => {
expect(add(42, 42)).toBe(84);
});

it("should sum up a list of numbers", () => {
expect(add([42, 42])).toBe(84);
expect(verifyConditions).toBeDefined();
});
});

it("should throw for invalid inputs", () => {
expect(() => add()).toThrow("Invalid input");
expect(() => add(42)).toThrow("Invalid input");
describe("prepare", () => {
it("should be defined", () => {
expect(prepare).toBeDefined();
});
});

0 comments on commit 7f6c932

Please sign in to comment.