diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..babc172 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,43 @@ +'use strict'; + +module.exports = { + extends: 'airbnb/base', + overrides: [ + { + files: '.eslintrc.js', + parserOptions: { + sourceType: 'script' + }, + // airbnb's config here is too inflexible as it prevents strict mode + // even with scripts, so set to `safe` + // Changed: https://github.com/airbnb/javascript/pull/1962 + rules: { + strict: ['error', 'safe'] + } + }, + { + files: ['examples/**'], + rules: { + 'no-console': 0 + } + }, + { + files: ['test/**'], + env: { + mocha: true + }, + globals: { + expect: true + }, + rules: { + 'no-console': 0, + // Is otherwise reporting in Atom ESLint linter (though not on command line) + 'import/no-extraneous-dependencies': 0 + } + } + ], + rules: { + 'comma-dangle': 0, + 'no-param-reassign': 0 + } +}; diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 0d52ab4..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "extends": "airbnb/base", - "overrides": [ - { - "files": ["examples/**"], - "rules": { - "no-console": 0 - } - }, - { - "files": ["test/**"], - "env": { - "mocha": true - }, - "globals": { - "expect": true - }, - "rules": { - "no-console": 0 - } - } - ], - "rules": { - "comma-dangle": 0, - "no-param-reassign": 0 - } -} diff --git a/.ncurc.js b/.ncurc.js new file mode 100644 index 0000000..9ba4904 --- /dev/null +++ b/.ncurc.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = { + // Whitelist all for checking besides `peer` which indicates + // somewhat older versions of peer deps. we still support even + // while our devDeps point to a more recent version + "dep": "prod,dev,optional,bundle" +}; diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..630874e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,33 @@ +language: node_js +node_js: + - 14 + - 12 + - 10 + +notifications: + email: false + +script: + - npm test + - 'if [ -n "${LINT-}" ]; then npm run lint; fi' + +before_install: + - npm config set depth 0 + +before_script: > + node_version=$(node -v); + npm install --no-save "express@${EXPRESS}" + +env: + matrix: + - EXPRESS=4 + - EXPRESS=5.0.0-alpha.8 +matrix: + fast_finish: true + include: + - node_js: 'lts/*' + env: LINT=true +# If Express exclusions needed by Node version +# exclude: +# - node_js: 10 +# env: EXPRESS=7 diff --git a/examples/broadcast.js b/examples/broadcast.js index 1ed03c4..4d2393e 100755 --- a/examples/broadcast.js +++ b/examples/broadcast.js @@ -2,7 +2,7 @@ const express = require('express'); let expressWs = require('..'); expressWs = expressWs(express()); -const app = expressWs.app; +const { app } = expressWs; app.ws('/a', (/* ws, req */) => { }); diff --git a/examples/params.js b/examples/params.js index d9829dc..814a3af 100644 --- a/examples/params.js +++ b/examples/params.js @@ -2,7 +2,7 @@ const express = require('express'); let expressWs = require('..'); expressWs = expressWs(express()); -const app = expressWs.app; +const { app } = expressWs; app.param('world', (req, res, next, world) => { req.world = world || 'world'; diff --git a/examples/simple.js b/examples/simple.js index c3324c0..acb993b 100755 --- a/examples/simple.js +++ b/examples/simple.js @@ -2,7 +2,7 @@ const express = require('express'); let expressWs = require('..'); expressWs = expressWs(express()); -const app = expressWs.app; +const { app } = expressWs; app.use((req, res, next) => { console.log('middleware'); diff --git a/package.json b/package.json index db664af..01b80dc 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,9 @@ "module": "src/index", "scripts": { "mocha": "mocha --require esm --require chai/register-expect --timeout 20000 test", - "test": "echo 'Blanking out cache for ESM/nyc that can get corrupted by terminated processes...' && rm -Rf ./node_modules/.cache && nyc npm run mocha", - "lint": "eslint ." + "nyc": "echo 'Blanking out cache for ESM/nyc that can get corrupted by terminated processes...' && rm -Rf ./node_modules/.cache && nyc npm run mocha", + "lint": "eslint --report-unused-disable-directives .", + "test": "npm run lint && npm run nyc" }, "author": "Henning Morud ", "contributors": [ @@ -21,7 +22,7 @@ ], "license": "BSD-2-Clause", "engines": { - "node": ">=4.5.0" + "node": ">=10.0.0" }, "directories": { "example": "examples" @@ -40,19 +41,19 @@ }, "homepage": "https://github.com/HenningM/express-ws", "dependencies": { - "esm": "^3.0.84", - "ws": "^6.0.0" + "esm": "^3.2.25", + "ws": "^7.3.1" }, "peerDependencies": { "express": "^4.0.0 || ^5.0.0-alpha.1" }, "devDependencies": { "chai": "^4.2.0", - "eslint": "^4.19.0", - "eslint-config-airbnb": "^15.1.0", - "eslint-plugin-import": "^2.12.0", - "express": "^5.0.0-alpha.6", - "got": "^11.4.0", + "eslint": "^7.4.0", + "eslint-config-airbnb": "^18.2.0", + "eslint-plugin-import": "^2.22.0", + "express": "^5.0.0-alpha.8", + "got": "^11.5.0", "mocha": "^8.0.1", "nyc": "^15.1.0" } diff --git a/test/test.js b/test/test.js index eca3c3d..2b06fb4 100644 --- a/test/test.js +++ b/test/test.js @@ -1,7 +1,6 @@ import http from 'http'; import express from 'express'; import WebSocket from 'ws'; -// eslint-disable-next-line import/no-extraneous-dependencies import got from 'got'; import expressWs from '../src'; @@ -308,18 +307,19 @@ describe('Error handling', () => { try { ws.send('server response'); } catch (err) { - expect(messages).to.deep.equal([ - 'middleware 1', - 'middleware 2', - 'socket', - 'something', - ]); + // For `ws` 6, this should be the error expect(err.toString()).to.include('WebSocket is not open'); - ws.terminate(); // Close WS client - server.close(); // Close HTTP server underlying WS server - expressWsInstance.getWss().close(); // Close WS server - done(); } + expect(messages).to.deep.equal([ + 'middleware 1', + 'middleware 2', + 'socket', + 'something', + ]); + ws.terminate(); // Close WS client + server.close(); // Close HTTP server underlying WS server + expressWsInstance.getWss().close(); // Close WS server + done(); }); messages.push('socket'); });