-
Notifications
You must be signed in to change notification settings - Fork 9
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
Can't import mudder 1.1.1 with jest #19
Comments
Thanks for the note! Hmm, it seems to work when I try the following very basic steps: first, mkdir newtest
npm init -y
npm i mudder typescript @types/mudder
npx tsc --init Then I create the following in import * as mudder from 'mudder';
console.log(mudder.base62.mudder(1))
console.log(mudder.base62.mudder(3)) before finally running: npx tsc -p .
node index.js I get the following: $ mudderts node index.js
[ 'U' ]
[ 'F', 'U', 'k' ] Let me know if the above works? Because, the above works if I install |
Ok, thanks. I will check my workflow. |
After checking my workflow and using your example as a starting point, I found that the problem occurs when testing with Jest (don't know why yet). npm i jest ts-jest @types/jest add the file const { defaults: tsjPreset } = require("ts-jest/presets");
module.exports = {
transform: {
...tsjPreset.transform,
},
}; and the file test import * as mudder from "mudder";
// import mudder = require("mudder");
// const mudder = require("mudder");
describe("tests", function () {
it("test generate string", function () {
expect(mudder.base62.mudder(1)).toBeTruthy();
});
}); and then type npx jest The result: TypeError: Cannot read properties of undefined (reading 'mudder')
5 | describe("tests", function () {
6 | it("test generate string", function () {
> 7 | expect(mudder.base62.mudder(1)).toBeTruthy();
| ^
8 | // expect("test").toBeTruthy();
9 | });
10 | }); |
Hmm, when I follow your instructions, I get ➜ npx jest
PASS ./index.test.js
PASS ./index.test.ts (9.972 s)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 12.005 s
Ran all test suites. Here's an orphan branch with the state of my directory right now: https://github.com/fasiha/mudderjs/tree/issue-19 Can you compare your state to mine and see where the diff is? Are we getting different versions of typescript/jest?
This is definitely the case but we all expected #18 to be a user-invisible change. If it turns out this is not an issue with your setup but is a broader problem, I'll definitely cut a 2.0 release. Thanks for bearing with me while we figure this out! |
The issue-19 brunch works, indeed. BUT when changing the mudder version to 1.1.1 (in package.json), the aforementioned error occurs. Could you check it with mudder version 1.1.1? |
Any news about the tests? |
Thanks for the updated info and the poke @tiagocpeixoto! Sorry for the delay, I now see I was misled last week, and you're right, with the latest mudder, jest indeed fails. @vitaliytv, sorry to bother you with this, I'm curious if you knew what might be causing this issue with jest? Before #18 (mudder 1.1.0) seems to work fine, but with #18 the following happens—first, the setup: git clone [email protected]:fasiha/mudderjs.git issue-19
cd issue-19
git checkout issue-19
npm i
npx jest --clearCache
npx jest This produces the following error:
I'm sure it's some weird Jest issue because I can run Potentially relevant links that I consulted that didn't help: |
thank you import { jest } from '@jest/globals'
import * as mudder from 'mudder'
test('Empty options', () => {
expect(mudder.base62.mudder(1)).toBeTruthy()
}) i recommend use something other for example test director: import { deepEqual } from 'assert'
import TestDirector from 'test-director'
import * as mudder from 'mudder'
const tests = new TestDirector()
tests.add('test director', async () => {
deepEqual(mudder.base62.mudder(1), ['U'])
})
tests.run() npx coverage-node test/index.js |
Hi there! Is it really not possible to use mudder 1.1.1 with Jest? |
no, use 1.1.0 |
@tiagocpeixoto are you trying to avoid pinning to a patch version of mudder in your package.json? If so, what I can do is re-release 1.1.1 as 2.0 and release a new 1.1.2 that's equal to 1.1.0 (i.e., roll back 1.1.1 in v1). I do think that, since we broke "developer" backwards compatibility somehow, we should release a new major version 😅. Will that work for you? Please accept my apologies for (1) not realizing the issue with Jest (I'm not a user), and (2) for taking so long to understand your issue! Let me know if this will work, I'll take care of it right away (~24 hours). |
@fasiha, yes, it will work. Thank you in advance. |
@tiagocpeixoto thanks for your patience, v1.1.2 should be identical to v1.1.0 and should continue working with Jest. v2.0 meanwhile has @vitaliytv's esbuild improvements. Both just pushed. I hope we can figure out how to get Jest to work but in the meantime, hopefully this workaround is ok. |
Just a note: Jest v28 solves the problem and can be used with mudder v2.0.0. |
When importing version 1.1.1 using Typescript, I got the following error:
I tried to import using these statements, without success:
The error only occurs with version 1.1.1. The previous version was ok.
Env:
Node version 16
Typescript version 4.5.5
Webpack version 5.68
Jest version 27.4.7
Test code:
The text was updated successfully, but these errors were encountered: