pluginpal/strapi-plugin-config-sync

Import data to config/env/test database

Closed this issue · 8 comments

Hello, i'm working on jest test for strapi.

I have a database in config folder but when i'm running some test i have a new database in config/env/test.
And my objective its when i'm running my test before starting my sqlite server it's to get the sync folder and his data.
But at this moment when i'm doing "yarn cs import" that only impact my "real" database.

Maybe i'm doing something wrong ;)

Aha. OK.
So what does your test command look like to start the test instance. What is it that differentiates it from a regular ‘strapi start’.
Do you use some ENV variables in the command to specify to use the test db?
I think the plugin should then listen to that env variable and connect to the right db.

HI thanks for the answer !
My command look like : "NODE_ENV=test yarn build && jest --forceExit --detectOpenHandles" and here i wanted to add my import form my sync directory.
I followed this github for strapi test in typescript : https://github.com/qunabu/strapi-unit-test-example/tree/ver4ts.
And so i have this architecture in my config folder :

Capture d’écran du 2022-12-27 07-23-07

And for create a strapi database instance during my test i have this code :
Capture d’écran du 2022-12-27 07-30-16

Allright, seems legit.
Though I'm still not quite understand when in this process the config import occurs. Is it before, during or after the jest command?

I tried somes :

  • in my test command before build
  • Before and after the await instance.server.mount()

I'm not sure i did your command to import in good moment

I think you have to do it after your build command and before your test command. Something like this: NODE_ENV=test yarn build && NODE_ENV=test yarn cs import -y && jest --forceExit --detectOpenHandles

Hi @ArmandThomas,

Just checking in. Have you managed to make it work based on the example I gave you?

I'm gonna close this due to inactivity