diff --git a/test/index.js b/test/index.js index 8f8ea37cd..2f0933658 100644 --- a/test/index.js +++ b/test/index.js @@ -35,15 +35,17 @@ const path = require('path'); let filterCondition = process.env.npm_config_filter || ''; let filterConditionFiles = []; -if (process.env.npm_config_filter !== null && process.env.npm_config_filter !== undefined && process.env.npm_config_filter.trim() !== '') { +if (filterCondition !== '') { filterCondition = require('../unit-test/matchModules').matchWildCards(process.env.npm_config_filter); - filterConditionFiles = filterCondition.split(' ').length ? filterCondition.split(' ') : [filterCondition]; + filterConditionFiles = filterCondition.split(' ').length > 0 ? filterCondition.split(' ') : [filterCondition]; } +const filterConditionsProvided = filterConditionFiles.length > 0; + function checkFilterCondition (fileName, parsedFilepath) { let result = false; - if (!filterConditionFiles.length) result = true; + if (!filterConditionsProvided) return true; if (filterConditionFiles.includes(parsedFilepath)) result = true; if (filterConditionFiles.includes(fileName)) result = true; return result; @@ -108,7 +110,7 @@ if (napiVersion < 3) { testModules.splice(testModules.indexOf('version_management'), 1); } -if (napiVersion < 4 && !filterConditionFiles.length) { +if (napiVersion < 4 && !filterConditionsProvided) { testModules.splice(testModules.indexOf('asyncprogressqueueworker'), 1); testModules.splice(testModules.indexOf('asyncprogressworker'), 1); testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function_ctx'), 1); @@ -119,30 +121,30 @@ if (napiVersion < 4 && !filterConditionFiles.length) { testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function'), 1); } -if (napiVersion < 5 && !filterConditionFiles.length) { +if (napiVersion < 5 && !filterConditionsProvided) { testModules.splice(testModules.indexOf('date'), 1); } -if (napiVersion < 6 && !filterConditionFiles.length) { +if (napiVersion < 6 && !filterConditionsProvided) { testModules.splice(testModules.indexOf('addon'), 1); testModules.splice(testModules.indexOf('addon_data'), 1); testModules.splice(testModules.indexOf('bigint'), 1); testModules.splice(testModules.indexOf('typedarray-bigint'), 1); } -if (majorNodeVersion < 12 && !filterConditionFiles.length) { +if (majorNodeVersion < 12 && !filterConditionsProvided) { testModules.splice(testModules.indexOf('objectwrap_worker_thread'), 1); testModules.splice(testModules.indexOf('error_terminating_environment'), 1); } -if (napiVersion < 8 && !filterConditionFiles.length) { +if (napiVersion < 8 && !filterConditionsProvided) { testModules.splice(testModules.indexOf('object/object_freeze_seal'), 1); } (async function () { console.log(`Testing with Node-API Version '${napiVersion}'.`); - if (filterConditionFiles.length) { console.log('Starting test suite\n', testModules); } else { console.log('Starting test suite\n'); } + if (filterConditionsProvided) { console.log('Starting test suite\n', testModules); } else { console.log('Starting test suite\n'); } // Requiring each module runs tests in the module. for (const name of testModules) {