-
Notifications
You must be signed in to change notification settings - Fork 465
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: conditional test experimental features with NODE_MAJOR_VERSION #545
Conversation
080913a
to
d098649
Compare
I'll have to find time to look more carefully, but I don't think we should have checks based on NODE_MAJOR_VERSION. It should be that either you need to enable experimental or guard against a specific N-API version. I could be wrong but I think adding checks against the NODE_MAJOR_VERSION will go counter to us wanting to provide support across versions. |
IMO, NODE_MAJOR_VERSION should only be used on the condition of experimental new apis like napi_bigint and previously napi_date which has different backport status so we could distinguish if the related test could be ran on that Node.js version hardly with NAPI_EXPERIMENTAL definition. Out of experimental api should be guarded with NAPI_VERSION normally. |
a9acd95
to
8757704
Compare
8757704
to
d198d14
Compare
For the issue of test not been run, check out here https://travis-ci.com/nodejs/node-addon-api/jobs/248367006#L296, the tests of bigint and date have been run on Node.js v10 and Node.js v12. |
@mhdawson I believe that using |
797d3d5
to
e7b4eea
Compare
Just updated the descriptions of the changelist to better indicate the NODE_MAJOR_VERSION was only used in tests. @mhdawson please take another look :) |
e7b4eea
to
a1cb729
Compare
NAPI_EXPERIMENTAL would be expand to NAPI_VERSION=2147483647 if NAPI_VERSION is not defined. It would be not compatible with various Node.js versions if we use NAPI_VERSION > 2147483646 mixed with definition of NAPI_EXPERIMENTAL. This fix introduced NODE_MAJOR_VERSION to allow more precise control over test sets that which set should be enabled on a Node.js release.
Strictly aligning with Node.js header js_native_api.h in which napi_bigint related apis were nested in NAPI_EXPERIMENTAL.
a1cb729
to
988e5c2
Compare
napi-inl.h
Outdated
@@ -613,9 +613,9 @@ inline double Number::DoubleValue() const { | |||
return result; | |||
} | |||
|
|||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is |
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.
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is | |
// currently experimental guard with version of NAPI_VERSION that it is |
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.
With commit src: enabling BigInt API with NAPI_EXPERIMENTAL
, BigInt would only be enabled with the definition of NAPI_EXPERIMENTAL
rather than a very big NAPI_VERSION
, which is what has been done in js_native_api.h
.
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.
What the comment is trying to say is:
- Currently it is experimental
- When it becomes non-experimental is should be guarded with the NAPI_VERSION in which it became non-experimental (for example it might be version 6).
Maybe it comment should be
// currently experimental, for now guard with definition of NAPI_EXPERIMENTAL. Once it is no
// longer experimental guard with the NAPI_VERSION in which it is released.
napi-inl.h
Outdated
@@ -376,9 +376,9 @@ inline bool Value::IsNumber() const { | |||
return Type() == napi_number; | |||
} | |||
|
|||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is |
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.
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is | |
// currently experimental guard with version of NAPI_VERSION that it is |
napi.h
Outdated
@@ -111,9 +111,9 @@ namespace Napi { | |||
class Value; | |||
class Boolean; | |||
class Number; | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is |
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.
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is | |
// currently experimental guard with version of NAPI_VERSION that it is |
napi.h
Outdated
@@ -139,9 +139,9 @@ namespace Napi { | |||
typedef TypedArrayOf<uint32_t> Uint32Array; ///< Typed-array of unsigned 32-bit integers | |||
typedef TypedArrayOf<float> Float32Array; ///< Typed-array of 32-bit floating-point values | |||
typedef TypedArrayOf<double> Float64Array; ///< Typed-array of 64-bit floating-point values | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is |
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.
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is | |
// currently experimental guard with version of NAPI_VERSION that it is |
napi.h
Outdated
@@ -244,9 +244,9 @@ namespace Napi { | |||
bool IsNull() const; ///< Tests if a value is a null JavaScript value. | |||
bool IsBoolean() const; ///< Tests if a value is a JavaScript boolean. | |||
bool IsNumber() const; ///< Tests if a value is a JavaScript number. | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is |
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.
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is | |
// currently experimental guard with version of NAPI_VERSION that it is |
napi.h
Outdated
@@ -321,9 +321,9 @@ namespace Napi { | |||
double DoubleValue() const; ///< Converts a Number value to a 64-bit floating-point value. | |||
}; | |||
|
|||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is |
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.
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is | |
// currently experimental guard with version of NAPI_VERSION that it is |
napi.h
Outdated
@@ -851,9 +851,9 @@ namespace Napi { | |||
: std::is_same<T, uint32_t>::value ? napi_uint32_array | |||
: std::is_same<T, float>::value ? napi_float32_array | |||
: std::is_same<T, double>::value ? napi_float64_array | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is |
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.
// currently experimental guard with definition of NAPI_EXPERIMENTAL that it is | |
// currently experimental guard with version of NAPI_VERSION that it is |
test/bigint.cc
Outdated
@@ -1,11 +1,12 @@ | |||
// currently experimental guard with version of NODE_MAJOR_VERSION that it is |
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.
// currently experimental guard with version of NODE_MAJOR_VERSION that it is | |
// currently experimental, but tests can't tell which version of Node.js supports | |
// which experimental features. Temporarily guard with NODE_MAJOR_VERISION. | |
// Guard with version of NAPI_VERSION that it is |
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.
I think experimental feature tests do tell which Node.js versions it could be run on. And we should continuously update the test table on each backport.
And experimental features were always temporary status, IMO. It is not necessary to point out that an experimental guard flag is temporary, IMO.
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.
I think it is important to point out that we should NOT use NODE_MAJOR_VERSION once it is not experimental.
I'd be ok with:
// currently experimental temporarily guard with NODE_MAJOR_VERISION.
// Once its no longer experimental guard with version of NAPI_VERSION that it is release in.
test/binding.cc
Outdated
@@ -11,9 +10,9 @@ Object InitBasicTypesArray(Env env); | |||
Object InitBasicTypesBoolean(Env env); | |||
Object InitBasicTypesNumber(Env env); | |||
Object InitBasicTypesValue(Env env); | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with version of NODE_MAJOR_VERSION that it is |
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.
// currently experimental guard with version of NODE_MAJOR_VERSION that it is | |
// currently experimental, but tests can't tell which version of Node.js supports | |
// which experimental features. Temporarily guard with NODE_MAJOR_VERISION. | |
// Guard with version of NAPI_VERSION that it is |
test/binding.cc
Outdated
@@ -56,9 +55,9 @@ Object Init(Env env, Object exports) { | |||
exports.Set("basic_types_boolean", InitBasicTypesBoolean(env)); | |||
exports.Set("basic_types_number", InitBasicTypesNumber(env)); | |||
exports.Set("basic_types_value", InitBasicTypesValue(env)); | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with version of NODE_MAJOR_VERSION that it is |
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.
// currently experimental guard with version of NODE_MAJOR_VERSION that it is | |
// currently experimental, but tests can't tell which version of Node.js supports | |
// which experimental features. Temporarily guard with NODE_MAJOR_VERISION. | |
// Guard with version of NAPI_VERSION that it is |
test/typedarray.cc
Outdated
@@ -1,4 +1,8 @@ | |||
// currently experimental guard with version of NODE_MAJOR_VERSION that it is |
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.
// currently experimental guard with version of NODE_MAJOR_VERSION that it is | |
// currently experimental, but tests can't tell which version of Node.js supports | |
// which experimental features. Temporarily guard with NODE_MAJOR_VERISION. | |
// Guard with version of NAPI_VERSION that it is |
test/typedarray.cc
Outdated
@@ -65,9 +69,9 @@ Value CreateTypedArray(const CallbackInfo& info) { | |||
NAPI_TYPEDARRAY_NEW(Float64Array, info.Env(), length, napi_float64_array) : | |||
NAPI_TYPEDARRAY_NEW_BUFFER(Float64Array, info.Env(), length, buffer, bufferOffset, | |||
napi_float64_array); | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with version of NODE_MAJOR_VERSION that it is |
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.
// currently experimental guard with version of NODE_MAJOR_VERSION that it is | |
// currently experimental, but tests can't tell which version of Node.js supports | |
// which experimental features. Temporarily guard with NODE_MAJOR_VERISION. | |
// Guard with version of NAPI_VERSION that it is |
test/typedarray.cc
Outdated
@@ -101,9 +105,9 @@ Value GetTypedArrayType(const CallbackInfo& info) { | |||
case napi_uint32_array: return String::New(info.Env(), "uint32"); | |||
case napi_float32_array: return String::New(info.Env(), "float32"); | |||
case napi_float64_array: return String::New(info.Env(), "float64"); | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with version of NODE_MAJOR_VERSION that it is |
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.
// currently experimental guard with version of NODE_MAJOR_VERSION that it is | |
// currently experimental, but tests can't tell which version of Node.js supports | |
// which experimental features. Temporarily guard with NODE_MAJOR_VERISION. | |
// Guard with version of NAPI_VERSION that it is |
test/typedarray.cc
Outdated
@@ -143,9 +147,9 @@ Value GetTypedArrayElement(const CallbackInfo& info) { | |||
return Number::New(info.Env(), array.As<Float32Array>()[index]); | |||
case napi_float64_array: | |||
return Number::New(info.Env(), array.As<Float64Array>()[index]); | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with version of NODE_MAJOR_VERSION that it is |
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.
// currently experimental guard with version of NODE_MAJOR_VERSION that it is | |
// currently experimental, but tests can't tell which version of Node.js supports | |
// which experimental features. Temporarily guard with NODE_MAJOR_VERISION. | |
// Guard with version of NAPI_VERSION that it is |
test/typedarray.cc
Outdated
@@ -189,9 +193,9 @@ void SetTypedArrayElement(const CallbackInfo& info) { | |||
case napi_float64_array: | |||
array.As<Float64Array>()[index] = value.DoubleValue(); | |||
break; | |||
// currently experimental guard with version of NAPI_VERSION that it is | |||
// currently experimental guard with version of NODE_MAJOR_VERSION that it is |
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.
// currently experimental guard with version of NODE_MAJOR_VERSION that it is | |
// currently experimental, but tests can't tell which version of Node.js supports | |
// which experimental features. Temporarily guard with NODE_MAJOR_VERISION. | |
// Guard with version of NAPI_VERSION that it is |
test/index.js
Outdated
|
||
if (nodeMajorVersion < 10) { | ||
// currently experimental only test if node major version | ||
// is set to experimental. We can't use napi_experimental here |
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.
// is set to experimental. We can't use napi_experimental here | |
is >= were it exists. We can't use NAPI_EXPERIMENTAL here | |
as the tests can't tell which version of Node.js support which | |
experimental versions. |
test/index.js
Outdated
|
||
if (nodeMajorVersion < 10) { | ||
// currently experimental only test if node major version | ||
// is set to experimental. We can't use napi_experimental here | ||
// as that is not supported as a number on earlier |
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.
// as that is not supported as a number on earlier |
test/index.js
Outdated
|
||
if (nodeMajorVersion < 10) { | ||
// currently experimental only test if node major version | ||
// is set to experimental. We can't use napi_experimental here | ||
// as that is not supported as a number on earlier | ||
// Node.js versions. Once bigint is in a release |
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.
// Node.js versions. Once bigint is in a release | |
Once bigint is in a release |
@legendecas having looked at this carefully I agree that we need to guard the tests with the NODE_MAJOR_VERSION but the comment need to say that when the feature is no longer experimental we'll guard with with the NAPI_VERSION instead. I've made suggested comments. If you think those make sense please accept them and let me know and then I'll run some CI tests to validate and we can get this landed. |
There are many comments with similar content. Posting what I've replied as links:
Also, I've updated the comment in |
34af5b3
to
5fae20a
Compare
@mhdawson I've updated all the comments that mentioned experimental guard with your concern of note on future works. PTAL :) |
@legendecas thanks. Looking now. |
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.
LGTM
Landed as 295e560 |
@mhdawson @gabrielschulhof I think the test script of https://ci.nodejs.org/job/node-test-node-addon-api-new could be simplified as same as what's done to .travis.yml in this PR. How do we make changes to it? |
NAPI_EXPERIMENTAL would be expand to NAPI_VERSION=2147483647 if NAPI_VERSION is not defined. It would be not compatible with various Node.js versions if we use NAPI_VERSION > 2147483646 mixed with definition of NAPI_EXPERIMENTAL. This fix introduced NODE_MAJOR_VERSION to allow more precise control over test sets that which set should be enabled on a Node.js release. PR-URL: nodejs/node-addon-api#545 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
NAPI_EXPERIMENTAL would be expand to NAPI_VERSION=2147483647 if NAPI_VERSION is not defined. It would be not compatible with various Node.js versions if we use NAPI_VERSION > 2147483646 mixed with definition of NAPI_EXPERIMENTAL. This fix introduced NODE_MAJOR_VERSION to allow more precise control over test sets that which set should be enabled on a Node.js release. PR-URL: nodejs/node-addon-api#545 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
NAPI_EXPERIMENTAL would be expand to NAPI_VERSION=2147483647 if NAPI_VERSION is not defined. It would be not compatible with various Node.js versions if we use NAPI_VERSION > 2147483646 mixed with definition of NAPI_EXPERIMENTAL. This fix introduced NODE_MAJOR_VERSION to allow more precise control over test sets that which set should be enabled on a Node.js release. PR-URL: nodejs/node-addon-api#545 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
NAPI_EXPERIMENTAL would be expand to NAPI_VERSION=2147483647 if NAPI_VERSION is not defined. It would be not compatible with various Node.js versions if we use NAPI_VERSION > 2147483646 mixed with definition of NAPI_EXPERIMENTAL. This fix introduced NODE_MAJOR_VERSION to allow more precise control over test sets that which set should be enabled on a Node.js release. PR-URL: nodejs/node-addon-api#545 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
test: conditionally test experimental features with NODE_MAJOR_VERSION
NAPI_EXPERIMENTAL would be expand to NAPI_VERSION=2147483647 if
NAPI_VERSION is not defined. It would be not compatible with various
Node.js versions if we use NAPI_VERSION > 2147483646 mixed with
definition of NAPI_EXPERIMENTAL. This fix introduced NODE_MAJOR_VERSION
to allow more precise control over test sets that which set should be
enabled on a Node.js release.
Refs: #534 (comment)
build: remove unnecessary NAPI_VERSION pre-definition on travis
Since experimental api tests were conditioned by NODE_MAJOR_VERSION, we could simply run tests with
npm test
on every Node.js LTS version.src: enabling BigInt API with NAPI_EXPERIMENTAL
Strictly aligning with Node.js header js_native_api.h in which
napi_bigint related apis were nested in NAPI_EXPERIMENTAL.