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

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

Closed
nadongguri opened this issue Dec 17, 2018 · 9 comments
Closed

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

nadongguri opened this issue Dec 17, 2018 · 9 comments

Comments

@nadongguri
Copy link
Contributor

nadongguri commented Dec 17, 2018

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?

@nadongguri nadongguri changed the title npm test is failed on earlier ode.js versions npm test is failed on earlier Node.js versions Dec 17, 2018
@NickNaso
Copy link
Member

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

@nadongguri
Copy link
Contributor Author

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);
}

@NickNaso
Copy link
Member

Are you using nvm?

@nadongguri
Copy link
Contributor Author

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.

@NickNaso
Copy link
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.

@nadongguri
Copy link
Contributor Author

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.

@nadongguri
Copy link
Contributor Author

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

@mhdawson
Copy link
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.

@mhdawson
Copy link
Member

mhdawson commented Dec 7, 2020

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.

@mhdawson mhdawson closed this as completed Dec 7, 2020
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