diff --git a/test/custom-methods-v4.test.js b/test/custom-methods-v4.test.js index e0168d5..109acd1 100644 --- a/test/custom-methods-v4.test.js +++ b/test/custom-methods-v4.test.js @@ -10,7 +10,7 @@ describe('feathers 4 custom http methods', () => { return; // only valid with feathers 4 } - let server; + let appTeardown; const startFeathersWithService = (service) => { const app = express(feathers()) @@ -21,10 +21,10 @@ describe('feathers 4 custom http methods', () => { .configure(express.rest()) .use('/service', service); - return startFeathersApp(app, 6776).then((res) => { server = res; }); + return startFeathersApp(app, 6776).then((res) => { appTeardown = res; }); }; - afterEach(done => server.close(done)); + afterEach(done => appTeardown(() => done())); it('handle simple post method', async () => { const customService = { diff --git a/test/custom-methods-v5.test.js b/test/custom-methods-v5.test.js index e42c1cd..7a2c38a 100644 --- a/test/custom-methods-v5.test.js +++ b/test/custom-methods-v5.test.js @@ -60,9 +60,9 @@ describe('feathers 5 custom methods', () => { describe(`using customMethodsHandler with ${type}`, () => { const { initApp } = options; - let server; + let appTeardown; - afterEach(done => server.close(done)); + afterEach(done => appTeardown(() => done())); it('should handle simple post method', async () => { const customService = { @@ -74,7 +74,7 @@ describe('feathers 5 custom methods', () => { }) }; - server = await startFeathersWithService(initApp, customService, ['find', 'getVersion']); + appTeardown = await startFeathersWithService(initApp, customService, ['find', 'getVersion']); const { data: responseContent } = await axios.post( 'http://localhost:6776/service/getVersion?param=abc', @@ -101,7 +101,7 @@ describe('feathers 5 custom methods', () => { }) }; - server = await startFeathersWithService(initApp, customService, ['find', 'getVersion']); + appTeardown = await startFeathersWithService(initApp, customService, ['find', 'getVersion']); const { data: responseContent } = await axios.get('http://localhost:6776/service/5/version?param=abc'); @@ -124,7 +124,7 @@ describe('feathers 5 custom methods', () => { }) }; - server = await startFeathersWithService(initApp, customService, ['find', 'getVersion']); + appTeardown = await startFeathersWithService(initApp, customService, ['find', 'getVersion']); const { data: responseContent } = await axios.get('http://localhost:6776/service/5/version?param=abc'); @@ -146,7 +146,7 @@ describe('feathers 5 custom methods', () => { }) }; - server = await startFeathersWithService(initApp, customService, ['find', 'setVersion']); + appTeardown = await startFeathersWithService(initApp, customService, ['find', 'setVersion']); const { data: responseContent } = await axios.put( 'http://localhost:6776/service/5/version?param=abc', @@ -171,7 +171,7 @@ describe('feathers 5 custom methods', () => { }) }; - server = await startFeathersWithService(initApp, customService, ['find', 'setVersion']); + appTeardown = await startFeathersWithService(initApp, customService, ['find', 'setVersion']); const { data: responseContent } = await axios.patch( 'http://localhost:6776/service/5/version?param=abc', @@ -196,7 +196,7 @@ describe('feathers 5 custom methods', () => { }) }; - server = await startFeathersWithService(initApp, customService, ['find', 'removeVersion']); + appTeardown = await startFeathersWithService(initApp, customService, ['find', 'removeVersion']); const { data: responseContent } = await axios.delete( 'http://localhost:6776/service/5/version?param=abc' @@ -226,7 +226,7 @@ describe('feathers 5 custom methods', () => { }); describe('without customMethodsHandler', () => { - let server; + let appTeardown; let app; const initApp = () => { @@ -236,7 +236,7 @@ describe('feathers 5 custom methods', () => { }); }; - afterEach(done => { server.close(done); app = undefined; }); + afterEach(done => { appTeardown(() => { done(); app = undefined; }); }); it('should not fail and don\'t add custom methods to open api specs', async () => { const customService = { @@ -248,7 +248,7 @@ describe('feathers 5 custom methods', () => { }) }; - server = await startFeathersWithService(initApp, customService, ['find', 'getVersion']); + appTeardown = await startFeathersWithService(initApp, customService, ['find', 'getVersion']); try { await axios.post( diff --git a/test/helper.js b/test/helper.js index 3129804..b1bba6d 100644 --- a/test/helper.js +++ b/test/helper.js @@ -14,13 +14,13 @@ if (feathers.version && feathers.version[0] >= '5') { * Start feathers app (compatibility layer to support feathers 4 and 5) * @param {object} app * @param {number} port - * @param {Function} [done] - * @return {Promise} server + * @return {Promise} appShutdown */ - exports.startFeathersApp = async function (app, port, done) { - const server = await app.listen(port); - if (done) { done(); } - return server; + exports.startFeathersApp = async function (app, port) { + await app.listen(port); + return (done) => { + app.teardown().then(done); + }; }; const { SERVICE } = feathers; @@ -59,16 +59,13 @@ if (feathers.version && feathers.version[0] >= '5') { * Start feathers app (compatibility layer to support feathers 4 and 5) * @param {object} app * @param {number} port - * @param {Function} [done] - * @return {Promise} server + * @return {Promise} server */ - exports.startFeathersApp = function (app, port, done) { - let server; + exports.startFeathersApp = async function (app, port) { return new Promise(resolve => { - server = app.listen(port, () => resolve()); - }).then(() => { - if (done) { done(); } - return server; + const server = app.listen(port, () => resolve((done) => { + server.close(() => { done(); }); + })); }); }; diff --git a/test/index.test.js b/test/index.test.js index 5fa87e8..1c983b8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -19,7 +19,7 @@ describe('feathers-swagger', () => { const { initApp } = options; describe(`should serve openapi json file with ${type}`, () => { - let server; + let appTeardown; let app; const startApp = (swaggerConfig) => { @@ -36,10 +36,10 @@ describe('feathers-swagger', () => { ...swaggerConfig })); - return startFeathersApp(app, 6776).then((res) => { server = res; }); + return startFeathersApp(app, 6776).then((res) => { appTeardown = res; }); }; - afterEach(done => server.close(done)); + afterEach(done => appTeardown(() => { done(); appTeardown = undefined; })); it('default as /swagger.json', async () => { await startApp({}); diff --git a/test/ui.test.js b/test/ui.test.js index e69ac8a..0247fdc 100644 --- a/test/ui.test.js +++ b/test/ui.test.js @@ -26,6 +26,7 @@ describe('feathers-swagger.swaggerUI', () => { const { initApp } = options; describe(`when using ${type}`, () => { let app; + let appTeardown; let messageService; const startServiceWithUi = (ui) => { @@ -45,7 +46,7 @@ describe('feathers-swagger.swaggerUI', () => { ) .use('/messages', messageService); - return startFeathersApp(app, 6776); + return startFeathersApp(app, 6776).then(teardown => { appTeardown = teardown; }); }; before(done => { @@ -74,10 +75,8 @@ describe('feathers-swagger.swaggerUI', () => { }); afterEach(function (done) { - this.timeout(50000); - app.teardown().then(() => { - done(); - }); + this.timeout(10000); + appTeardown(() => done()); }); ['/docs', '/docs/'].forEach((requestPath) => {