Skip to content

test: specify e2e run location #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions test/e2e/help.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { runOpenupm } from "./common";
import { runOpenupm } from "./run";
import { prepareHomeDirectory } from "./setup/directories";

describe("help", () => {
it("should show help when running with no commands", async () => {
const output = await runOpenupm([]);
const homeDir = await prepareHomeDirectory();
const output = await runOpenupm(homeDir, []);

expect(output.stdErr).toEqual(
expect.arrayContaining([expect.stringContaining("Usage")])
);
});

it("should exit with 0", async () => {
const output = await runOpenupm([]);
const homeDir = await prepareHomeDirectory();
const output = await runOpenupm(homeDir, []);

expect(output.code).toEqual(1);
});
Expand Down
14 changes: 6 additions & 8 deletions test/e2e/common.ts → test/e2e/run.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import path from "path";
import childProcess from "child_process";
import fse from "fs-extra";
import os from "os";

export type AppOutput = {
stdOut: string[];
stdErr: string[];
code: number;
};

const projectDir = path.join(os.homedir(), "projects/MyUnityProject");

/**
* Runs openupm. It assumes that it was previously built to the default location.
* @param cwd The directory in which to run openupm.
* @param args Strings containing commands, arguments and options.
* @returns The runs status-code.
*/
export async function runOpenupm(args: string[]): Promise<AppOutput> {
await fse.ensureDir(projectDir);

export async function runOpenupm(
cwd: string,
args: string[]
): Promise<AppOutput> {
const entryPointPath = path.resolve("./lib/index.js");
const openupmProcess = childProcess.fork(entryPointPath, args, {
stdio: "pipe",
cwd: projectDir,
cwd,
});

const stdOut = Array.of<string>();
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/setup/directories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os from "os";
import fse from "fs-extra";

const homePath = os.homedir();

/**
* Gets the path to the users home-directory and makes sure it exists.
*/
export async function prepareHomeDirectory(): Promise<string> {
await fse.ensureDir(homePath);
return homePath;
}
12 changes: 8 additions & 4 deletions test/e2e/unknown.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { runOpenupm } from "./common";
import { runOpenupm } from "./run";
import { prepareHomeDirectory } from "./setup/directories";

describe("unknown command", () => {
it("should warn of unknown command", async () => {
const output = await runOpenupm(["unknown-command"]);
const homeDir = await prepareHomeDirectory();
const output = await runOpenupm(homeDir, ["unknown-command"]);

expect(output.stdErr).toEqual(
expect.arrayContaining([expect.stringContaining("unknown command")])
);
});

it("should suggest to run with help", async () => {
const output = await runOpenupm(["unknown-command"]);
const homeDir = await prepareHomeDirectory();
const output = await runOpenupm(homeDir, ["unknown-command"]);

expect(output.stdErr).toEqual(
expect.arrayContaining([expect.stringContaining("see --help")])
);
});

it("should exit with 1", async () => {
const output = await runOpenupm(["unknown-command"]);
const homeDir = await prepareHomeDirectory();
const output = await runOpenupm(homeDir, ["unknown-command"]);

expect(output.code).toEqual(1);
});
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/version.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { runOpenupm } from "./common";
import { runOpenupm } from "./run";
import pkgJson from "../../package.json";
import { prepareHomeDirectory } from "./setup/directories";

describe("version", () => {
it("should print current version", async () => {
const output = await runOpenupm(["--version"]);
const homeDir = await prepareHomeDirectory();
const output = await runOpenupm(homeDir, ["--version"]);

expect(output.stdOut).toEqual(
expect.arrayContaining([expect.stringContaining(pkgJson.version)])
);
});

it("should exit with 0", async () => {
const output = await runOpenupm(["--version"]);
const homeDir = await prepareHomeDirectory();
const output = await runOpenupm(homeDir, ["--version"]);

expect(output.code).toEqual(0);
});
Expand Down
Loading