From 74baa4e127faa734cf3b67033aa37ef6720225c2 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 26 Jun 2019 09:59:44 +0300 Subject: [PATCH] fix: inject app.css file from unit-test-runner on test command Currently the app.css file from unit-test-runner is not included in bundle/vendor files on test command so the application remains without app.css file. The `tns-core-modules` shows an error in this situation with the in their latest next versions: ``` JS: Error: Could not load CSS from ./app.css: Error: com.tns.NativeScriptException: Failed to find module: "./app.css", relative to: app// JS: com.tns.Module.resolvePathHelper(Module.java:146) JS: com.tns.Module.resolvePath(Module.java:55) JS: com.tns.Runtime.callJSMethodNative(Native Method) JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1212) JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1092) JS: com.tns.Runtime.callJSMethod(Runtime.java:1079) JS: com.tns.Runtime.callJSMethod(Runtime.java:1059) JS: com.tns.Runtime.callJSMethod(Runtime.java:1051) JS: com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:19) JS: android.app.Activity.performCreate(Activity.java:7136) JS: android.app.Activity.performCreate(Activity.java:7127) JS: android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) JS: android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) JS: android.app.servertransac... ``` So we need to inject app.css in order to prevent this error :) --- unit-testing-config-loader.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unit-testing-config-loader.js b/unit-testing-config-loader.js index 31937c70..cc3e2315 100644 --- a/unit-testing-config-loader.js +++ b/unit-testing-config-loader.js @@ -6,10 +6,13 @@ module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp const testFilesRegExp = /tests\/.*\.(ts|js)/; const runnerFullPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner"); const runnerRelativePath = convertSlashesInPath(relative(appFullPath, runnerFullPath)); + const appCssFilePath = join(runnerRelativePath, "app.css"); let source = ` require("tns-core-modules/bundle-entry-points"); const runnerContext = require.context("${runnerRelativePath}", true, ${rootPagesRegExp}); global.registerWebpackModules(runnerContext); + global.registerModule("${appCssFilePath}", () => require("${appCssFilePath}")); + require("tns-core-modules/application").setCssFileName("${appCssFilePath}"); `; if (angular) {