Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 4b54342a
authored
Jan 17, 2021
by
papb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: fix
6f74bf62
for Node.js 6
1 parent
f42d5f3a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
18 deletions
package.json
test/.eslintrc.json
test/integration/__patched_p-timeout__.js
test/integration/support.js
package.json
View file @
4b54342
...
...
@@ -76,7 +76,6 @@
"mocha"
:
"^6.1.4"
,
"mysql2"
:
"^1.6.5"
,
"nyc"
:
"^14.1.1"
,
"p-timeout"
:
"^4.0.0"
,
"pg"
:
"^7.8.1"
,
"pg-hstore"
:
"^2.x"
,
"pg-types"
:
"^2.0.0"
,
...
...
test/.eslintrc.json
View file @
4b54342
{
"ignorePatterns"
:
[
"**/__patched_p-timeout__.js"
],
"rules"
:
{
"no-invalid-this"
:
0
,
"no-unused-expressions"
:
0
,
...
...
test/integration/__patched_p-timeout__.js
0 → 100644
View file @
4b54342
/**
* 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
;
test/integration/support.js
View file @
4b54342
...
...
@@ -4,7 +4,7 @@
// avoiding to be affected unintentionally by `sinon.useFakeTimers()` called by the tests themselves.
const
{
setTimeout
,
clearTimeout
}
=
global
;
const
pTimeout
=
require
(
'
p-timeout
'
);
const
pTimeout
=
require
(
'
./__patched_p-timeout__
'
);
const
Support
=
require
(
'../support'
);
const
CLEANUP_TIMEOUT
=
Number
.
parseInt
(
process
.
env
.
SEQ_TEST_CLEANUP_TIMEOUT
,
10
)
||
10000
;
...
...
@@ -20,11 +20,11 @@ before(function() {
});
});
beforeEach
(
async
function
()
{
await
Support
.
clearDatabase
(
this
.
sequelize
);
beforeEach
(
function
()
{
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.
let
runningQueriesProblem
;
...
...
@@ -40,14 +40,14 @@ afterEach(async function() {
runningQueries = new Set();
try
{
await
pTimeout(
return Promise.resolve().then(() =>
{
return
pTimeout(
Support.clearDatabase(this.sequelize),
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.`
,
{
customTimers
:
{
setTimeout
,
clearTimeout
}
}
);
}
catch
(
error
)
{
}
).
catch
(
error
=>
{
let
message
=
error
.
message
;
if
(
runningQueriesProblem
)
{
message
+=
`\n\n Also,
${
runningQueriesProblem
}
`
;
...
...
@@ -56,17 +56,17 @@ afterEach(async function() {
// Throw, aborting the entire Mocha execution
throw
new
Error
(
message
);
}
if
(
runningQueriesProblem
)
{
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 is better than throwing because throwing would cause the entire Mocha execution to abort
this
.
test
.
error
(
new
Error
(
`This test passed, but
${
runningQueriesProblem
}
`
));
}
else
{
console
.
log
(
`
${
runningQueriesProblem
}
`
);
}
).
then
(()
=>
{
if
(
runningQueriesProblem
)
{
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 is better than throwing because throwing would cause the entire Mocha execution to abort
this
.
test
.
error
(
new
Error
(
`This test passed, but
${
runningQueriesProblem
}
`
));
}
else
{
console
.
log
(
`
${
runningQueriesProblem
}
`
);
}
}
}
}
);
});
module
.
exports
=
Support
;
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment