Skip to content
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

Tests from iconv-lite are not passing #7

Open
bpasero opened this issue Jul 8, 2020 · 11 comments
Open

Tests from iconv-lite are not passing #7

bpasero opened this issue Jul 8, 2020 · 11 comments

Comments

@bpasero
Copy link
Member

bpasero commented Jul 8, 2020

I did an experiment where I let all tests from iconv-lite run against this webpacked version. Here are the steps:

  • copy the test folder of iconv-lite into the root of this project
  • copy all devDependencies of iconv-lite into the package.json of this project
  • copy the "test": "mocha --reporter spec --grep ." over into the scripts section of the package.json of this project
  • remove the UTF-32/UTF-7 exclusions from webpack.config.js
  • ensure you are not webpacking with target: "node" but the default (web)
  • run yarn test

The result is a couple of test failures:

1) Full DBCS encoding tests Encode DBCS encoding 'shiftjis':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  2) Full DBCS encoding tests Encode DBCS encoding 'eucjp':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  3) Full DBCS encoding tests Encode DBCS encoding 'gb18030':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  4) Full DBCS encoding tests Encode DBCS encoding 'cp950':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  5) Full DBCS encoding tests Encode DBCS encoding 'big5hkscs':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  6) Generic UTF8-UCS2 tests Return values are of correct types:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(Buffer.isBuffer(iconv.encode(testString, "utf8")))

      + expected - actual

      -false
      +true
      
      at Context.<anonymous> (test/main-test.js:13:16)
      at processImmediate (internal/timers.js:456:21)

  7) Generic UTF8-UCS2 tests Convert to string, not buffer (utf8 used):

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(Buffer.isBuffer(res))

      + expected - actual

      -false
      +true
      
      at Context.<anonymous> (test/main-test.js:43:16)
      at processImmediate (internal/timers.js:456:21)

  8) UTF-16 decoder handles very short buffers nice:

      AssertionError [ERR_ASSERTION]: '\u0000' == ''
      + expected - actual

      -�
      
      at Context.<anonymous> (test/utf16-test.js:45:16)
      at processImmediate (internal/timers.js:456:21)

@gyzerok @ashtuchkin this worries me a bit. Some notes:

  • all tests run green when using target: "node" (not to any surprise)
  • I am seeing the same test errors when I try [email protected]

I would appreciate some help in fixing these issues as they would probably block the July release where I would like to go back to the webpacked version that does not target node. Thanks.

@bpasero bpasero self-assigned this Jul 8, 2020
@gyzerok
Copy link
Contributor

gyzerok commented Jul 8, 2020

@bpasero have you also tried [email protected]?

@bpasero
Copy link
Member Author

bpasero commented Jul 8, 2020

@gyzerok yes I am seeing the same result with either 0.6.1 or 0.6.2. Especially Error: Bad argument worries me because I thought any Buffer usage is removed in 0.6.2, the line that throws this is:

