karma config fails to add external project or file in the current project - unit-testing

I have added unit tests in some frontend projects using karma. I have multiple projects in my Git folder. If I run them individually, they work fine. However if there is a dependency of one project in another project it fails to include it. (failed to load JavaScript resource:)
If I run the tests using the html file directly, it runs the tests normally and even loads the external projects without any error. following are my resource roots in my unitTest.qunit.html file:
data-sap-ui-resourceroots='{
"x.y.projectmain": "../../",
"test.unit": "./",
"x.y.project2": "../../../../project2/WebContent"
}'
If I try to include the project same way in my Karma.conf.js it gives an error:
"Failed to resolve dependencies of 'x/y/projectmain/test/unit/AllTests.js' -> 'x/y/projectmain/test/unit/myUnitTest.js' -> 'x.y.project2/util/myfile.js': failed to load 'x.y.project2/util/myfile.js' from ./../../project2/WebContent/util/myfile.js: script load error"
Following are some of my Karma.conf.js settings:
ui5: {
type: "library",
paths: {
src: "projectmain/WebContent",
test: "projectmain/WebContent/test"
},
url: "https://openui5.hana.ondemand.com",
mode: "script",
config: {
async: true,
bindingSyntax: "complex",
compatVersion: "edge",
resourceRoots: {
"x.y.projectmain": "./base/projectmain/WebContent",
// "x.y.project2": path.resolve('../project2/WebContent')
"x.y.project2": "./../../projet2/WebContent"
// "x.y.project2": "./base/projectmain/WebContent/test/resources/project2/WebContent"
// "x.y.project2.util": "./base/project2/WebContent/util"
}
}
,
tests: [
"x.y.projectmain/test/unit/AllTests"
]
},
files: [
'Utils.js',
{ pattern: "../public/Project2/WebContent/utils/myfile.js", included: false, served: true, watched: false, nocache: true },
{ pattern: '../Project2/WebContent/**/*', watched: true, served: true, included: false }
],
// proxies: {
// '/project2/': path.resolve('../../project2/WebContent')
// },
proxies: {
'/x.y.project2/': '/absolute/' + path.resolve('../project2/WebContent'),
'/myfile.js/': '../public/project2/WebContent/util/myfile.js'
},

I have tried many things here. It even refers to the exact file in that external project but it just cant load the file. If I try to load the file manually in the browser it opens fine. But with Karma it gives an error.
My ultimate goal is to add one project as a dependency inside another project. I did check it by copying the whole WebContent folder from Project 2 inside the 'ProjectMain/WebContent/test/Resources/' directory It does work, but that's not appropriate way to include it.
There must be some way where we can register or include one project in another either as a resource root or proxies.

Related

Make ng serve on Angular 12 loads environment.ts instead of environment.prod.ts?

I read that Angular 12 changed some default configurations.
Now I'm not able to load environment.ts when starting the app with ng serve; environment.prod.ts is called instead.
I tried to load environment.ts typing ng serve --configuration=development, but environment.prod.ts is called again.
I edited the development property of angular.json this way, by adding the fileReplacements property and it works, but this seems a workaround to me and not the right solution:
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true,
"fileReplacements": [
{
"replace": "src/environments/environment.prod.ts",
"with": "src/environments/environment.ts"
}
]
}
Is there a better solution to start a development environment when running ng serve?

Expo/Metro/Minify: how to exclude specific variable names from getting mangled?

