diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bd64c1a..02968b42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} @@ -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 diff --git a/package.json b/package.json index 972a9050..7bc62866 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/e2e/common.ts b/test/e2e/common.ts index 63606e77..8b706f76 100644 --- a/test/e2e/common.ts +++ b/test/e2e/common.ts @@ -1,17 +1,7 @@ -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[]; @@ -19,14 +9,20 @@ export type AppOutput = { 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 { - const openupmProcess = childProcess.fork("./lib/index.js", args, { +export async function runOpenupm(args: string[]): Promise { + 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(); @@ -35,7 +31,7 @@ export function runOpenupm(args: string[]): Promise { openupmProcess.stdout!.on("data", (data) => stdOut.push(data.toString())); openupmProcess.stderr!.on("data", (data) => stdErr.push(data.toString())); - return new Promise((resolve) => + return await new Promise((resolve) => openupmProcess.on("exit", (code) => resolve({ stdOut,