Skip to content

Commit

Permalink
Merge pull request #1722 from yunnysunny/feature/test-on-low-node
Browse files Browse the repository at this point in the history
Add test for old version Node
  • Loading branch information
titanism authored May 3, 2022
2 parents 0b5bbf2 + 1330634 commit 34c9ff4
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 233 deletions.
25 changes: 21 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
strategy:
matrix:
include:
- node-version: 10.x
test-on-old-node: 1
- node-version: 12.x
# test-on-brower: 1
- node-version: 14.x
Expand All @@ -21,7 +23,7 @@ jobs:
- uses: actions/checkout@v2

- name: Install Node - ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
Expand All @@ -32,14 +34,29 @@ jobs:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies
- name: Install Dependencies On Old Node ${{ matrix.node-version }}
if: ${{ matrix.test-on-old-node == '1' }}
run: yarn install --ignore-optional --ignore-scripts
- name: Install Dependencies On Node ${{ matrix.node-version }}
if: ${{ matrix.test-on-old-node != '1' }}
run: yarn install
- name: Build
run: npm run build
- name: Build On Old Node
if: ${{ matrix.test-on-old-node == '1' }}
run: npm run build:test
- name: Test On Node ${{ matrix.node-version }}
env:
BROWSER: ${{ matrix.test-on-brower }}
HTTP2_TEST: ${{ matrix.test-http2 }}
OLD_NODE_TEST: ${{ matrix.test-on-old-node }}
run: |
npm run test
npm run coverage
if [ "$OLD_NODE_TEST" = "1" ]; then
make test
else
npm run lint
make test
fi
- name: Coverage On Node ${{ matrix.node-version }}
run:
npm run coverage
20 changes: 10 additions & 10 deletions .lib.babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"presets": [
["@babel/env", {
"targets": {
"node": "6.4.0",
"browsers": [ "> 1%", "last 2 versions", "ie 9" ]
}
}]
],
"sourceMaps": "inline"
}
"presets": [
["@babel/env", {
"targets": {
"node": "6.4.0",
"browsers": [ "> 1%", "last 2 versions", "ie 9" ]
}
}]
],
"sourceMaps": "inline"
}
17 changes: 17 additions & 0 deletions .test.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"presets": [
["@babel/env", {
"targets": {
"node": "6.4.0",
"browsers": [ "> 1%", "last 2 versions", "ie 9" ]
}
}]
],
"plugins": [
["@babel/transform-runtime"]
],
"parserOpts": {
"allowReturnOutsideFunction": true
},
"sourceMaps": "inline"
}
42 changes: 26 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@

OLDNODETESTS ?= lib/node/test/*.js lib/node/test/node/*.js
NODETESTS ?= test/*.js test/node/*.js
BROWSERTESTS ?= test/*.js test/client/*.js
REPORTER = spec

test:
@if [ "x$(BROWSER)" = "x" ]; then make test-node; else make test-browser; fi
ifeq ("$(OLD_NODE_TEST)", "1")
NODETESTS := $(OLDNODETESTS)
endif

test-node:
@NODE_ENV=test ./node_modules/.bin/nyc ./node_modules/.bin/mocha \
--require should \
--trace-warnings \
--throw-deprecation \
--reporter $(REPORTER) \
--slow 2000 \
--timeout 5000 \
--exit \
$(NODETESTS)
test:
@if [ "$(BROWSER)" = "1" ]; then \
echo test on browser; \
make test-browser; \
fi

test-node-http2:
@NODE_ENV=test HTTP2_TEST=1 node ./node_modules/.bin/mocha \
@if [ "$(NODE_TEST)" = "1" ] || [ "x$(BROWSER)" = "x" ]; then \
echo test on node; \
make test-node; \
fi

copy:
@if [ "$(OLD_NODE_TEST)" = "1" ]; then \
echo test on old node; \
cp test/node/fixtures lib/node/test/node -rf; \
else \
echo test on plain node; \
fi

test-node:copy
@NODE_ENV=test HTTP2_TEST=$(HTTP2_TEST) ./node_modules/.bin/nyc ./node_modules/.bin/mocha \
--require should \
--trace-warnings \
--throw-deprecation \
--reporter $(REPORTER) \
--slow 2000 \
--timeout 5000 \
--exit \
$(NODETESTS)
Expand Down Expand Up @@ -60,4 +70,4 @@ test-docs: docs/head.html docs/tail.html
clean:
rm -fr components

.PHONY: test-cov test docs test-docs clean test-browser-local
.PHONY: copy test-cov test docs test-docs clean test-browser-local
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"@babel/core": "^7.17.9",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@commitlint/cli": "^16.2.3",
"@commitlint/config-conventional": "^16.2.1",
"@babel/runtime": "^7.17.9",
"Base64": "^1.1.0",
"babelify": "^10.0.0",
"basic-auth-connect": "^1.0.0",
Expand All @@ -51,29 +50,33 @@
"codecov": "^3.8.3",
"cookie-parser": "^1.4.6",
"cross-env": "^7.0.3",
"eslint": "^8.14.0",
"eslint-config-xo-lass": "^1.0.6",
"eslint-plugin-compat": "^4.0.2",
"eslint-plugin-node": "^11.1.0",
"express": "^4.18.0",
"express-session": "^1.17.2",
"fixpack": "^4.0.0",
"get-port": "4.2.0",
"husky": "^7.0.4",
"lint-staged": "^12.4.1",
"marked": "^2.0.0",
"mocha": "6.2.2",
"multer": "^1.4.4",
"nyc": "^15.1.0",
"remark-cli": "^10.0.1",
"remark-preset-github": "^4.0.1",
"rimraf": "^3.0.2",
"should": "^13.2.3",
"should-http": "^0.1.1",
"tinyify": "^3.0.0",
"xo": "^0.48.0",
"zuul": "^3.12.0"
},
"optionalDependencies": {
"@commitlint/cli": "^16.2.3",
"@commitlint/config-conventional": "^16.2.1",
"eslint": "^8.14.0",
"eslint-config-xo-lass": "^1.0.6",
"eslint-plugin-compat": "^4.0.2",
"eslint-plugin-node": "^11.1.0",
"husky": "^7.0.4",
"lint-staged": "^12.4.1",
"remark-cli": "^10.0.1",
"remark-preset-github": "^4.0.1",
"xo": "^0.48.0"
},
"engines": {
"node": ">=6.4.0 <13 || >=14"
},
Expand Down Expand Up @@ -154,6 +157,7 @@
"build:clean": "rimraf lib dist",
"build:dist": "npm run browserify && npm run minify",
"build:lib": "babel --config-file ./.lib.babelrc src --out-dir lib",
"build:test": "babel --config-file ./.test.babelrc test --out-dir lib/node/test",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "eslint -c .eslintrc src test && remark . -qfo && eslint -c .lib.eslintrc lib/**/*.js && eslint -c .dist.eslintrc dist/**/*.js",
"minify": "cross-env NODE_ENV=production browserify src/node/index.js -o dist/superagent.min.js -s superagent -g [ babelify --configFile ./.dist.babelrc ] -p tinyify",
Expand Down
4 changes: 3 additions & 1 deletion test/node/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
const assert = require('assert');
const utils = require('../../lib/utils');
const utils = process.env.OLD_NODE_TEST === '1' ?
// eslint-disable-next-line node/no-missing-require
require('../../../utils') : require('../../lib/utils');

describe('utils.type(str)', () => {
it('should return the mime type', () => {
Expand Down
Loading

0 comments on commit 34c9ff4

Please sign in to comment.