-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { vi, describe, beforeEach, test, expect } from "vitest"; | ||
import { vol } from "memfs"; | ||
import fs from "fs/promises"; | ||
import inquirer from "inquirer"; | ||
import { genezioCommand } from "../../../src/commands/superGenezio/superGenezio"; | ||
import { IFs } from "memfs"; | ||
import { deployCommand } from "../../../src/commands/deploy"; | ||
import { startLocalEnvironment } from "../../../src/commands/local"; | ||
import colors from "colors"; | ||
import { loginCommand } from "../../../src/commands/login"; | ||
|
||
vi.mock("fs", async () => { | ||
const memfs = await vi.importActual<{ fs: IFs }>("memfs"); | ||
return { default: memfs.fs }; | ||
}); | ||
vi.mock("fs/promises", async () => { | ||
const memfs = await vi.importActual<{ fs: IFs }>("memfs"); | ||
return { default: memfs.fs.promises }; | ||
}); | ||
vi.mock("../../../src/commands/deploy", async () => { | ||
return { deployCommand: vi.fn(() => Promise.resolve()) }; | ||
}); | ||
vi.mock("../../../src/commands/local", async () => { | ||
return { startLocalEnvironment: vi.fn(() => Promise.resolve()) }; | ||
}); | ||
vi.mock("../../../src/commands/login", async (original) => { | ||
return { loginCommand: vi.fn(() => Promise.resolve()) }; | ||
}); | ||
|
||
describe("superGenezio", () => { | ||
beforeEach(() => { | ||
// Clean up the mocked file system before each test | ||
vol.reset(); | ||
}); | ||
|
||
test("detects genezio.yaml and deploys project", async () => { | ||
// Create environment | ||
await fs.mkdir(process.cwd(), { recursive: true }); | ||
await fs.writeFile("genezio.yaml", "test"); | ||
|
||
const promptSpy = vi.spyOn(inquirer, "prompt"); | ||
|
||
// Mock user selecting Deploy | ||
promptSpy.mockResolvedValueOnce({ command: "deploy" }); | ||
|
||
// Run the super command | ||
await genezioCommand(); | ||
|
||
// Check if inquirer.prompt was called with the correct arguments | ||
expect(promptSpy).toHaveBeenCalledWith([ | ||
{ | ||
type: "list", | ||
name: "command", | ||
message: colors.magenta("Genezio project detected. What would you like to do?"), | ||
choices: [ | ||
{ | ||
name: "Deploy your project (genezio deploy)", | ||
value: "deploy", | ||
}, | ||
{ | ||
name: "Start a Local server (genezio local)", | ||
value: "local", | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
// Login should be called because the memfs doesn't have the auth token stored in .geneziorc | ||
expect(loginCommand).toHaveBeenCalledOnce(); | ||
// Check if the deploy command was called | ||
expect(deployCommand).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
test("detects genezio.yaml and starts local", async () => { | ||
// Create environment | ||
await fs.mkdir(process.cwd(), { recursive: true }); | ||
await fs.writeFile("genezio.yaml", "test"); | ||
|
||
const promptSpy = vi.spyOn(inquirer, "prompt"); | ||
|
||
// Mock user selecting Local | ||
promptSpy.mockResolvedValueOnce({ command: "local" }); | ||
|
||
// Run the super command | ||
await genezioCommand(); | ||
|
||
// Check if inquirer.prompt was called with the correct arguments | ||
expect(promptSpy).toHaveBeenCalledWith([ | ||
{ | ||
type: "list", | ||
name: "command", | ||
message: colors.magenta("Genezio project detected. What would you like to do?"), | ||
choices: [ | ||
{ | ||
name: "Deploy your project (genezio deploy)", | ||
value: "deploy", | ||
}, | ||
{ | ||
name: "Start a Local server (genezio local)", | ||
value: "local", | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
// Check if the local environment was started | ||
expect(startLocalEnvironment).toHaveBeenCalled(); | ||
}); | ||
}); |