Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Trouble with db initialization for automated testing #1911
Basically, the problem arise when I launch my (small for the moment) tests in watch mode:
On the first run everything seems to work as intended, tables are created and populated without issues:
but as soon as the watch is triggered (adding a space anywhere for example), I get this:
I think I am doing something wrong but I can't figure it out...
and finally a typical migration file:
I tried to see knex log with DEBUG=knex.* but saw absolutly no difference between the 2 cases (first run versus subsequent runs)
It's probably something dumb but I seem blind to it right now
I think this question should go to stackoverflow. Knex issue tracker should be used only for development purposes.
That aside try to make your tests work first with file based database. You are probably not understanding how sqlite inmemory databases work. https://www.sqlite.org/inmemorydb.html
Every connection you make to inmemory database creates new distinct database. So if your app is using inmemory database and your tests are trying to connect to it and reset it, the database that your app is using will not change.
I didn't see your app code there... if you are initializing the app in tests files and pass the initialized database for it, in that case you might be able to make your tests run using plain inmemorydb. In that case probably easiest way to reset it is to kill old knex instance and create a new one before each test.