Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sequelize-fixtures

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-fixtures - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

lib/logger.js

1

index.js

@@ -7,3 +7,2 @@ var Loader = require('./lib/loader'),

options.encoding = options.encoding || 'utf8';
options.log = options.log || console.log;
return options;

@@ -10,0 +9,0 @@ }

var Promise = require('./Promise');
var Op = require('sequelize').Op;
var objectAssign = require('object-assign');
var Op = require('sequelize').Op;
var logger = require('./logger');
var Loader = module.exports = function(options) {
this.options = options;
this.logger = logger(options.log || options.logger);
this.saved = 0;

@@ -21,2 +24,3 @@ this.skipped = 0;

Loader.prototype.loadFixture = function(fixture, models) {
this.logger.debug(`Loading fixture for model '${fixture.model}:'`, fixture.data);
var buildOptions = fixture.buildOptions,

@@ -41,2 +45,3 @@ saveOptions = fixture.saveOptions,

if (!Model) {
this.logger.error('Model not found: ' + fixture.model + ' (loaded models are: )' + Object.keys(models));
throw new Error('Model not found: ' + fixture.model);

@@ -141,3 +146,3 @@ } else if (typeof Model === 'function' && typeof Model.prototype !== 'object') {

self.fixtureModels[Model.name].push(instance);
return setManyToMany(instance);

@@ -247,3 +252,3 @@ }

} else {
console.warn('attribute "' + key +"' not defined on model '" + Model.name + "'.");
this.logger.warn('attribute "' + key +"' not defined on model '" + Model.name + "'.");
}

@@ -250,0 +255,0 @@ }

@@ -1,6 +0,8 @@

var Promise = require('./Promise'),
path = require('path'),
yaml = require('js-yaml'),
glob = Promise.promisify(require('glob')),
fs = Promise.promisifyAll(require('fs'));
var Promise = require('./Promise');
var path = require('path');
var yaml = require('js-yaml');
var objectAssign = require('object-assign');
var glob = Promise.promisify(require('glob'));
var fs = Promise.promisifyAll(require('fs'));
var logger = require('./logger');

@@ -10,2 +12,3 @@ var Reader = module.exports = function (options) {

this.options = options;
this.logger = logger(options.log || options.logger);
};

@@ -20,3 +23,3 @@

Reader.prototype.readFile = Promise.method(function(filename) {
this.options.log('Fixtures: reading file ' + filename + '...');
this.logger.debug('Fixtures: reading file ' + filename + '...');
var ext = path.extname(filename).toLowerCase();

@@ -23,0 +26,0 @@

{
"name": "sequelize-fixtures",
"version": "1.0.2",
"version": "1.1.0",
"description": "sequelize fixture loader",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -60,2 +60,18 @@ [![Build Status](https://travis-ci.org/domasx2/sequelize-fixtures.svg?branch=master)](https://travis-ci.org/domasx2/sequelize-fixtures)

//specify separate stdout and stderr streams
//(e.g. a winston-compatible logger)
function errorReporter(message) {
console.error('OH NO! ERROR: ' + message);
}
sequelize_fixtures.loadFile('fixtures/*.json', models, {
logger: {
debug: console.log,
info: console.log,
warn: console.log,
error: errorReporter
}
}).then(function(){
doStuffAfterLoad();
});
//load fixtures inside a transaction

@@ -62,0 +78,0 @@ sequelize.transaction(function(tx) {

var sf = require('../index');
var objectAssign = require('object-assign');
var logger = require('./logger');

@@ -9,3 +11,3 @@ module.exports = function(grunt) {

done = this.async(),
options = data.options || {},
options = data.options,
loadFiles = function(models) {

@@ -28,3 +30,8 @@ var sources = [];

// link grunt logging to internal, if not specified
options.log = options.log || grunt.verbose.writeln;
options.logger = options.logger || {
debug: grunt.verbose.writeln,
info: grunt.log.writeln,
warn: grunt.fail.warn,
error: grunt.fail.fatal,
};

@@ -31,0 +38,0 @@ if (typeof models == 'string') {

@@ -20,5 +20,16 @@ var sf = require('../index'),

var noopLogger = {
debug: function() {},
info: function() {},
warn: function() {},
error: function() {},
};
var options = {
logger: noopLogger
};
describe('fixture (with promises)', function() {
it('should load fixture without id', function() {
return sf.loadFixture(FOO_FIXTURE, models)
return sf.loadFixture(FOO_FIXTURE, models, options)
.then(function() {

@@ -46,3 +57,3 @@ return models.Foo.findOne({

}
}, models).then(function() {
}, models, options).then(function() {
return models.Foo.findOne({where: {id: 3}});

@@ -64,3 +75,3 @@ }).then(function(foo){

}
}, models).then(function() {
}, models, options).then(function() {
return models.Article.findOne({

@@ -85,3 +96,3 @@ where: {

}
}, models).then(function() {
}, models, options).then(function() {
return models.Article.findOne({

@@ -98,5 +109,5 @@ where: {

it('should not duplicate fixtures', function () {
return sf.loadFixture(FOO_FIXTURE, models)
return sf.loadFixture(FOO_FIXTURE, models, options)
.then(function() {
return sf.loadFixture(FOO_FIXTURE, models);
return sf.loadFixture(FOO_FIXTURE, models, options);
}).then(function() {

@@ -120,3 +131,3 @@ return models.Foo.count({

}
}], models).then(function() {
}], models, options).then(function() {
return models.Foo.count();

@@ -136,3 +147,3 @@ }).then(function(c){

}
}], models).then(function() {
}], models, options).then(function() {
return models.Foo.count({

@@ -149,3 +160,3 @@ where: {

it('should load fixtures from json', function() {
return sf.loadFile('tests/fixtures/fixture1.json', models)
return sf.loadFile('tests/fixtures/fixture1.json', models, options)
.then(function() {

@@ -162,3 +173,3 @@ return models.Foo.count();

it('should return model count and models', function() {
return sf.loadFile('tests/fixtures/fixture1.json', models)
return sf.loadFile('tests/fixtures/fixture1.json', models, options)
.then(function(retVal) {

@@ -165,0 +176,0 @@ retVal.count.should.equal(3);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc