test: ensure BigInts are decoded as BigInts#18
test: ensure BigInts are decoded as BigInts#18achingbrain wants to merge 1 commit intorvagg:masterfrom
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:
|
| "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", |
|
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.