From ec2e46e04d9306dd5c99ac1b75c38baa2895282d Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sat, 15 Apr 2023 01:28:59 -0400 Subject: [PATCH] build: run tests using actual build (#23) * build: run tests using actual build * build: build script that includes hashbang prepending * ci: missing /bin/zsh --- .github/workflows/nodejs.yml | 8 +++++++- package.json | 7 ++++--- script/build | 18 ++++++++++++++++++ script/test-suite | 23 +++++++++++++++++++++++ src/cli.ts | 2 -- src/collector.ts | 2 -- src/worker.ts | 2 -- tests/expect.test.ts | 2 +- tests/it.test.ts | 2 +- 9 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 script/build create mode 100644 script/test-suite diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index dcec5dd..24519ea 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -44,11 +44,13 @@ jobs: key: ${{ runner.os }}-build-${{env.cache-name}}-${{ hashFiles('**/yarn.lock') }}-node-${{ matrix.node-version }} - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} run: corepack enable && yarn + integration: runs-on: ubuntu-latest needs: dependencies name: Integration tests - + env: + SHELL: /usr/bin/bash strategy: matrix: node-version: [16, 18] @@ -95,6 +97,8 @@ jobs: matrix: node-version: [16, 18] + env: + SHELL: /usr/bin/bash steps: - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} @@ -115,6 +119,8 @@ jobs: build: runs-on: ubuntu-latest needs: dependencies + env: + SHELL: /usr/bin/bash strategy: matrix: node-version: [16, 18] diff --git a/package.json b/package.json index 6b11794..44a33b2 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,10 @@ "prebuild": "rm -rf dist", "lint": "rome format src tests && rome check src tests", "lint:fix": "rome format src tests --write && rome check src tests --apply", - "test": "ts-node ./src/cli.ts ./tests", - "test:integration": "/usr/bin/bash ./script/integration-tests", - "build": "tsc --project ." + "test": "$SHELL ./script/test-suite", + "test:integration": "$SHELL ./script/integration-tests", + "build:ts": "tsc --project .", + "build": "$SHELL ./script/build" }, "devDependencies": { "@types/node": "^18.15.10", diff --git a/script/build b/script/build new file mode 100644 index 0000000..d63de8e --- /dev/null +++ b/script/build @@ -0,0 +1,18 @@ +#!/usr/bin/bash + +yarn build:ts + +# Certain files need hashbangs as they are executables. + +NODE_HASHBANG="#!/usr/bin/env node" + +addHashbang() { + echo $1 + echo $NODE_HASHBANG > $1_prefixed + cat $1 >> $1_prefixed + mv $1_prefixed $1 +} + +addHashbang dist/cli.js +addHashbang dist/collector.js +addHashbang dist/worker.js diff --git a/script/test-suite b/script/test-suite new file mode 100644 index 0000000..c583fe2 --- /dev/null +++ b/script/test-suite @@ -0,0 +1,23 @@ +#!/usr/bin/bash + +# +# Tests are executed using a built version of the runner. +# +# This will first build the package, install it in a temporary +# environment and run the test suite with it. +# + +yarn pack --out integration-build.tgz + +mkdir .tests + +echo "{}" > .tests/package.json +touch .tests/yarn.lock + +( + cd .tests + yarn add ../integration-build.tgz ts-node + yarn womm ../tests --ts --workers=2 +) + +rm -rf .tests diff --git a/src/cli.ts b/src/cli.ts index 8357a3e..b83f373 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,5 +1,3 @@ -#!/usr/bin/env node - import helpText from './help' import parseArgs from './argumentParser' import { getContext, redText, assertTsNodeInstall } from './utils' diff --git a/src/collector.ts b/src/collector.ts index 23471c7..97f1e6b 100644 --- a/src/collector.ts +++ b/src/collector.ts @@ -1,5 +1,3 @@ -#!/usr/bin/env ts-node - import { type Context } from './types' import { getContext, spawnProcess } from './utils' diff --git a/src/worker.ts b/src/worker.ts index bfab3ef..900f520 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,5 +1,3 @@ -#!/usr/bin/env ts-node - import path from 'path' import { getContext, spawnProcess } from './utils' diff --git a/tests/expect.test.ts b/tests/expect.test.ts index b5f8650..7e0f11b 100644 --- a/tests/expect.test.ts +++ b/tests/expect.test.ts @@ -1,5 +1,5 @@ import assert from 'assert' -import { describe, test, expect } from '../src' +import { describe, test, expect } from 'works-on-my-machine' describe('Equality', () => { test.each([1, 'expectations', true])('Equality (value=%s)', (value: unknown) => { diff --git a/tests/it.test.ts b/tests/it.test.ts index a304da4..bf8a3a7 100644 --- a/tests/it.test.ts +++ b/tests/it.test.ts @@ -1,6 +1,6 @@ import assert from 'assert' -import { it, test, expect, describe } from '../src' +import { it, test, expect, describe } from 'works-on-my-machine' describe.each([it, test])('Runs tests', (fn: unknown) => { const testFn = fn as typeof test