From a223b2b6b3b085699abb10e3453c26b0a903651d Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 29 Mar 2019 10:07:39 +0200 Subject: [PATCH] fix: respect files property from karma.config on `tns test android --bundle` command Rel to: https://github.com/NativeScript/nativescript-cli/issues/4477 https://github.com/NativeScript/nativescript-cli/issues/1798 --- unit-testing-config-loader.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/unit-testing-config-loader.js b/unit-testing-config-loader.js index 3d257915..6cd582b7 100644 --- a/unit-testing-config-loader.js +++ b/unit-testing-config-loader.js @@ -1,8 +1,7 @@ const { join, relative } = require("path"); module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp }) { - // TODO: Consider to use the files property from karma.conf.js - const testFilesRegExp = /tests\/.*\.js/; + const testFilesRegExp = getKarmaConfig().files; const runnerFullPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner"); const runnerRelativePath = relative(appFullPath, runnerFullPath); let source = ` @@ -30,4 +29,16 @@ module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp `; return source; +} + +function getKarmaConfig() { + let result = { files: /tests\/.*\.(js|ts)/ }; + const pathToKarmaConfig = join(__dirname, "../../karma.conf.js"); + if (existsSync(pathToKarmaConfig)) { + try { + require(pathToKarmaConfig)({ set: (options) => result = options }); + } catch (err) { } + } + + return result; } \ No newline at end of file