不要怂,就是干,撸起袖子干!

Commit 4b54342a by papb

test: fix 6f74bf62 for Node.js 6

1 parent f42d5f3a
...@@ -76,7 +76,6 @@ ...@@ -76,7 +76,6 @@
"mocha": "^6.1.4", "mocha": "^6.1.4",
"mysql2": "^1.6.5", "mysql2": "^1.6.5",
"nyc": "^14.1.1", "nyc": "^14.1.1",
"p-timeout": "^4.0.0",
"pg": "^7.8.1", "pg": "^7.8.1",
"pg-hstore": "^2.x", "pg-hstore": "^2.x",
"pg-types": "^2.0.0", "pg-types": "^2.0.0",
......
{ {
"ignorePatterns": ["**/__patched_p-timeout__.js"],
"rules": { "rules": {
"no-invalid-this": 0, "no-invalid-this": 0,
"no-unused-expressions": 0, "no-unused-expressions": 0,
......
/**
* This is just `https://npmjs.com/package/p-timeout` transpiled with Babel.js to ensure compatibility with Node.js 6
*/
'use strict';
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
class TimeoutError extends Error {
constructor(message) {
super(message);
this.name = 'TimeoutError';
}
}
const pTimeout = (promise, milliseconds, fallback, options) => {
let timer;
const cancelablePromise = new Promise((resolve, reject) => {
if (typeof milliseconds !== 'number' || milliseconds < 0) {
throw new TypeError('Expected `milliseconds` to be a positive number');
}
if (milliseconds === Infinity) {
resolve(promise);
return;
}
options = _objectSpread({
customTimers: {
setTimeout,
clearTimeout
}
}, options);
timer = options.customTimers.setTimeout.call(undefined, () => {
if (typeof fallback === 'function') {
try {
resolve(fallback());
} catch (error) {
reject(error);
}
return;
}
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
if (typeof promise.cancel === 'function') {
promise.cancel();
}
reject(timeoutError);
}, milliseconds);
_asyncToGenerator(function* () {
try {
resolve(yield promise);
} catch (error) {
reject(error);
} finally {
options.customTimers.clearTimeout.call(undefined, timer);
}
})();
});
cancelablePromise.clear = () => {
clearTimeout(timer);
timer = undefined;
};
return cancelablePromise;
};
module.exports = pTimeout; // TODO: Remove this for the next major release
module.exports.default = pTimeout;
module.exports.TimeoutError = TimeoutError;
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// avoiding to be affected unintentionally by `sinon.useFakeTimers()` called by the tests themselves. // avoiding to be affected unintentionally by `sinon.useFakeTimers()` called by the tests themselves.
const { setTimeout, clearTimeout } = global; const { setTimeout, clearTimeout } = global;
const pTimeout = require('p-timeout'); const pTimeout = require('./__patched_p-timeout__');
const Support = require('../support'); const Support = require('../support');
const CLEANUP_TIMEOUT = Number.parseInt(process.env.SEQ_TEST_CLEANUP_TIMEOUT, 10) || 10000; const CLEANUP_TIMEOUT = Number.parseInt(process.env.SEQ_TEST_CLEANUP_TIMEOUT, 10) || 10000;
...@@ -20,11 +20,11 @@ before(function() { ...@@ -20,11 +20,11 @@ before(function() {
}); });
}); });
beforeEach(async function() { beforeEach(function() {
await Support.clearDatabase(this.sequelize); return Support.clearDatabase(this.sequelize);
}); });
afterEach(async function() { afterEach(function() {
// Note: recall that throwing an error from a `beforeEach` or `afterEach` hook in Mocha causes the entire test suite to abort. // Note: recall that throwing an error from a `beforeEach` or `afterEach` hook in Mocha causes the entire test suite to abort.
let runningQueriesProblem; let runningQueriesProblem;
...@@ -40,14 +40,14 @@ afterEach(async function() { ...@@ -40,14 +40,14 @@ afterEach(async function() {
runningQueries = new Set(); runningQueries = new Set();
try { return Promise.resolve().then(() => {
await pTimeout( return pTimeout(
Support.clearDatabase(this.sequelize), Support.clearDatabase(this.sequelize),
CLEANUP_TIMEOUT, CLEANUP_TIMEOUT,
`Could not clear database after this test in less than ${CLEANUP_TIMEOUT}ms. This test crashed the DB, and testing cannot continue. Aborting.`, `Could not clear database after this test in less than ${CLEANUP_TIMEOUT}ms. This test crashed the DB, and testing cannot continue. Aborting.`,
{ customTimers: { setTimeout, clearTimeout } } { customTimers: { setTimeout, clearTimeout } }
); );
} catch (error) { }).catch(error => {
let message = error.message; let message = error.message;
if (runningQueriesProblem) { if (runningQueriesProblem) {
message += `\n\n Also, ${runningQueriesProblem}`; message += `\n\n Also, ${runningQueriesProblem}`;
...@@ -56,8 +56,7 @@ afterEach(async function() { ...@@ -56,8 +56,7 @@ afterEach(async function() {
// Throw, aborting the entire Mocha execution // Throw, aborting the entire Mocha execution
throw new Error(message); throw new Error(message);
} }).then(() => {
if (runningQueriesProblem) { if (runningQueriesProblem) {
if (this.test.ctx.currentTest.state === 'passed') { if (this.test.ctx.currentTest.state === 'passed') {
// `this.test.error` is an obscure Mocha API that allows failing a test from the `afterEach` hook // `this.test.error` is an obscure Mocha API that allows failing a test from the `afterEach` hook
...@@ -67,6 +66,7 @@ afterEach(async function() { ...@@ -67,6 +66,7 @@ afterEach(async function() {
console.log(` ${runningQueriesProblem}`); console.log(` ${runningQueriesProblem}`);
} }
} }
});
}); });
module.exports = Support; module.exports = Support;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!