Skip to content
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

[1-min] better package testing #512

Merged
merged 10 commits into from
Oct 25, 2022
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
76 changes: 69 additions & 7 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,95 @@ on:
# Leave out to test branches off of branches
# branches: [ main ]

env:
NODE_VERSION_MAJOR: 16
GITHUB_SHA: ${{ github.event.pull_request.head.sha }}

jobs:

prepare-node:
name: Prepare Node
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ env.NODE_VERSION_MAJOR }}.x
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION_MAJOR }}.x
cache: 'yarn'
- run: yarn install

lint:
name: Lint
runs-on: ubuntu-latest
needs: prepare-node
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
- name: Use Node.js ${{ env.NODE_VERSION_MAJOR }}.x
uses: actions/setup-node@v2
with:
node-version: 16.x
node-version: ${{ env.NODE_VERSION_MAJOR }}.x
cache: 'yarn'
- run: yarn install
- run: yarn lint:quiet

test:
name: Test
unit-test:
name: Unit Test
runs-on: ubuntu-latest
needs: prepare-node
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ env.NODE_VERSION_MAJOR }}.x
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION_MAJOR }}.x
cache: 'yarn'
- run: yarn install
- run: yarn test

build-package:
name: Build Package
runs-on: ubuntu-latest
needs: prepare-node
steps:
- uses: actions/checkout@v2
- name: Cache Package Build
id: cache-package-build
uses: actions/cache@v3
with:
# We'll cache this file
path: test/build/spectaql.tgz
key: ${{ runner.os }}-node-v${{ env.NODE_VERSION_MAJOR }}-${{ env.GITHUB_SHA }}
- name: Use Node.js ${{ env.NODE_VERSION_MAJOR }}.x
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION_MAJOR }}.x
cache: 'yarn'
- run: yarn install
- run: yarn pack --filename test/build/spectaql.tgz

test-package:
name: Test Package
runs-on: ubuntu-latest
needs: build-package
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [12.x, 14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Cache Package Build
id: cache-package-build
uses: actions/cache@v3
with:
# We'll cache this file
path: test/build/spectaql.tgz
#key: ${{ runner.os }}-primes
key: ${{ runner.os }}-node-v${{ env.NODE_VERSION_MAJOR }}-${{ env.GITHUB_SHA }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install
- run: yarn test
- run: yarn --cwd test/build install
- run: yarn --cwd test/build test
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v12
v16
3 changes: 3 additions & 0 deletions test/build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.tgz
node_modules
yarn.lock
3 changes: 3 additions & 0 deletions test/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is just a folder where we'll simulate installing the built package as a dependency and making sure it runs on every Node engine we support.

The `lint-and-test.yml` will package things up and put it here.
11 changes: 11 additions & 0 deletions test/build/alive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { run } = require('spectaql')

console.warn('Trying on Node ' + process.version)

if (typeof run !== 'function') {
console.error("I didn't work.")
process.exit(1)
}

console.log('I worked!')
process.exit()
14 changes: 14 additions & 0 deletions test/build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "build",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "yarn node alive.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"spectaql": "file:spectaql.tgz"
}
}