Skip to content

Commit

Permalink
fix(ci): replace after with run-series to address flaky superagent be…
Browse files Browse the repository at this point in the history
…havior
  • Loading branch information
wesleytodd committed Sep 1, 2024
1 parent 11dd0b9 commit 04f8c3b
Show file tree
Hide file tree
Showing 4 changed files with 720 additions and 537 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"utils-merge": "1.0.1"
},
"devDependencies": {
"after": "0.8.2",
"eslint": "8.34.0",
"eslint-config-standard": "14.1.1",
"eslint-plugin-import": "2.26.0",
Expand All @@ -29,6 +28,7 @@
"finalhandler": "1.2.0",
"mocha": "10.2.0",
"nyc": "15.1.0",
"run-series": "^1.1.9",
"safe-buffer": "5.2.1",
"supertest": "6.3.3"
},
Expand Down
73 changes: 43 additions & 30 deletions test/param.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var after = require('after')
var series = require('run-series')
var Router = require('..')
var utils = require('./support/utils')

Expand Down Expand Up @@ -35,7 +35,6 @@ describe('Router', function () {
})

it('should map logic for a path param', function (done) {
var cb = after(2, done)
var router = new Router()
var server = createServer(router)

Expand All @@ -49,13 +48,18 @@ describe('Router', function () {
res.end('get user ' + req.params.id)
})

request(server)
.get('/user/2')
.expect(200, 'get user 2', cb)

request(server)
.get('/user/bob')
.expect(200, 'get user NaN', cb)
series([
function (cb) {
request(server)
.get('/user/2')
.expect(200, 'get user 2', cb)
},
function (cb) {
request(server)
.get('/user/bob')
.expect(200, 'get user NaN', cb)
}
], done)
})

it('should allow chaining', function (done) {
Expand Down Expand Up @@ -121,7 +125,6 @@ describe('Router', function () {
})

it('should only invoke fn when necessary', function (done) {
var cb = after(2, done)
var router = new Router()
var server = createServer(router)

Expand All @@ -137,14 +140,19 @@ describe('Router', function () {
router.get('/user/:user', saw)
router.put('/user/:id', saw)

request(server)
.get('/user/bob')
.expect(500, /Error: boom/, cb)

request(server)
.put('/user/bob')
.expect('x-id', 'bob')
.expect(200, 'saw PUT /user/bob', cb)
series([
function (cb) {
request(server)
.get('/user/bob')
.expect(500, /Error: boom/, cb)
},
function (cb) {
request(server)
.put('/user/bob')
.expect('x-id', 'bob')
.expect(200, 'saw PUT /user/bob', cb)
}
], done)
})

it('should only invoke fn once per request', function (done) {
Expand Down Expand Up @@ -300,7 +308,6 @@ describe('Router', function () {

describe('next("route")', function () {
it('should cause route with param to be skipped', function (done) {
var cb = after(3, done)
var router = new Router()
var server = createServer(router)

Expand All @@ -326,17 +333,23 @@ describe('Router', function () {
res.end('cannot get a new user')
})

request(server)
.get('/user/2')
.expect(200, 'get user 2', cb)

request(server)
.get('/user/bob')
.expect(404, cb)

request(server)
.get('/user/new')
.expect(400, 'cannot get a new user', cb)
series([
function (cb) {
request(server)
.get('/user/2')
.expect(200, 'get user 2', cb)
},
function (cb) {
request(server)
.get('/user/bob')
.expect(404, cb)
},
function (cb) {
request(server)
.get('/user/new')
.expect(400, 'cannot get a new user', cb)
}
], done)
})

it('should invoke fn if path value differs', function (done) {
Expand Down
Loading

0 comments on commit 04f8c3b

Please sign in to comment.