karte-expo-plugin
Version:
Config plugin for karte-react-native package
84 lines (83 loc) • 2.73 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_plugins_1 = require("@expo/config-plugins");
const fs_1 = __importDefault(require("fs"));
const withKarteiOS_1 = require("../withKarteiOS");
jest.mock("fs", () => {
return {
existsSync: jest.fn(),
copyFileSync: jest.fn(),
readdirSync: jest.fn(),
promises: {
readFile: jest.fn(),
},
};
});
jest.mock("@expo/config-plugins", () => {
return {
...jest.requireActual("@expo/config-plugins"),
withXcodeProject: jest.fn(),
IOSConfig: {
Paths: {
getSourceRoot: () => "",
},
XcodeUtils: {
getProjectName: () => "",
addResourceFileToGroup: () => "",
},
},
};
});
const mockXcodeProject = (mock) => {
const xcodeProject = { ...mock };
// @ts-ignore
config_plugins_1.withXcodeProject.mockImplementation((config, callback) => {
// @ts-ignore
return callback({
...config,
modRequest: {
projectRoot: "projectRoot",
},
modResults: {
hasFile: () => false,
},
xcodeProject,
});
});
};
const exp = { name: "foo", slug: "bar" };
describe(withKarteiOS_1.withKarteiOS, () => {
beforeEach(() => {
config_plugins_1.withXcodeProject.mockClear();
});
it("should not throw if plist path is set", () => {
mockXcodeProject({});
jest.spyOn(fs_1.default, "existsSync").mockImplementation((_) => {
return true;
});
expect(() => (0, withKarteiOS_1.withKarteiOS)(exp, {
karteInfoPlist: "karte.plist",
karteXml: "",
})).not.toThrow();
});
it("should throw if plist path is not set", () => {
mockXcodeProject({});
jest.spyOn(fs_1.default, "existsSync").mockImplementation((_) => {
return true;
});
expect(() => (0, withKarteiOS_1.withKarteiOS)(exp, {})).toThrow(/^Path to Karte-Info.plist is not defined. Please specify the path in app.json.$/);
});
it("should throw if plist file is not exists", () => {
mockXcodeProject({});
jest.spyOn(fs_1.default, "existsSync").mockImplementation((_) => {
return false;
});
expect(() => (0, withKarteiOS_1.withKarteiOS)(exp, {
karteInfoPlist: "karte.plist",
karteXml: "",
})).toThrow(/Karte-Info.plist doesn't exist/);
});
});