@applicaster/zapplicaster-cli
Version:
CLI Tool for the zapp app and Quick Brick project
166 lines (138 loc) • 4.67 kB
JavaScript
const {
gatherDependencies,
getPluginDependencies,
getSDKAssets,
} = require("../index");
const camelize = require("camelize");
const fs = require("fs");
const resolvedPath = {
lg_tv: "~/zapp-webos/packages/zapp-react-dom-development-app",
android: "~/zapp-platform-android/quick_brick",
};
const dirs = ["drawable-hdpi", "mipmap-hdpi", "drawable-xxxhdpi"];
const assets = ["image.png", "splashBackground.png", "intro.mp4"];
jest.mock("fs", () => ({
readdirSync: jest.fn(),
statSync: jest.fn(),
}));
const name = "Applicaster";
const identifier = "applicaster";
const dependency_name = "@applicaster/zapp-pipes-provider-applicaster";
const dependency_version = "1.4.2";
const type = "data_source_provider";
const configuration_json = { foo: "bar" };
const applicasterManifest = {
plugin: {
name,
identifier,
dependency_name,
dependency_version,
type,
},
configuration_json,
};
const nonJSPlugin = {
plugin: {
name: "Not a JS Plugin",
identifier: "not-a-JS-plugin",
dependency_name: "some-pod",
dependency_version: "~> 1.x.x",
type: "player",
},
configuration_json: {},
};
const rnPlugin = {
plugin: {
name: "RN Plugin",
identifier: "rn-plugin",
dependency_name: "npm-package",
dependency_version: "1.3.4",
type: "general",
react_native: true,
},
configuration_json: {},
};
const rnPluginWithNoDependencyName = {
plugin: {
...rnPlugin.plugin,
dependency_name: undefined, // eslint-disable-line no-undefined
},
};
const rnPluginWithNoIdentifier = {
plugin: {
...rnPlugin.plugin,
identifier: undefined, // eslint-disable-line no-undefined
},
};
const webpackAssets = {
android: {
image: "./assets/android/drawable-xxxhdpi/image.png",
splashBackground: "./assets/android/drawable-xxxhdpi/splashBackground.png",
intro: "./assets/android/drawable-xxxhdpi/intro.mp4",
},
lg_tv: {
image: "./assets/lg_tv/image.png",
splashBackground: "./assets/lg_tv/splashBackground.png",
intro: "./assets/lg_tv/intro.mp4",
},
};
describe("gatherDependencies", () => {
it("parses plugin configuration correctly", () => {
const result = gatherDependencies([applicasterManifest])[0];
expect(result).toHaveProperty("name", name);
expect(result).toHaveProperty("packageName", dependency_name);
expect(result).toHaveProperty("version", dependency_version);
expect(result).toHaveProperty("moduleName", camelize(identifier));
expect(result).toHaveProperty("type", [type]);
expect(result).toHaveProperty("configuration", configuration_json);
});
it("exclude non JS plugin", () => {
const pluginConfigurations = [applicasterManifest, nonJSPlugin, rnPlugin];
const result = gatherDependencies(pluginConfigurations);
expect(result).toBeArrayOfSize(2);
expect(result[0]).toHaveProperty("name", name);
expect(result[1]).toHaveProperty("name", rnPlugin.plugin.name);
});
it("excludes plugins which don't have dependency_name or identifier", () => {
const pluginConfigurations = [
applicasterManifest,
nonJSPlugin,
rnPluginWithNoDependencyName,
rnPluginWithNoIdentifier,
];
const result = gatherDependencies(pluginConfigurations);
expect(result).toMatchSnapshot();
});
});
describe("getPluginDependencies", () => {
const pluginConfigurations = [applicasterManifest, nonJSPlugin, rnPlugin];
const plugins = gatherDependencies(pluginConfigurations);
it("maps the plugins from plugin configurations", () => {
expect(getPluginDependencies(plugins)).toMatchSnapshot();
});
});
describe("getSDKAssets", () => {
afterEach(() => jest.resetAllMocks());
it("retrieves list of assets for web platform and returns an object of assets", async () => {
const platform = "lg_tv";
const dir = resolvedPath[platform];
fs.statSync.mockReturnValue({ isDirectory: () => false });
fs.readdirSync.mockReturnValue(assets);
const result = await getSDKAssets(platform, dir);
expect(result).toMatchSnapshot();
expect(result).toEqual(webpackAssets[platform]);
});
it("retrieves list of assets for native platform and returns an object of assets", async () => {
const platform = "android";
const dir = resolvedPath[platform];
fs.statSync.mockReturnValue({ isDirectory: () => true });
fs.readdirSync
.mockReturnValueOnce(dirs)
.mockReturnValueOnce(assets)
.mockReturnValueOnce(assets)
.mockReturnValueOnce(assets);
const result = await getSDKAssets(platform, dir);
expect(result).toMatchSnapshot();
expect(result).toEqual(webpackAssets[platform]);
});
});