Skip to content

test: e2e environment #323

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
31 changes: 25 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: CI
on: [push, pull_request]

jobs:
test:
unit-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
name: CI - node ${{ matrix.node-version }}
name: Unit Tests
steps:
- uses: actions/checkout@v3
- name: set node.js ${{ matrix.node-version }}
Expand All @@ -19,12 +19,31 @@ jobs:
run: npm ci
- name: Build
run: npm run build
- name: npm run test
run: npm run test:full

- name: Unit tests
run: npm run test:unit
e2e-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
name: E2E Tests
steps:
- uses: actions/checkout@v3
- name: set node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: install deps
run: npm ci
- name: build
run: npm run build
- name: run tests
run: npx jest --testMatch "**/*.e2e.ts" --runInBand
release:
runs-on: ubuntu-latest
needs: test
needs:
- unit-test
- e2e-test
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
},
"scripts": {
"test:unit": "cross-env NODE_ENV=test jest --testMatch \"**/*.test.ts\"",
"test:e2e": "npm run build && cross-env NODE_ENV=test jest --testMatch \"**/*.e2e.ts\" --runInBand",
"test:full": "npm run test:unit && npm run test:e2e",
"clean": "rimraf lib",
"build": "npm run clean && tsc -p tsconfig.build.json",
"build:watch": "tsc -w -p tsconfig.build.json",
Expand Down
28 changes: 12 additions & 16 deletions test/e2e/common.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
import os from "os";
import path from "path";
import childProcess from "child_process";

const testDirBasePath = path.resolve(os.tmpdir(), "openupm-cli");

/**
* Makes a temporary directory path for a test.
* @param testName A short string identifying the test or test-suite.
* @returns The path.
*/
export function makeTestDirPath(testName: string): string {
return path.join(testDirBasePath, testName);
}
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.
* Runs openupm. It assumes that it was previously built to the default location.
* @param args Strings containing commands, arguments and options.
* @returns The runs status-code.
*/
export function runOpenupm(args: string[]): Promise<AppOutput> {
const openupmProcess = childProcess.fork("./lib/index.js", args, {
export async function runOpenupm(args: string[]): Promise<AppOutput> {
await fse.ensureDir(projectDir);

const entryPointPath = path.resolve("./lib/index.js");
const openupmProcess = childProcess.fork(entryPointPath, args, {
stdio: "pipe",
cwd: projectDir,
});

const stdOut = Array.of<string>();
Expand All @@ -35,7 +31,7 @@ export function runOpenupm(args: string[]): Promise<AppOutput> {
openupmProcess.stdout!.on("data", (data) => stdOut.push(data.toString()));
openupmProcess.stderr!.on("data", (data) => stdErr.push(data.toString()));

return new Promise<AppOutput>((resolve) =>
return await new Promise<AppOutput>((resolve) =>
openupmProcess.on("exit", (code) =>
resolve({
stdOut,
Expand Down
Loading