Skip to content

Replace Travis CI with Github Actions #24

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

Merged
merged 1 commit into from
Mar 4, 2024
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
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 }}

# 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 external packages.
# - run: npm install [email protected] # TODO: can be removed? Not needed with github action?
- run: npm install [email protected]
# 6.2.0 is supposedly compatible with v6, but fails to install.
# So we use a (working) version referenced by [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:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [ 20 ]
steps:
- uses: actions/checkout@v4

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

# 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+
# note: --test-reporter=lcov requires Node v20.11.0+ (https://github.com/nodejs/node/pull/50018)
- 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:
name: Report to Coveralls
needs: [ test-old-node, test-recent-node ]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- 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