diff --git a/lib/index.js b/lib/index.js index 0232fce..75f5484 100644 --- a/lib/index.js +++ b/lib/index.js @@ -38,7 +38,10 @@ class Backend { this.options = { ...getDefaults(), ...(this.options || {}), ...options } this.allOptions = allOptions if (this.services && this.options.reloadInterval) { - setInterval(() => this.reload(), this.options.reloadInterval) + const timer = setInterval(() => this.reload(), this.options.reloadInterval) + if (typeof timer === 'object') { + timer.unref() + } } } diff --git a/package.json b/package.json index 50df799..4a28a81 100644 --- a/package.json +++ b/package.json @@ -77,8 +77,8 @@ "compile": "npm run compile:esm && npm run compile:cjs", "browser": "browserify --ignore cross-fetch --standalone i18nextHttpBackend cjs/index.js -o i18nextHttpBackend.js && uglifyjs i18nextHttpBackend.js --compress --mangle -o i18nextHttpBackend.min.js", "build": "npm run compile && npm run browser", - "test:xmlhttpreq": "mocha test -R spec --require test/fixtures/xmlHttpRequest.cjs --exit --experimental-modules", - "test:fetch": "mocha test -R spec --exit --experimental-modules", + "test:xmlhttpreq": "mocha test -R spec --require test/fixtures/xmlHttpRequest.cjs --experimental-modules", + "test:fetch": "mocha test -R spec --experimental-modules", "test": "npm run lint && npm run build && npm run test:fetch && npm run test:xmlhttpreq && npm run test:typescript", "test:typescript": "tslint --project tsconfig.json && tsd", "test:deno": "deno test --allow-net test/deno/*.js", diff --git a/test/fixtures/server.js b/test/fixtures/server.js index aace61b..c1e305f 100644 --- a/test/fixtures/server.js +++ b/test/fixtures/server.js @@ -6,6 +6,11 @@ const server = (done) => { if (js) return done(null, js) js = jsonServer.create() + js.use((req, res, next)=> { + // disable keep alive so the test server can close quickly. + res.setHeader('Connection', 'close') + next() + }) js.use(jsonServer.bodyParser) js.get('/locales/en/testqs', (req, res) => { @@ -54,7 +59,7 @@ const server = (done) => { js.listen(5001, () => { console.log('JSON Server is running') done(null, js) - }) + }).unref() } export default server diff --git a/test/http.spec.js b/test/http.spec.js index 71caca6..b77be7a 100644 --- a/test/http.spec.js +++ b/test/http.spec.js @@ -41,8 +41,8 @@ describe(`http backend using ${hasXMLHttpRequest() ? 'XMLHttpRequest' : 'fetch'} errO = err dataO = data resolve(true) - setTimeout(() => reject(new Error('timeout')), 1500) }) + setTimeout(() => reject(new Error('timeout')), 1500).unref() }) // evaluate outside callback to get actuall error when something is wrong expect(errO).to.be(null) @@ -72,8 +72,8 @@ describe(`http backend using ${hasXMLHttpRequest() ? 'XMLHttpRequest' : 'fetch'} errO = err dataO = data resolve(true) - setTimeout(() => reject(new Error('timeout')), 1500) }) + setTimeout(() => reject(new Error('timeout')), 1500).unref() }) // evaluate outside callback to get actuall error when something is wrong expect(errO).to.be(null)