Skip to content

Commit

Permalink
- Breaking change: Update engines to Node 10+
Browse files Browse the repository at this point in the history
- Linting: As per latest eslint config
- Linting: Add `--report-unused-disable-directives` flag
- Linting: Switch to `.eslintrc.js` so can add comments
- CI: Add `travis.yml`
- Testing: Make `nyc` separate script and add it and `lint` to `test` script
- Maintenance: Add `.ncurc.js` config to allow `npm-check-updates` to avoid auto-updating peerDeps.
- npm: Update deps. (esm, ws) and devDeps.
  • Loading branch information
brettz9 committed Jul 8, 2020
1 parent a54f4f3 commit bb6ba52
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 51 deletions.
43 changes: 43 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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
}
};
27 changes: 0 additions & 27 deletions .eslintrc.json

This file was deleted.

8 changes: 8 additions & 0 deletions .ncurc.js
Original file line number Diff line number Diff line change
@@ -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"
};
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
language: node_js
node_js:
- 14
- 12
- 10

notifications:
email: false

script:
- npm ci
- '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
2 changes: 1 addition & 1 deletion examples/broadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */) => {
});
Expand Down
2 changes: 1 addition & 1 deletion examples/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>",
"contributors": [
Expand All @@ -21,7 +22,7 @@
],
"license": "BSD-2-Clause",
"engines": {
"node": ">=4.5.0"
"node": ">=10.0.0"
},
"directories": {
"example": "examples"
Expand All @@ -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"
}
Expand Down
22 changes: 11 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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');
});
Expand Down

0 comments on commit bb6ba52

Please sign in to comment.