refs #6436 feat: jasmine helper
This commit is contained in:
parent
cb55740b68
commit
d6ee5d571e
|
@ -84,12 +84,13 @@ async function test() {
|
|||
'loopback/**/*[sS]pec.js',
|
||||
'modules/*/back/**/*.[sS]pec.js'
|
||||
],
|
||||
helpers: [`back/tests-helper.js`]
|
||||
helpers: [`back/vn-jasmine.js`]
|
||||
};
|
||||
|
||||
if (PARALLEL) {
|
||||
const ParallelRunner = require('jasmine/parallel');
|
||||
runner = new ParallelRunner({numWorkers: 1});
|
||||
config.helpers.push(`back/tests-helper.js`);
|
||||
} else {
|
||||
const Jasmine = require('jasmine');
|
||||
runner = new Jasmine();
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
const LoopBackContext = require('loopback-context');
|
||||
const DEFAULT_ACCESS_TOKEN = {accessToken: {userId: 9}};
|
||||
const DEFAULT_HEADERS = {headers: {origin: 'http://localhost'}};
|
||||
const DEFAULT_BEFORE_ALL = {
|
||||
ctx: {
|
||||
req: {
|
||||
...DEFAULT_ACCESS_TOKEN,
|
||||
...DEFAULT_HEADERS
|
||||
|
||||
},
|
||||
args: {}
|
||||
}
|
||||
};
|
||||
const DEFAULT_LOOPBACK_CTX = {
|
||||
...DEFAULT_ACCESS_TOKEN,
|
||||
http: {
|
||||
req: {
|
||||
...DEFAULT_HEADERS
|
||||
}
|
||||
},
|
||||
args: {}
|
||||
};
|
||||
|
||||
function vnBeforeAll(value = DEFAULT_BEFORE_ALL) {
|
||||
Object.assign(beforeAll, value);
|
||||
}
|
||||
function mockBeforeAll(value = DEFAULT_BEFORE_ALL) {
|
||||
const origin = beforeAll.ctx;
|
||||
Object.assign(origin, value);
|
||||
return origin;
|
||||
}
|
||||
|
||||
const mockLoopBackContext = (value = DEFAULT_LOOPBACK_CTX) => {
|
||||
const activeCtx = value;
|
||||
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
return activeCtx;
|
||||
};
|
||||
module.exports = {
|
||||
mockBeforeAll, mockLoopBackContext
|
||||
};
|
||||
|
||||
(function init() {
|
||||
vnBeforeAll();
|
||||
})();
|
Loading…
Reference in New Issue