-
Notifications
You must be signed in to change notification settings - Fork 15
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
test: ensure BigInts are decoded as BigInts #18
Conversation
If you encode an object with a BigInt property, you get a Number back when the buffer is decoded - is this intentional? Also, the node tests appear to be run during `npm test:browser`?
Ports ipfs/go-ipns@3deb032 to js. The browser tests won't pass until rvagg/cborg#18 is resolved.
Ports ipfs/go-ipns@3deb032 to js. The browser tests won't pass until rvagg/cborg#18 is resolved.
Yes, from the README, we're in this position with integers:
for
for
So, tag-free, cborg does this:
And there are existing tests to probe all of these boundaries too -- if we made this new test pass, a bunch of others would fail. These decisions are mostly driven around DAG-CBOR obviously, and here's the set of factors there that contribute to the state of play:
So the current implementation takes one of the possible paths here to dealing with integers in JavaScript. There are other options we could take, and these are certainly worth ongoing discussions so I wouldn't rule out a shift here if we decide on better API choices:
|
@@ -15,7 +15,7 @@ | |||
"build:types": "npm run build:copy && cd dist && tsc --build", | |||
"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js dist/cjs/node-test/node-test-*.js", | |||
"test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/test-*.js test/node-test-*.js", | |||
"test:browser": "polendina --page --worker --serviceworker --cleanup dist/cjs/node-test/test-*.js", | |||
"test:browser": "polendina --page --worker --serviceworker --cleanup dist/cjs/browser-test/test-*.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this looks like an error!
I think the current way is the most user-friendly one. From an IPLD perspective, I think it would be great to have a mode, where IPLD Data-Model integers are always |
Ha, you're joking, right? You put one type in, you get another type back and they are completely incompatible, though it's hard to see how it would be any other way without a schema. Anyway thanks for the detailed explanation @rvagg, the tradeoffs that have been made are clear and this PR should be closed. |
If you encode an object with a BigInt property, you get a Number back when the buffer is decoded - is this intentional?
Also, the node tests appear to be run during
npm test:browser
?This PR doesn't fix anything but does add a failing test as I'm not sure whether this is intended behaviour or not.