UNPKG

@applicaster/zapplicaster-cli

Version:

CLI Tool for the zapp app and Quick Brick project

65 lines (53 loc) 1.76 kB
const { workspaceCreator } = require("../workspaceCreator"); jest.mock("path", () => ({ ...jest.requireActual("path"), resolve: (...args) => args.join("/"), })); jest.mock("fs", () => { /* assuming here that the workspace directory and the config folder exist */ const existingDirectories = ["path/to/workspace", "path/to/workspace/config"]; function existsSync(dir) { return existingDirectories.includes(dir); } return { ...jest.requireActual("fs"), existsSync: jest.fn(existsSync), mkdirSync: jest.fn(), }; }); const { existsSync, mkdirSync } = require("fs"); function clearAllMocks() { existsSync.mockClear(); mkdirSync.mockClear(); } describe("workspaceCreator", () => { const configuration = { destinationPath: "path/to/workspace", platform: "ios", }; afterEach(() => { clearAllMocks(); }); it("creates the directories if they don't exist", () => { workspaceCreator(configuration); /* folders tested for creation : 1 - path/to/workspace (exists) 2 - path/to/workspace/config/ios (doesn't exist, looking up parent) 3 - path/to/workspace/config (exists) 4 - path/to/workspace/fonts/ios (doesn't exist, looking up parent) 5 - path/to/workspace/fonts (doesn't exist, looking up parent) 6 - path/to/workspace (exists) 7 - path/to/workspace/assets/ios (doesn't exist, looking up parent) 8 - path/to/workspace/assets (doesn't exist, looking up parent) 9 - path/to/workspace (exists) // => 5 folders are created */ expect(existsSync).toHaveBeenCalledTimes(9); expect(mkdirSync).toHaveBeenCalledTimes(5); expect(existsSync.mock.calls).toMatchSnapshot(); expect(mkdirSync.mock.calls).toMatchSnapshot(); }); });