Skip to content

Commit

Permalink
Replace Travis CI with Github Actions
Browse files Browse the repository at this point in the history
... and replace mocha+istanbul with built-in "node:test" module and rely
on the --experimental-test-coverage option.

Although not used anywhere, include an example with genhtml (part of
GCC's lcov package) in case someone is interested in locally viewing the
coverage data in HTML format.
  • Loading branch information
Rob--W committed Mar 3, 2024
1 parent 96d01f8 commit ed14c13
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 17 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
on: [ push, pull_request ]

name: Tests

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install # install eslint
- run: npm run lint

test-old-node:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [ 6.4.0 ]
steps:
- uses: actions/checkout@v4

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

# Note: no npm ci / npm install:
# The package has no non-dev dependencies.
# Old Node.js does not have built-in coverage reporting, so we use packages from before.
# - run: npm install [email protected] # TODO: can be removed? Not needed with github action?
- run: npm install [email protected]
- run: npm install [email protected]

# test-coverage will also run the tests, but does not print helpful output upon test failure.
# So we also run the tests separately.
- run: ./node_modules/.bin/mocha ./test.js --reporter spec
# ^ instead of: npm test

- run: ./node_modules/.bin/istanbul cover ./node_modules/.bin/mocha -- --reporter spec # creates coverage/lcov.info
# ^ instead of: npm run test-coverage

- name: Send coverage for Node ${{ matrix.node_version }} to Coveralls
uses: coverallsapp/github-action@v2
with:
parallel: true
file: coverage/lcov.info
flag-name: coverage-node-${{ matrix.node_version }}

test-recent-node:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [ 18, 20 ]
steps:
- uses: actions/checkout@v4

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

# Note: no npm ci / npm install:
# The package has no non-dev dependencies.
# We rely on Node.js's built-in test module and reporter,
# and do not require any dev dependencies either.

# test-coverage will also run the tests, but does not print helpful output upon test failure.
# So we also run the tests separately.
- run: npm test

# note: --experimental-test-coverage requires Node v18.15.0+
- run: npm run test-coverage

- name: Send coverage for Node ${{ matrix.node_version }} to Coveralls
uses: coverallsapp/github-action@v2
with:
parallel: true
file: lcov.info
flag-name: coverage-node-${{ matrix.node_version }}

coveralls:
needs: [ test-old-node, test-recent-node ]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Report to Coveralls
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
coverage/
lcov.info
node_modules/
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# proxy-from-env

[![Build Status](https://travis-ci.org/Rob--W/proxy-from-env.svg?branch=master)](https://travis-ci.org/Rob--W/proxy-from-env)
![Build Status](https://github.com/Rob--W/proxy-from-env/actions/workflows/run-tests.yaml/badge.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/Rob--W/proxy-from-env/badge.svg?branch=master)](https://coveralls.io/github/Rob--W/proxy-from-env?branch=master)

`proxy-from-env` is a Node.js package that exports a function (`getProxyForUrl`)
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"main": "index.js",
"scripts": {
"lint": "eslint *.js",
"test": "mocha ./test.js --reporter spec",
"test-coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter spec"
"test": "node --test ./test.js",
"test-coverage": "node --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info ./test.js",
"test-coverage-as-html": "npm run test-gen-lcov && genhtml lcov.info -o coverage/"
},
"repository": {
"type": "git",
Expand All @@ -26,9 +27,6 @@
},
"homepage": "https://github.com/Rob--W/proxy-from-env#readme",
"devDependencies": {
"coveralls": "^3.0.9",
"eslint": "^6.8.0",
"istanbul": "^0.4.5",
"mocha": "^7.1.0"
"eslint": "^6.8.0"
}
}
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/* eslint max-statements:0 */
'use strict';

// For compatibility with old Node that
// The node:test modules is only supported in Node v16.17.0+.
// To run in earlier versions, run this file through mocha instead,
// e.g. mocha ./test.js --reporter spec
var describe = global.describe || require('node:test').describe;
var it = global.it || require('node:test').it;

var assert = require('assert');
var parseUrl = require('url').parse;

Expand Down

0 comments on commit ed14c13

Please sign in to comment.