diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml new file mode 100644 index 0000000..ee9a8c7 --- /dev/null +++ b/.github/workflows/run-tests.yaml @@ -0,0 +1,90 @@ +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 packages from before. + # - run: npm install coveralls@3.1.1 # TODO: can be removed? Not needed with github action? + - run: npm install istanbul@0.4.5 + - run: npm install mocha@6.2.0 + + # 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 }} + + # 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 diff --git a/.gitignore b/.gitignore index 68e7bda..04501bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp coverage/ +lcov.info node_modules/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 64a05f9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: node_js -node_js: - - node - - lts/* -script: - - npm run lint - # test-coverage will also run the tests, but does not print helpful output upon test failure. - # So we also run the tests separately. - - npm run test - - npm run test-coverage && cat coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf coverage diff --git a/README.md b/README.md index e82520c..50a9de3 100644 --- a/README.md +++ b/README.md @@ -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`) diff --git a/package.json b/package.json index be2b845..39d2c67 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/test.js b/test.js index abf6542..1af16e8 100644 --- a/test.js +++ b/test.js @@ -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;