strapi / documentation

Strapi Documentation
https://docs.strapi.io
Other
1.03k stars 1.12k forks source link

Error log is suppressed in unit test when following unit testing guide #15

Closed jasonprado closed 2 years ago

jasonprado commented 4 years ago

Describe the bug I’m following the unit testing guide and I hit an error because I didn’t have sqlite3 installed. No error was printed at the command line and I had to console.log from inside the framework to see what was wrong.

Steps to reproduce the behavior

  1. Follow the unit testing guide. Add a database.json for the test env that references the sqlite client.
  2. Do not install the npm module sqlite3
  3. Copy in the test helper and the app test outlined in the guide.
  4. yarn run test

Expected behavior These lines in the framework are executing, thus an error should be printed:

        strapi.log.error('The client `' + connection.settings.client + '` is not installed.');
        strapi.log.error(
          'You can install it with `$ npm install ' + connection.settings.client + ' --save`.'
        );

Actual behavior A callstack referencing knex.js is printed but the log messages are not visible.

Code snippets The line in strapi code that I expect an error from: https://github.com/strapi/strapi/blob/master/packages/strapi-connector-bookshelf/lib/knex.js#L79.

System

Additional context I don't know if jest is swallowing the error or if strapi.log.error isn't emitting it. I followed the guide so I'd expect it to work. Also the guide should probably mention installing sqlite3. Thanks!

derrickmehaffy commented 4 years ago

Can you try to use just a normal console.log and as a side note it appears that guide needs some updating as it should be a database.js not database.json

jasonprado commented 4 years ago

A console.log appears with the jest boilerplate around it:

  ● Console

    console.log
      <the message appears here>
derrickmehaffy commented 4 years ago

I'll ping @alexandrebodin about this to see if he has any suggestions on it, as the tests run outside the normal Strapi application I'm not sure we should be using strapi.log

jasonprado commented 4 years ago

Thanks for looking. I'm using a custom JestEnvironment to set up the Strapi object, so there's space to set up the logger if it needs to be configured.

alexandrebodin commented 4 years ago

Hi, It might be swallowed somehow but your custom jest environement. Can you try without your custom env ?

meganelacheny commented 2 years ago

Hello,

I will mark this issue as closed for now, as there has been no reply in a while. Also, we are no longer maintaining the Strapi v3 documentation, except for security-related issues, as the EOL (end of life) for Strapi v3 is due to end of 2022 (see Security file for more information).

We would suggest v3 users to use the various migration resources below to upgrade projects from Strapi v3 to Strapi v4:

Thank you!