question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error running tests with Jest using mysql2 1.7.0

See original GitHub issue

I get the following error after updating from mysql2@^1.6.5 to mysql2@^1.7.0.

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.

      at Object.getCodec (node_modules/mysql2/node_modules/iconv-lite/lib/index.js:65:27)
      at Object.getDecoder (node_modules/mysql2/node_modules/iconv-lite/lib/index.js:127:23)
      at Object.<anonymous>.exports.decode (node_modules/mysql2/lib/parsers/string.js:10:25)
      at Packet.readNullTerminatedString (node_modules/mysql2/lib/packets/packet.js:384:25)
      at Function.fromPacket (node_modules/mysql2/lib/packets/handshake.js:58:33)
C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\node_modules\iconv-lite\lib\index.js:106
                throw new Error("Encoding not recognized: '" + encoding + "' (searched as: '"+enc+"')");
                ^

Error: Encoding not recognized: 'cesu8' (searched as: 'cesu8')
    at Object.getCodec (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\node_modules\iconv-lite\lib\index.js:106:23)
    at Object.getDecoder (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\node_modules\iconv-lite\lib\index.js:127:23)
    at Object.<anonymous>.exports.decode (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\lib\parsers\string.js:10:25)
    at Packet.readNullTerminatedString (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\lib\packets\packet.js:384:25)
siroc\repositories\sphinxql\node_modules\mysql2\lib\packets\handshake.js:58:33)
    at ClientHandshake.handshakeInit (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\lib\commands\client_handshake.js:92:40)
    at ClientHandshake.execute (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\lib\commands\command.js:39:22)
    at Connection.handlePacket (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\lib\connection.js:449:32)
    at PacketParser.Connection.packetParser.p [as onPacket] (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\lib\connection.js:72:12)
    at PacketParser.executeStart (C:\Users\siroc\repositories\sphinxql\node_modules\mysql2\lib\packet_parser.js:75:16)

If you want to see the project with all updated (except the mysql2 package) to replicate the problem use https://github.com/SiroDiaz/sphinxql. Note that it is under develop branch. Just try to update mysql2 to latest version(1.7.0), start Manticore search 3.1.0 and run jest tests.

Start Manticore search daemon:

cd __tests__
searchd --config sphinx.conf

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
halfercommented, May 8, 2020

There’s two errors here. The second one:

Error: Encoding not recognized: 'cesu8' (searched as: 'cesu8')

This can be resolved using this code (tests/setup.js):

// Little fix for Jest, see https://stackoverflow.com/a/54175600
require('mysql2/node_modules/iconv-lite').encodingExists('foo');

Then wire it in using jest.config.json:

{
  "setupFilesAfterEnv": ["<rootDir>/tests/setup.js"]
}
3reactions
damianobarbaticommented, Jan 21, 2022

Not working with native ESM (type=module).

What’s going on?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error running tests with Jest using mysql2 1.7.0 - Bountysource
Note that it is under develop branch. Just try to update mysql2 to latest version(1.7. 0), start Manticore search 3.1. 0 and run...
Read more >
node.js - Encoding not recognized in jest.js - Stack Overflow
I have a problem testing a project using node-mysql2, react, sequelize and jest. This problem only occurs during testing.
Read more >
Configuring Jest
By default, Jest runs all tests and produces all errors into the console upon completion. The bail config option can be used here...
Read more >
Installing kubeadm | Kubernetes
To run containers in Pods, Kubernetes uses a container runtime. ... For example, the kubelet running 1.7.0 should be fully compatible with a ......
Read more >
How To Test a React App with Jest and React Testing Library
You will use Jest to write and run unit tests, and you will implement ... when testing the absence of an element without...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found