I'm using Expo managed workflow.
Is there a way to exclude certain variable names from being mangled when Expo bundles and minifies my app in production mode?
I tried adding the following “reserved” array to the miniferConfig, but it had no effect:
path: node_modules/metro-config/src/defaults/index.js
...
minifierConfig: {
mangle: {
toplevel: false,
reserved: [“myVariableName”]
},
...
Thanks

how to configure angular to work remotely with django APIs?

I am running a web application, front-end with angular and back-end with django. the thing is: These two frameworks are not running on the same server. how can I configure angular to work remotely with APIs? (I have tested the APIs, and they are just fine)
Check setup proxy for your project from Proxying to a backend server
Basically you need to create a proxy.conf.json file and have settings like:
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
Then you can define your backend hostname, port and available APIs and other settings.
OK, after hours of debugging I finally found it.
FIRST Create a file named proxy.conf.json in /src folder and fill it with this json:
{
"/api": {
"target": "http://test.com/",
"secure": false,
"changeOrigin": true,
"logLevel": "info"
}
}
This line is ESSENTIAL:
"changeOrigin": true,
THEN Edit the angular.json file.In the projects section, find architect and append this line to optionssection:"proxyConfig":"src/proxy.conf.json". So it should look like this:
.
.
.
"options": {
"browserTarget": "some-name:build",
"proxyConfig": "src/proxy.conf.json"
},
.
.
.
NOTE1 Trailing comma is not allowed in JSON.
NOTE2 Loglevel gives you more information.
NOTE3 Thanks to Haifeng for his guide.

Is there a way to unit test localization resources in asp.net core class libarary?

I want to have a resource class library and test it in another mstest class libary.
this is my project.json in resource library : (my resx file is in Resources folder)
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.AspNetCore.Mvc.DataAnnotations": "1.0.1"
},
"buildOptions": {
"embed": {
"include": [ "Resources/PS.ModelBase.Models.Person.fa.resx" ]
}
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
and this is my test method :
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Resources;
using System.Threading.Tasks;
namespace PS.ModelBaseTest
{
[TestClass]
public class PersonTest
{
[TestMethod]
public void FullNameValidateNullFirstName()
{
ResourceManager rm = new ResourceManager(typeof(PS.ModelBase.Models.Person));
string test = rm.GetString("Fisrt Name", new System.Globalization.CultureInfo("fa-IR"));
Assert.AreEqual("Fisrt Name", test);
}
}
}
I have this error when I run the test :
Could not find any resources appropriate for the specified culture or
the neutral culture. Make sure "PS.ModelBase.Models.Person.resources"
was correctly embedded or linked into assembly "PS.ModelBase" at
compile time, or that all the satellite assemblies required are
loadable and fully signed.
what should I do ?
َUpdate :
Ok. I solved my problem by inserting resx to the Models folder (Where the Person class is in it ) and renamed resx files to class name (like Person.en.resx) .
Nothing to do with project.json :
{
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.AspNetCore.Mvc.DataAnnotations": "1.0.1"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"version": "1.0.0-*"
}
But I faced another problem .I want to remain my resx files in Resources folder , not in Models folder! How can embed resx file to person class when is in Resources folder ?
I got the second problem. In fact the resource file and the class must be in a same domain
Using the following two resources as reference :
Github Issue: Updates to project.json schema
project.json reference
Based on project file in question, either try
"includeFiles" string/string[]
A list of file paths to include. The paths are rooted at the project folder. This list has a higher
priority than the include and exclude globbing patterns, hence a file
listed here and in the exclude globbing pattern will still be
included. Defaults to none.
"buildOptions": {
"embed": {
"includeFiles": [ "Resources/PS.ModelBase.Models.Person.fa.resx" ]
}
}
for just the one resource file, or
"include" string/string[]
A list of file globbing patterns for files
to include. The patterns are rooted at the project folder. Defaults to
none.
"buildOptions": {
"embed": {
"include": [ "Resources" ]
}
}
for the contents of the Resources folder

Sencha touch 2 SDK compress JS file

there is a way to specify in app.json, where I include js files, not to minify 1 js file, somethig like
"js": [
{
"path": "sdk/sencha-touch.js"
},
{
"path": "sdk/myjs.js",
"compress": false
},
...
"compress": false -- ofc doesn work , there is something to specify not to compress or minify that js file ?
Thanks for any help!
As fas as I found there is not why to specify not to compress, the way how I do an workaround is:
creating in "resources" folder a "js" folder and dropped my js file in that folder
Updated the app.json file (not to loose the "js" folder when we build production app) like this :
"resources": [
"resources/js",
]
Include the file in index html as a regular script