Skip to content

Commit

Permalink
♻️ Run bin for pipeline tests (#34)
Browse files Browse the repository at this point in the history
Installs the packed `css-typed` package from CI Build into a sandbox for
the pipeline tests and switches to using `npx css-typed`. This uses the
actual `bin` entry point instead of emulating it with `node dist/main.js`.

In addition to matching the real world use case better, this ensures that
we do not break the bin configuration again. (It broke in the 0.5.0 release.)
  • Loading branch information
connorjs authored Aug 6, 2024
1 parent c9aa453 commit fd066f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
Publish:
name: Publish
needs:
- CiBuild # For version variable
- CiBuild
- PipelineTests # Requires passing tests

uses: connorjs/github-workflows/.github/workflows/npm-publish~v1.yaml@main
Expand All @@ -30,10 +30,14 @@ jobs:

PipelineTests:
name: Test (${{ matrix.node }} | ${{ matrix.platform.os }})
needs:
- CiBuild

runs-on: ${{ matrix.platform.os }}-latest
defaults:
run:
shell: bash
runs-on: ${{ matrix.platform.os }}-latest

strategy:
matrix:
node:
Expand All @@ -49,17 +53,21 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: ${{ needs.CiBuild.outputs.npmPackFilename }}

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
cache: npm
node-version: ${{ matrix.node }}

- name: Install
run: npm install

- name: Build
run: npm run build
- name: Install css-typed
run: |
mkdir -p sandbox
cd sandbox
npm install ../${{ needs.CiBuild.outputs.npmPackFilename }}
- name: "Test 1: default case"
run: |
Expand All @@ -83,7 +91,7 @@ jobs:
- name: "Test 5: absolute outdir"
if: success() || failure()
run: |
scripts/test.sh foo "" "-o $GITHUB_WORKSPACE/generated *.css" "" "$GITHUB_WORKSPACE"/generated/
scripts/test.sh foo "" "-o $RUNNER_TEMP/generated *.css" "" "$RUNNER_TEMP"/generated/
# Note: This test uses double quotes, which expands differently.

- name: "Test 6: json file config"
Expand Down
27 changes: 16 additions & 11 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@ output=${4:-$1}
# $5 is the path prefix for output. Defaults to "".
prefix=${5:-}

# Run from $RUNNER_TEMP for auto-cleanup.
cp fixtures/${input}.css $RUNNER_TEMP/test.css
cp fixtures/${output}.d.css.ts $RUNNER_TEMP/expected.d.css.ts
# `sandbox` is where we installed css-typed.
# Create fresh tmp directory under it each time (under for npx usage).
TEST_DIR=sandbox/tmp
rm -rf $TEST_DIR
mkdir -p $TEST_DIR

cp fixtures/${input}.css $TEST_DIR/test.css
cp fixtures/${output}.d.css.ts $TEST_DIR/expected.d.css.ts

rm -rf "${RUNNER_TEMP:?}/.config"
if [ -f fixtures/config/${config} ]; then
mkdir -p $RUNNER_TEMP/.config
cp fixtures/config/${config} $RUNNER_TEMP/.config/${config}
mkdir -p $TEST_DIR/.config
cp fixtures/config/${config} $TEST_DIR/.config/${config}
fi

pushd $RUNNER_TEMP > /dev/null || exit
pushd $TEST_DIR > /dev/null || exit

set -x # Print the css-typed command exactly as executed

# `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`).
# But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`.
echo "css-typed " "${options[@]}"
# shellcheck disable=SC2068
$GITHUB_WORKSPACE/dist/main.js ${options[@]}
npx css-typed ${options[@]}

{ set +x; } 2>/dev/null # Turn off command printing, and do not print set +X

# Use `diff` to compare the files.
# Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp.
Expand Down

0 comments on commit fd066f4

Please sign in to comment.