-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add select object query helper class (#143)
* add select object query helper class * validate results * require dotenv * remove dotenv config * bump @themost/query@2.5.9 to @themost/query@2.5.22 * 2.6.47
- Loading branch information
1 parent
9ad4a57
commit b017458
Showing
7 changed files
with
13,655 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,7 @@ | ||
const { TraceUtils } = require('@themost/common'); | ||
const moment = require('moment'); | ||
const {inspect} = require('util'); | ||
|
||
class JestLogger { | ||
|
||
/** | ||
* @param {{dateFormat:string=,logLevel:string=,format:raw=}=} options | ||
*/ | ||
constructor(options) { | ||
this.options = Object.assign({}, { | ||
dateFormat: 'DD/MMM/YYYY:HH:mm:ss Z', | ||
logLevel: 'info', | ||
format: 'raw' | ||
}, options); | ||
if (options == null) { | ||
// validate NODE_ENV environment variable | ||
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') { | ||
this.options.logLevel = 'debug'; | ||
} | ||
} | ||
this.level = JestLogger.Levels.info; | ||
if (Object.prototype.hasOwnProperty.call(JestLogger.Levels), this.options.logLevel) { | ||
this.level = JestLogger.Levels[this.options.logLevel]; | ||
} | ||
|
||
} | ||
|
||
static get Levels() { | ||
return { | ||
error: 0, | ||
warn: 1, | ||
info: 2, | ||
verbose: 3, | ||
debug: 4 | ||
}; | ||
} | ||
|
||
log() { | ||
if (this.level < JestLogger.Levels.info) { | ||
return; | ||
} | ||
this.write.apply(this, ['log'].concat(Array.from(arguments))); | ||
} | ||
|
||
info() { | ||
if (this.level < JestLogger.Levels.info) { | ||
return; | ||
} | ||
this.write.apply(this, ['info'].concat(Array.from(arguments))); | ||
} | ||
|
||
warn() { | ||
if (this.level < JestLogger.Levels.warn) { | ||
return; | ||
} | ||
this.write.apply(this, ['warn'].concat(Array.from(arguments))); | ||
} | ||
|
||
error() { | ||
if (this.level < JestLogger.Levels.error) { | ||
return; | ||
} | ||
this.write.apply(this, ['error'].concat(Array.from(arguments))); | ||
} | ||
|
||
verbose() { | ||
if (this.level < JestLogger.Levels.verbose) { | ||
return; | ||
} | ||
this.write.apply(this, ['verbose'].concat(Array.from(arguments))); | ||
} | ||
|
||
debug() { | ||
if (this.level < JestLogger.Levels.debug) { | ||
return; | ||
} | ||
this.write.apply(this, ['debug'].concat(Array.from(arguments))); | ||
} | ||
|
||
/** | ||
* @param {string} level | ||
* @param {...*} arg | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
write(level, arg) { | ||
const args = Array.from(arguments); | ||
const log = (level === 'error') ? process.stderr : process.stdout | ||
if (args.length > 1) { | ||
if (args[args.length - 1] == null) { | ||
args.pop(); | ||
} | ||
} | ||
// add timestamp | ||
args.unshift(moment().format(this.options.dateFormat || 'DD/MMM/YYYY:HH:mm:ss Z')); | ||
log.write(args.map((arg) => inspect(arg)).map( | ||
(arg) => arg.replace(/^'/, '').replace(/'$/, '') | ||
).join(',') + '\n'); | ||
} | ||
} | ||
|
||
TraceUtils.useLogger(new JestLogger()); | ||
|
||
const { JsonLogger } = require('@themost/json-logger'); | ||
TraceUtils.useLogger(new JsonLogger({ | ||
format: 'raw' | ||
})); | ||
/* global jest */ | ||
jest.setTimeout(30000); |
Oops, something went wrong.