Skip to content

Commit ed14c13

Browse files
committed
Replace Travis CI with Github Actions
... 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.
1 parent 96d01f8 commit ed14c13

File tree

6 files changed

+105
-17
lines changed

6 files changed

+105
-17
lines changed

.github/workflows/run-tests.yaml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
on: [ push, pull_request ]
2+
3+
name: Tests
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-node@v4
11+
- run: npm install # install eslint
12+
- run: npm run lint
13+
14+
test-old-node:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
node_version: [ 6.4.0 ]
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Use Node.js ${{ matrix.node_version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node_version }}
26+
cache: npm
27+
28+
# Note: no npm ci / npm install:
29+
# The package has no non-dev dependencies.
30+
# Old Node.js does not have built-in coverage reporting, so we use packages from before.
31+
# - run: npm install [email protected] # TODO: can be removed? Not needed with github action?
32+
- run: npm install [email protected]
33+
- run: npm install [email protected]
34+
35+
# test-coverage will also run the tests, but does not print helpful output upon test failure.
36+
# So we also run the tests separately.
37+
- run: ./node_modules/.bin/mocha ./test.js --reporter spec
38+
# ^ instead of: npm test
39+
40+
- run: ./node_modules/.bin/istanbul cover ./node_modules/.bin/mocha -- --reporter spec # creates coverage/lcov.info
41+
# ^ instead of: npm run test-coverage
42+
43+
- name: Send coverage for Node ${{ matrix.node_version }} to Coveralls
44+
uses: coverallsapp/github-action@v2
45+
with:
46+
parallel: true
47+
file: coverage/lcov.info
48+
flag-name: coverage-node-${{ matrix.node_version }}
49+
50+
test-recent-node:
51+
name: Build
52+
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
node_version: [ 18, 20 ]
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- name: Use Node.js ${{ matrix.node_version }}
60+
uses: actions/setup-node@v4
61+
with:
62+
node-version: ${{ matrix.node_version }}
63+
cache: npm
64+
65+
# Note: no npm ci / npm install:
66+
# The package has no non-dev dependencies.
67+
# We rely on Node.js's built-in test module and reporter,
68+
# and do not require any dev dependencies either.
69+
70+
# test-coverage will also run the tests, but does not print helpful output upon test failure.
71+
# So we also run the tests separately.
72+
- run: npm test
73+
74+
# note: --experimental-test-coverage requires Node v18.15.0+
75+
- run: npm run test-coverage
76+
77+
- name: Send coverage for Node ${{ matrix.node_version }} to Coveralls
78+
uses: coverallsapp/github-action@v2
79+
with:
80+
parallel: true
81+
file: lcov.info
82+
flag-name: coverage-node-${{ matrix.node_version }}
83+
84+
coveralls:
85+
needs: [ test-old-node, test-recent-node ]
86+
if: ${{ always() }}
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Report to Coveralls
90+
uses: coverallsapp/github-action@v2
91+
with:
92+
parallel-finished: true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.swp
22
coverage/
3+
lcov.info
34
node_modules/

.travis.yml

-10
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# proxy-from-env
22

3-
[![Build Status](https://travis-ci.org/Rob--W/proxy-from-env.svg?branch=master)](https://travis-ci.org/Rob--W/proxy-from-env)
3+
![Build Status](https://github.com/Rob--W/proxy-from-env/actions/workflows/run-tests.yaml/badge.svg?branch=master)
44
[![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)
55

66
`proxy-from-env` is a Node.js package that exports a function (`getProxyForUrl`)

package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"main": "index.js",
66
"scripts": {
77
"lint": "eslint *.js",
8-
"test": "mocha ./test.js --reporter spec",
9-
"test-coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter spec"
8+
"test": "node --test ./test.js",
9+
"test-coverage": "node --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info ./test.js",
10+
"test-coverage-as-html": "npm run test-gen-lcov && genhtml lcov.info -o coverage/"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -26,9 +27,6 @@
2627
},
2728
"homepage": "https://github.com/Rob--W/proxy-from-env#readme",
2829
"devDependencies": {
29-
"coveralls": "^3.0.9",
30-
"eslint": "^6.8.0",
31-
"istanbul": "^0.4.5",
32-
"mocha": "^7.1.0"
30+
"eslint": "^6.8.0"
3331
}
3432
}

test.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/* eslint max-statements:0 */
22
'use strict';
33

4+
// For compatibility with old Node that
5+
// The node:test modules is only supported in Node v16.17.0+.
6+
// To run in earlier versions, run this file through mocha instead,
7+
// e.g. mocha ./test.js --reporter spec
8+
var describe = global.describe || require('node:test').describe;
9+
var it = global.it || require('node:test').it;
10+
411
var assert = require('assert');
512
var parseUrl = require('url').parse;
613

0 commit comments

Comments
 (0)