From 673df495d6ca97919423fd3da4915bc3393581d0 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 23 Nov 2020 13:19:05 -0500 Subject: [PATCH] test: fixup testing for specific N-API version Fixup testing for a specific N-API version and document. --- 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) {