function convert(conv, input, context) {
  if (!Buffer.isBuffer(input) && input !== FLUSH) {
    throw new Error('Bad argument.');  // Not a buffer or a string.
  }

@bpasero
Copy link
Member Author

bpasero commented Jul 8, 2020

The object that is checked, when using JSON.stringify seems to be: {"type":"Buffer","data":[63]}

@gyzerok
Copy link
Contributor

gyzerok commented Jul 8, 2020

@bpasero I see.

No worries. I've decided to take a small break. Was using most of my free time before to make everything work 😄 But I am confident we can fix everything for July release. I will get back to it this weekend then.

@bpasero
Copy link
Member Author

bpasero commented Jul 8, 2020

Sounds good, thanks.

@bpasero
Copy link
Member Author

bpasero commented Jul 8, 2020

@ashtuchkin if there are no objections, I wonder if we should simply copy the tests folder from iconv-lite over into this repo to be able to run them? Let me know if you have a better idea...

@ashtuchkin
Copy link

ashtuchkin commented Jul 8, 2020 via email

bpasero added a commit that referenced this issue Jul 9, 2020
@bpasero
Copy link
Member Author

bpasero commented Jul 9, 2020

I pushed the tests to this repo so that they can be run via yarn test. Here is the result:

  244 passing (19s)
  33 pending
  8 failing

  1) Full DBCS encoding tests Encode DBCS encoding 'shiftjis':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  2) Full DBCS encoding tests Encode DBCS encoding 'eucjp':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  3) Full DBCS encoding tests Encode DBCS encoding 'gb18030':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  4) Full DBCS encoding tests Encode DBCS encoding 'cp950':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  5) Full DBCS encoding tests Encode DBCS encoding 'big5hkscs':
     Error: Bad argument.
      at convert (node_modules/iconv/lib/iconv.js:103:11)
      at Iconv.convert (node_modules/iconv/lib/iconv.js:64:12)
      at convertWithDefault (test/dbcs-test.js:44:26)
      at Context.<anonymous> (test/dbcs-test.js:230:32)
      at processImmediate (internal/timers.js:456:21)

  6) Generic UTF8-UCS2 tests Return values are of correct types:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(Buffer.isBuffer(iconv.encode(testString, "utf8")))

      + expected - actual

      -false
      +true
      
      at Context.<anonymous> (test/main-test.js:13:16)
      at processImmediate (internal/timers.js:456:21)

  7) Generic UTF8-UCS2 tests Convert to string, not buffer (utf8 used):

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(Buffer.isBuffer(res))

      + expected - actual

      -false
      +true
      
      at Context.<anonymous> (test/main-test.js:43:16)
      at processImmediate (internal/timers.js:456:21)

  8) UTF-16 decoder handles very short buffers nice:

      AssertionError [ERR_ASSERTION]: '\u0000' == ''
      + expected - actual

      -�
      
      at Context.<anonymous> (test/utf16-test.js:45:16)
      at processImmediate (internal/timers.js:456:21)

@gyzerok
Copy link
Contributor

gyzerok commented Jul 11, 2020

Hello @bpasero! I've looked into this as promised.

Especially Error: Bad argument worries me because I thought any Buffer usage is removed in 0.6.2

It's not exactly like that. In 0.6.2 what changed is that iconv-lite won't expect input to be a Buffer. So it won't use any Buffer specific methods on the input (like Buffer.concat) for example. This makes it safe for us to pass in Uint8Array. However internally Buffer is still used.

With most errors you are seeing the problem is not with the library itself or with our webpack build, but with the fact that tests are written without any expectation that they could be run against umd build where Buffer is shimmed.

So the library creates and returns buffers using it's shimmed Buffer, but tests are expecting it to be Node Buffer. These are not compatible and that's why everywhere Buffer.isBuffer is used the problem arises.

After reading this you might start wondering if it means same problem for VSCode when running in Electron. And according to my understanding it is not the case, because we don't expect Buffer as an output, but simply Uint8Array, which means that we won't be using any Buffer specific methods on the output and thus won't have these errors.

Now the only error here which concerns me personally is

  8) UTF-16 decoder handles very short buffers nice:

      AssertionError [ERR_ASSERTION]: '\u0000' == ''
      + expected - actual

      -�
      
      at Context.<anonymous> (test/utf16-test.js:45:16)
      at processImmediate (internal/timers.js:456:21)

I will look into it. And here is my suggestion: I don't think VSCode nor iconv-lite benefit from tests extracted and modified here. For VSCode team it means additional maintenance burden and for iconv-lite it means that nothing gets improved. To avoid this I will try to contribute to the iconv-lite tests directly and hopefully help to move more of them in the browser. Does this make sense?

@gyzerok
Copy link
Contributor

gyzerok commented Jul 11, 2020

I have identified the source of the last error.

// Node
Buffer.from([0x61]).toString('utf16le') == ''
// feross/buffer
Buffer.from([0x61]).toString('utf16le') == '\u0000'

Will see what I can do about it.

@bpasero
Copy link
Member Author

bpasero commented Jul 11, 2020

Sounds good, thanks. And agree, ideally tests would remain in iconv-lite and run in a mode that tests the web scenario 👍

@bpasero bpasero removed their assignment Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants