diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 5ca2748..7e5e22e 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -11,15 +11,11 @@ concurrency: cancel-in-progress: true jobs: - e2e: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest] - runs-on: ${{ matrix.os }} + get-node-version: + runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get Node Version id: get-node-version @@ -28,33 +24,29 @@ jobs: # breaks the github action that consumes this data run: echo node-version=$(cat package.json | jq ".engines.node" | sed 's/^"\(.*\)"$/\1/') >> $GITHUB_OUTPUT - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: ${{ steps.get-node-version.outputs.node-version }} + outputs: + node-version: ${{ steps.get-node-version.outputs.node-version }} - - name: Get Node Modules Cache Key - id: get-node-modules-cache-key - run: echo cache-key=${{ matrix.os }}-${{ hashFiles('package-lock.json') }} >> $GITHUB_OUTPUT + e2e: + needs: + - get-node-version + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 - - name: Cache Node Modules - id: cache-node-modules - uses: actions/cache@v3 + - name: Setup Node + uses: actions/setup-node@v4 with: - key: ${{ steps.get-node-modules-cache-key.outputs.cache-key }} - path: node_modules - lookup-only: true + node-version: ${{ needs.get-node-version.outputs.node-version }} + cache: "npm" - name: Install Dependencies - if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }} - run: npm install - - - name: Restore Node Modules - uses: actions/cache/restore@v3 - with: - key: ${{ steps.get-node-modules-cache-key.outputs.cache-key }} - path: node_modules - fail-on-cache-miss: true + run: npm ci - name: Run E2E Tests run: npm run e2e diff --git a/scripts/e2eTest.ts b/scripts/e2eTest.ts index 5387a42..8ef7a2d 100644 --- a/scripts/e2eTest.ts +++ b/scripts/e2eTest.ts @@ -1,4 +1,4 @@ -import { execSync } from "node:child_process"; +import { execSync, spawn } from "node:child_process"; import tar from "tar"; import { mkdir, readFile, readdir, copyFile, rm } from "fs/promises"; @@ -10,11 +10,15 @@ const run = (...args: Parameters) => { const main = async () => { run("npm run prepublishOnly"); + // Simulates publishing to npm // and includes only the files that would be published run("npm pack"); + await mkdir("e2e"); + await extractPackage(); + if (process.env.CI === "true") { run(`git config --global user.email "you@example.com"`, { cwd: "e2e", @@ -23,16 +27,19 @@ const main = async () => { cwd: "e2e", }); } - run("echo ./installation | ./package/bin.js", { - cwd: "e2e", - }); + + await install(); + run("npm run postpublish"); + await Promise.all( ["graph", "concrete", "foundation"].map(copyExerciseAnswers) ); + run("npm run check -- --run", { cwd: "e2e/installation", }); + rm("e2e", { recursive: true, force: true }); }; @@ -50,6 +57,27 @@ const extractPackage = async () => { }); }; +const install = async () => { + // For some reason piping stuff with echo + // doesn't work properly with Windows + + const process = spawn("node ./package/bin.js", { + stdio: ["pipe", "inherit", "inherit"], + cwd: "e2e", + shell: true, + }); + + await new Promise((resolve) => { + process.on("spawn", resolve); + }); + + process.stdin.write("installation\n"); + + await new Promise((resolve) => { + process.on("exit", resolve); + }); +}; + const copyExerciseAnswers = async (category: string) => { const exercises = await readdir(`./src/exercises/${category}`);