@applicaster/zapplicaster-cli
Version:
CLI Tool for the zapp app and Quick Brick project
74 lines (57 loc) • 2.05 kB
JavaScript
const { configurator } = require("../configurator");
jest.mock("fs", () => require("../../../../test_helpers/fsMock"));
const fs = require("fs");
jest.mock("path", () => ({
resolve: (path) => {
if (path.includes("fail")) {
return "./testPackage.json";
}
return "./__tests__/testPackage.json";
},
}));
const actualPath = jest.requireActual("path");
const projectRoot = actualPath.resolve(__dirname, "..");
const options = (cliOptions) => ({ cliOptions });
const zappifests = {
ios: "plugin-manifest.ios.json",
android: "plugin-manifest.android.json",
};
describe("configurator", () => {
beforeAll(() => {
jest.spyOn(console, "warn").mockImplementation(() => ({}));
});
afterAll(() => {
fs.__resetFiles();
console.warn.mockRestore();
});
it("forms a configuration object with the right properties", () => {
const config = configurator(options({ projectRoot }));
expect(config).toHaveProperty("name", "@applicaster/pluginname");
expect(config).toHaveProperty("cwd", projectRoot);
expect(config).toHaveProperty("entryPoint", "./src/App");
expect(config).toHaveProperty("zappifests", zappifests);
});
it("takes the name from options if provided", () => {
const { name } = configurator(
options({ projectName: "override-name", projectRoot })
);
expect(name).toBe("@applicaster/override-name");
});
it("leaves the package name untouched if it's already applicaster scoped", () => {
const { name } = configurator(
options({ projectName: "@applicaster/override-name", projectRoot })
);
expect(name).toBe("@applicaster/override-name");
});
it("takes the entry point from options if provided", () => {
const { entryPoint } = configurator(
options({ entryPoint: "./foo/bar", projectRoot })
);
expect(entryPoint).toBe("./foo/bar");
});
it("throws if package.json doesn't exist", () => {
expect(() =>
configurator(options({ projectRoot: "fail" }))
).toThrowErrorMatchingSnapshot();
});
});