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

Array of files not working #80

Open
Sorgrum opened this issue Aug 11, 2017 · 7 comments
Open

Array of files not working #80

Sorgrum opened this issue Aug 11, 2017 · 7 comments
Labels

Comments

@Sorgrum
Copy link

Sorgrum commented Aug 11, 2017

I'm trying to do this
sequelize_fixtures.loadFile(['fixtures/user.json', 'fixtures/authentication.json'], models).then(() => { ... }

But it results in the following error:

Unhandled rejection TypeError: glob pattern string required
    at new Minimatch (.../node_modules/minimatch/minimatch.js:116:11)
    at setopts (.../node_modules/glob/common.js:113:20)
    at new Glob (.../node_modules/glob/glob.js:135:3)
    at glob (.../node_modules/glob/glob.js:75:10)
    at tryCatcher (.../node_modules/bluebird/js/main/util.js:26:23)
    at ret (eval at makeNodePromisifiedEval (.../node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:14:23)
    at module.exports.Reader.readFileGlob (.../node_modules/sequelize-fixtures/lib/reader.js:38:12)
    at .../node_modules/sequelize-fixtures/index.js:49:19
    at Object.loadFile (.../node_modules/sequelize-fixtures/index.js:21:23)
    at .../index.js:57:24
    at tryCatcher (.../node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (.../node_modules/sequelize/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (.../node_modules/sequelize/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (.../node_modules/sequelize/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (.../node_modules/sequelize/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (.../node_modules/sequelize/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (.../node_modules/sequelize/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (.../node_modules/sequelize/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:800:20)
    at tryOnImmediate (timers.js:762:5)
    at processImmediate [as _immediateCallback] (timers.js:733:5)

I get the same error if I include only one element in the array:
sequelize_fixtures.loadFile(['fixtures/user.json'], models).then(() => { ... }

but I don't get an error I load the same file not as an array:
sequelize_fixtures.loadFile('fixtures/user.json', models).then(() => { ... }

@balexandre
Copy link

balexandre commented Nov 13, 2017

Did you try the wildcard? (that's what I use and it's been working fine for a long time... I never had the need to specify only some files)

sequelize_fixtures.loadFile('fixtures/*.json', models).then(() => {
 // ...
});

this is my initialization/index.js

const chalk = require('chalk');
const fixtures = require('sequelize-fixtures');

const models = require('./../server/models');
const logger = require('./../server/utilities/logger');

// from file
module.exports = (callback) => {
  fixtures
    .loadFile('./initialization/fixtures/*.json', models)
    .then(() => {
      logger.log(chalk.green('Test data added to database'));
      callback();
    });
};

@Sorgrum
Copy link
Author

Sorgrum commented Dec 6, 2017

The wildcard does work, but the order the fixtures load in matters. Using the wildcard seems to use alphabetical order.

So while the wildcard does work, it doesn't work for my case.
I ended up having multiple calls like this:

await sequelize_fixtures.loadFile("fixtures/user.json", models);
await sequelize_fixtures.loadFile("fixtures/authentication.json", models);

@balexandre
Copy link

balexandre commented Dec 6, 2017

@Sorgrum

So while the wildcard does work, it doesn't work for my case.

to solve that problem, I use

001.user.json
002.authentication.json

as file names, and I know they will always follow the order I set up to be.

you can even name as

001.user.json
005.authentication.json
010.somethingelse.json

so in the future, you can have a file in between ...

@Sorgrum
Copy link
Author

Sorgrum commented Dec 6, 2017

Sure, I personally don't think that's a very elegant way of solving the problem, but regardless the usage docs say this should work:

    //array of files
    sequelize_fixtures.loadFiles(['fixtures/users.json', 'fixtures/data*.json'], models).then(function(){
        doStuffAfterLoad();
    });

and it hadn't been working for me.

@balexandre
Copy link

@Sorgrum I do prefer the file editing than edit all the time the function...

:)

@Sorgrum
Copy link
Author

Sorgrum commented Dec 6, 2017

Sure, so maybe we should just update the docs to reflect that passing in an array of files isn't a valid way to load fixtures?

@matmar10
Copy link
Collaborator

@Sorgrum can you raise a PR with a change to the README.md you feel is appropriate? Thanks!

@matmar10 matmar10 added the docs label Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants