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.

Wierd issue when running with jest

See original GitHub issue

I know this is very little information, but I’ve encountered the following when executing some tests with Jest, which touches code that connects to MySQL using node-mysql2, but the code makes no queries.

Any ideas on what causes this issue? The code is fine, when executed directly.

PROJECT_FOLDER/node_modules/jest-runtime/build/index.js:439
    const wrapper = this._environment.runScript(script)[
                                                       ^

TypeError: Cannot read property 'Object.<anonymous>' of null
    at Runtime._execModule (PROJECT_FOLDER/node_modules/jest-runtime/build/index.js:439:56)
    at Runtime.requireModule (PROJECT_FOLDER/node_modules/jest-runtime/build/index.js:296:14)
    at Runtime.requireModuleOrMock (PROJECT_FOLDER/node_modules/jest-runtime/build/index.js:365:19)
    at Object.getCodec (PROJECT_FOLDER/node_modules/iconv-lite/lib/index.js:61:27)
    at Object.getDecoder (PROJECT_FOLDER/node_modules/iconv-lite/lib/index.js:118:23)
    at Object.<anonymous>.exports.decode (PROJECT_FOLDER/node_modules/mysql2/lib/parsers/string.js:19:23)
    at Packet.Object.<anonymous>.Packet.readNullTerminatedString (PROJECT_FOLDER/node_modules/mysql2/lib/packets/packet.js:371:23)
    at Function.Object.<anonymous>.Handshake.fromPacket (PROJECT_FOLDER/node_modules/mysql2/lib/packets/handshake.js:19:31)
    at ClientHandshake.Object.<anonymous>.ClientHandshake.handshakeInit (PROJECT_FOLDER/node_modules/mysql2/lib/commands/client_handshake.js:83:38)
    at ClientHandshake.Object.<anonymous>.Command.execute (PROJECT_FOLDER/node_modules/mysql2/lib/commands/command.js:39:20)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

20reactions
opatutcommented, Jul 6, 2017

I found a temporary workaround for now, add this to your setupTestFrameworkScriptFile:

// Hack to make iconv load the encodings module, otherwise jest crashes. Compare
// https://github.com/sidorares/node-mysql2/issues/489
require('mysql2/node_modules/iconv-lite').encodingExists('foo');

Might look a bit different depending on your setup 😉

4reactions
v1d3rm3commented, Dec 22, 2018

I found a temporary workaround for now, add this to your setupTestFrameworkScriptFile:

// Hack to make iconv load the encodings module, otherwise jest crashes. Compare
// https://github.com/sidorares/node-mysql2/issues/489
require('mysql2/node_modules/iconv-lite').encodingExists('foo');

Might look a bit different depending on your setup 😉

In typescript, just do:

// Hack to make iconv load the encodings module, otherwise jest crashes. Compare
// https://github.com/sidorares/node-mysql2/issues/489
import * as iconv from 'iconv-lite';
iconv.encodingExists('foo');

In my case, foo was cp1252

Read more comments on GitHub >

github_iconTop Results From Across the Web

Very poor performance on basic tests · Issue #7963 - GitHub
It's weird that Jest reports that a test runs in 10ms but the reported time is 5seconds. Even on my work laptop, running...
Read more >
Randomly failing tests jest and supertest Node.js
Tests could pass 10 times in a row and then suddenly that weird 'jest' timer shows up and 3 cases fail. I'm using...
Read more >
Jest: Does It Test Funny to You? | Ackee blog
The issue however is that you know about the benefits from the start (easy to write) and feel the pain much later on...
Read more >
Jest Testing like a Pro - Tips and tricks
When you run Jest, tests are run by file, within that file you can have groups of related tests, which you put under...
Read more >
Fixing Jest Memory Usage on CircleCI | hey it's violet
We realized that the issue might lie with how Jest spawns child processes. Although test output appears linear, the tests by default run...
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