Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove test adapter and use sqlite #140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ dist
.theia
.vscode
.DS_Store
*.code-workspace
*.code-workspace

# db
spec/test2/db/test.db
spec/test1/db/test.db
spec/test/db/test.db
18 changes: 4 additions & 14 deletions data-object-junction.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ function insert_(obj, callback) {
*/
var relatedModel = self.parent.context.model(self.mapping.childModel);
//find object by querying child object
relatedModel.find(child).select(self.mapping.childField).first(function (err, result) {
var silentMode = !!self.$silent
relatedModel.silent(silentMode).find(child).select(self.mapping.childField).first(function (err, result) {
if (err) {
cb(err);
}
Expand All @@ -429,19 +430,8 @@ function insert_(obj, callback) {
* Validates related object, inserts this object if does not exists
* and finally defines the relation between child and parent objects
*/
if (!result) {
//ensure silent mode
if (self.getBaseModel().$silent) { relatedModel.silent(); }
//insert related item if does not exists
relatedModel.save(child, function(err) {
if (err) {
cb(err);
}
else {
//insert relation between child and parent
insertSingleObject_.call(self, child, function(err) { cb(err); });
}
});
if (result == null) {
return cb(new Error('The associated object cannot be found or is inaccessible.'));
}
else {
//set primary key
Expand Down
105 changes: 104 additions & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,105 @@
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());

/* global jest */
jest.setTimeout(30000);
jest.setTimeout(30000);
Loading