Skip to content

npm test is failed on earlier Node.js versions #409

Closed

Description

@nadongguri

Hi, node-addon-api,

I've checked 'npm test' with earlier Node.js versions (v8.9.4) on linux env and
some tests such as bigint, callbackscope are required to higher version of Node.js.

Checking napi version is already in test/index.js but the value process.env.npm_config_NAPI_VERSION
is undefined on my setup, so.. users should set that value? (I have searched npm_config_NAPI_VERSION in the node and node-addon-api source but I couldn't find the define).
Or is it fine to modify that code in test/index.js by using a node version to pass tests?

Activity

  1. changed the title [-]npm test is failed on earlier ode.js versions[/-] [+]npm test is failed on earlier Node.js versions[/+] on Dec 17, 2018
  2. NickNaso commented on Dec 17, 2018

    @NickNaso
    Member

    Hi @nadongguri,
    could you specify the Node.js versions that present the problem?

  3. nadongguri commented on Dec 17, 2018

    @nadongguri
    ContributorAuthor

    Hi @NickNaso,

    I'm afraid this situation only happens in my environments (I have checked it on ubuntu laptops and servers) but the point is that process.env.npm_config_NAPI_VERSION is "undefined".
    Even though there is code to splice test cases by using npm_config_NAPI_VERSION, I guess it's not working..

    test/index.js
    if ((process.env.npm_config_NAPI_VERSION !== undefined) &&
        (process.env.npm_config_NAPI_VERSION < 50000)) {
      // currently experimental only test if NAPI_VERSION
      // is set to experimental. We can't use C max int
      // as that is not supported as a number on earlier
      // Node.js versions. Once bigint is in a release
      // this should be guarded on the napi version
      // in which bigint was added.
      testModules.splice(testModules.indexOf('bigint'), 1);
      testModules.splice(testModules.indexOf('typedarray-bigint'), 1);
    }
    

    As far as I understand, the bigint primitive type is added since Nodejs v10.4.0 so "npm test" is failed with earlier version on Nodejs.

    Running test 'bigint'
    /home/ryan/Desktop/node/node-addon-api/test/bigint.js:19
        0n,
        ^
    
    SyntaxError: Invalid or unexpected token
    

    In addition, the version_management test is failed with Nodejs v8.4.0 because of napi in process.versions is Nan. I think this issue also can be solved if this code is working properly.

    test/index.js
    if ((process.env.npm_config_NAPI_VERSION !== undefined) &&
        (process.env.npm_config_NAPI_VERSION < 3)) {
      testModules.splice(testModules.indexOf('callbackscope'), 1);
      testModules.splice(testModules.indexOf('version_management'), 1);
    }
    
  4. NickNaso commented on Dec 17, 2018

    @NickNaso
    Member

    Are you using nvm?

  5. nadongguri commented on Dec 17, 2018

    @nadongguri
    ContributorAuthor

    Hi @NickNaso,
    I used to download Nodejs in https://nodejs.org/dist but now I can use nvm. :)
    I've installed nvm, downloaded few versions of nodejs and tested. Still I get the same result.

  6. NickNaso commented on Dec 17, 2018

    @NickNaso
    Member

    I want better understand the problem:
    Could you try this?
    nvm list
    The output should be something like this:
    screenshot 2018-12-17 at 15 52 23
    Then if you have system you can switch to system version:
    nvm use system
    Try to execute the test suite after this switch and if you don't have the problem is something correlated with nvm otherwise we need to investigate more deeply.

  7. nadongguri commented on Dec 17, 2018

    @nadongguri
    ContributorAuthor

    Hi @NickNaso,

    ryan@ryan-Inspiron-7566:~/Desktop/node/node-addon-api$ nvm list
    ->      v8.14.0
            v11.4.0
             system
    default -> node (-> v11.4.0)
    node -> stable (-> v11.4.0) (default)
    stable -> 11.4 (-> v11.4.0) (default)
    niojs -> N/A (default)
    vlts/* -> lts/dubnium (-> N/A)
    mlts/argon -> v4.9.1 (-> N/A)
    lts/boron -> v6.15.1 (-> N/A)
    lts/carbon -> v8.14.0
    lts/dubnium -> v10.14.2 (-> N/A)
    
    ryan@ryan-Inspiron-7566:~/Desktop/node/node-addon-api$ nvm use system
    Now using system version of node: v8.12.0 (npm v6.4.1)
    

    As you see system's verison is v8.12.0. With the latest clean node-addon-api code in master branch,
    "npm test" is failed at the bigint test.

    > node-addon-api@1.6.2 test /home/ryan/Desktop/node/node-addon-api
    > node test
    
    Starting test suite
    
    Running test 'arraybuffer'
    Running test 'asynccontext'
    Running test 'asyncworker'
    Running test 'basic_types/array'
    Running test 'basic_types/boolean'
    Running test 'basic_types/number'
    Running test 'basic_types/value'
    Running test 'bigint'
    /home/ryan/Desktop/node/node-addon-api/test/bigint.js:19
        0n,
        ^
    
    SyntaxError: Invalid or unexpected token
    
    

    I'm wondering when process.env.npm_config_NAPI_VERSION is set... or I can add code to check nodejs and napi version then skip those test cases with unproper nodejs.

  8. nadongguri commented on Dec 18, 2018

    @nadongguri
    ContributorAuthor

    I knew how process.env_npm_config_#macro# is set by referring to #350.

  9. mhdawson commented on Dec 18, 2018

    @mhdawson
    Member

    Out CI sets the NAPI_VERSION as follows

    echo 'console.log(process.versions.napi)' >get_napi_version.js
    NAPI_VERSION_REPORTED=`node get_napi_version.js`
    npm test --NAPI_VERSION=$NAPI_VERSION_REPORTED

    We should probably document this somewhere. I think I had tried to make it automatically default to the right value but was not successful.

  10. mhdawson commented on Dec 7, 2020

    @mhdawson
    Member

    I recently added some additional detail in this section: https://github.com/nodejs/node-addon-api#tests. Closing. Please let us know if that was not the right thing to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions