2024-01-26 05:03:28 +08:00
|
|
|
import { resolveAppFunction } from "../src/helpers/resolve-app-function.js";
|
|
|
|
import { describe, expect, vi, it } from "vitest";
|
2017-10-14 20:25:02 +08:00
|
|
|
|
2024-01-26 05:03:28 +08:00
|
|
|
const stubAppFnPath = require.resolve("./fixtures/plugin/stub-plugin.ts");
|
2020-12-18 07:03:59 +08:00
|
|
|
const stubTranspiledAppFnPath = require.resolve(
|
2024-01-26 05:03:28 +08:00
|
|
|
"./fixtures/plugin/stub-typescript-transpiled-plugin.ts",
|
2020-12-18 07:03:59 +08:00
|
|
|
);
|
2020-08-18 15:47:53 +08:00
|
|
|
const basedir = process.cwd();
|
2017-10-14 20:25:02 +08:00
|
|
|
|
2020-08-18 15:47:53 +08:00
|
|
|
describe("resolver", () => {
|
2021-01-15 07:38:32 +08:00
|
|
|
it("loads the module at the resolved path", async () => {
|
2024-01-26 05:03:28 +08:00
|
|
|
const stubResolver = vi.fn().mockReturnValue(stubAppFnPath);
|
2021-01-15 07:38:32 +08:00
|
|
|
const module = await resolveAppFunction("foo", { resolver: stubResolver });
|
2024-01-26 05:03:28 +08:00
|
|
|
expect(module).toBeInstanceOf(Function);
|
2020-08-18 15:47:53 +08:00
|
|
|
expect(stubResolver).toHaveBeenCalledWith("foo", { basedir });
|
|
|
|
});
|
2020-12-18 07:03:59 +08:00
|
|
|
|
2021-01-15 07:38:32 +08:00
|
|
|
it("loads module transpiled from TypeScript (https://github.com/probot/probot/issues/1447)", async () => {
|
2024-01-26 05:03:28 +08:00
|
|
|
const stubResolver = vi.fn().mockReturnValue(stubTranspiledAppFnPath);
|
2021-01-15 07:38:32 +08:00
|
|
|
const module = await resolveAppFunction("foo", { resolver: stubResolver });
|
2024-01-26 05:03:28 +08:00
|
|
|
expect(module).toBeInstanceOf(Function);
|
2020-12-18 07:03:59 +08:00
|
|
|
expect(stubResolver).toHaveBeenCalledWith("foo", { basedir });
|
|
|
|
});
|
2020-08-18 15:47:53 +08:00
|
|
|
});
|