From 356e93d69a1a9c294e52ff1f28a5347becf38de2 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Thu, 26 Nov 2020 18:08:41 -0500 Subject: [PATCH] test: fixup testing for specific N-API version (#840) Fixup testing for a specific N-API version and document. Reviewed-By: NickNaso PR-URL: https://github.com/nodejs/node-addon-api/pull/840 --- README.md | 9 +++++++++ test/index.js | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e7ee391d..41935336d 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,15 @@ npm install npm test --disable-deprecated ``` +To run the tests targetting a specific version of N-API run +``` +npm install +export NAPI_VERSION=X +npm test --NAPI_VERSION=X +``` + +where X is the version of N-API you want to target. + ### **Debug** To run the **node-addon-api** tests with `--debug` option: diff --git a/test/index.js b/test/index.js index ac95d88aa..ece32b3b4 100644 --- a/test/index.js +++ b/test/index.js @@ -62,7 +62,15 @@ let testModules = [ 'version_management' ]; -const napiVersion = Number(process.versions.napi) +let napiVersion = Number(process.versions.napi) +if (process.env.NAPI_VERSION) { + // we need this so that we don't try run tests that rely + // on methods that are not available in the NAPI_VERSION + // specified + napiVersion = process.env.NAPI_VERSION; +} +console.log('napiVersion:' + napiVersion); + const majorNodeVersion = process.versions.node.split('.')[0] if (napiVersion < 3) {