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

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

Closed
jasonprado opened this issue Aug 25, 2020 · 6 comments
Closed
Assignees
Labels
pr: fix Used on the docs repo for anything that is not "new" or "updated" content: chore, typos, fixes, etc. severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: Dev Docs PRs/issues targeting the Developer Docs target: v3 Documentation PRs/issues targeting content from docs-v3.strapi.io (v3 branch)

Comments

@jasonprado
Copy link

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

  • Node.js version: v12.8.1
  • NPM version: yarn 1.22.4
  • Strapi version: 3.0.5
  • Database: sqlite
  • Operating system: Debian linux (running in docker desktop on macOS)

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
Copy link
Member

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
Copy link
Author

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

  ● Console

    console.log
      <the message appears here>

@derrickmehaffy
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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

@derrickmehaffy derrickmehaffy transferred this issue from strapi/strapi Dec 15, 2020
@derrickmehaffy derrickmehaffy added severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: Dev Docs PRs/issues targeting the Developer Docs pr: fix Used on the docs repo for anything that is not "new" or "updated" content: chore, typos, fixes, etc. labels Dec 15, 2020
@pwizla pwizla added the target: v3 Documentation PRs/issues targeting content from docs-v3.strapi.io (v3 branch) label May 16, 2022
@meganelacheny meganelacheny self-assigned this Jun 1, 2022
@meganelacheny
Copy link
Collaborator

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix Used on the docs repo for anything that is not "new" or "updated" content: chore, typos, fixes, etc. severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: Dev Docs PRs/issues targeting the Developer Docs target: v3 Documentation PRs/issues targeting content from docs-v3.strapi.io (v3 branch)
Projects
None yet
Development

No branches or pull requests

5 participants