Nesting Angular component files into one in Visual Studio - visual-studio-2017

Which setting in Visual Studio 2017 allows for bundling Angular component files into one file?
In the image below the files in the red square should be visually presented as one that then can be expanded.
Names of the files are:
navmenu.component.css
navmenu.component.html
navmenu.component.ts
They only differ by extension. The html file should be the main one with ts and css being presented as sub files.
It was working fine until I updated Visual Studio 2017 to version 15.3.3 (before it was 15.1).

I finally found a solution to that issue on that thread. It requires editing the toolSettings.json file.
It requires editing toolSettings.json, located in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Web Tools\ProjectSystem
The following entries need to be added
".ts": [
".html"
],
under extensionToExtension.
And ".html" in the "css" array.
The whole file looks like that:
{
"dependentFileProviders": {
"addedExtension": {},
"pathSegment": {
"*": [
".js",
".css",
".html",
".htm",
".less",
".scss",
".coffee",
".iced",
".config",
".cs",
".vb",
".json"
]
},
"extensionToExtension": {
".js": [
".coffee",
".iced",
".ts",
".tsx",
".jsx"
],
".ts": [
".html"
],
".css": [
".less",
".scss",
".sass",
".styl",
".html"
],
".html": [
".md",
".mdown",
".markdown",
".mdwn",
],
".map": [
".js",
".css"
],
".svgz": [
".svg"
],
".designer.cs": [
".resx"
],
".cs.d.ts": [
".cs"
]
},
"fileToFile": {
".bowerrc": [
"bower.json"
],
".npmrc": [
"package.json"
],
"npm-shrinkwrap.json": [
"package.json"
],
"yarn.lock": [
"package.json"
],
".yarnclean": [
"package.json"
],
".yarnignore": [
"package.json"
],
".yarn-integrity": [
"package.json"
],
".yarnrc": [
"package.json"
]
},
"filePartToExtension": {
"-vsdoc.js": [
".js"
]
},
"allExtensions": {
"*": [
".tt"
]
}
}
}

The accepted answer got me on the right track, but I have a couple of improvements to contribute:
First, rather than editing the Visual Studio default rules, I would recommend creating your own nesting rules. You can either create one just for your personal use, or create a .filenesting.json file in your Project or Solution folder so your teammates get the same experience by default.
Second, since in Angular it's the typescript that defines the component and sometimes references HTML, CSS, etc., for me it makes more sense to reverse the relationship.
Here's the .filenesting.json file I ended up using for our web app project, in case it's useful as a minimalist starting point for other Angular and Visual Studio users.
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"root": true,
"dependentFileProviders": {
"add": {
"addedExtension": {},
"pathSegment": {
"add": {
".spec.ts": [
".ts"
]
}
},
"extensionToExtension": {
"add": {
".html": [
".ts"
],
".scss": [
".ts"
]
}
}
}
}
}

Related

Chutzpah and Jasmine typescript unit testing

I am trying to get Chutzpah and Jasmine working together in visual studio, my end goal is to get unit tests running with TeamCity integration.
On save, all of the typescript code generates a single .js file. This also causes Chutzpah to run my tests, so far so good.
My issue is Chutzpah reports 0 passed, 0 failed and 0 errors. The Jasmine html file that is generated lists out all of my tests correctly but Chutzpa doesn't seem to receive any information back from Jasmine.
Highlights of a trace log:
Trying to build test context for c:\.....\test.ts
Building test context for c:\.....\test.ts
...framework dependencies / other ok looking things... (~15 lines)
Finished building test context for c:\.....\test.ts
Warning: 0 : Message:Chutzpah determined generated .js files are missing but the compile
mode is External so Chutzpah can't compile them. Test results may be wrong.
Then it starts Phantom js and logs loading / receiving resources. My test.ts file is not one of the recources listed but the site-wide .js is (I checked the site-wide file and my tests are being appended to it).
Finished test run for c:\......\test.ts in Discovery mode
Cleaning up test context for c:\......\test.ts
Chutzpah run finished with 0 passed, 0 failed and 0 errors
Chutzpah.json file cache cleared
End Test Adapter Discover Tests
chutzpah.json
{
"Framework": "jasmine",
"EnableTestFileBatching": true,
"Compile": {
"Mode": "External",
"Extensions": [ ".ts" ],
"ExtensionsWithNoOutput": [ ".d.ts" ],
"Paths": [
{
"OutputPath": "../SiteWide.js",
"SourcePath": "Views"
}
]
},
"References": [
{
"Path": "../knockout-3.4.2.js",
"IsTestFrameworkFile": true
}
],
"Tests": [
{
"Includes": [ "*.ts" ],
"Path": "../Tests/Views"
}
],
"EnableTracing": true,
"TraceFilePath": "./trace.log"
}
tests.ts
describe('configuring unit tests for typescript!', () => {
it('this should pass', () => {
expect(1).toBe(1);
});
it('this should fail', () => {
expect(1).toBe(0);
});
});
There are a few things I'm suspicious of (the missing .js files line from the trace - but that might just be caused by my single js file compilation step?)
Maybe I'm missing references to jasmine in my chutzpah.json?
I'm at a loss for why the Jasmine tests work, but Chutzpah doesn't report back.
Maybe late...
But something like this in chutzpah.json would help.
{
"Framework": "jasmine",
"Compile": {
"Mode": "External",
"Extensions": [ "*.ts" ],
"ExtensionsWithNoOutput": [ "*.d.ts" ]
},
"References": [
{ "Path": "node_modules/promise-polyfill/dist", "Include": "*.js", "Exclude": "*.d.ts" },
{ "Path": "node_modules/systemjs/dist", "Include": "*.js", "Exclude": "*.d.ts" }
],
"Tests": [
{ "Path": "unittests", "Includes": [ "*.spec.ts" ], "Excludes": [ "*.d.ts" ], "ExpandReferenceComments": "true" }
]
}
Having your system related files is important in the references. Also you can try "*.spec.js" in the Tests section

Grok parse error when using custom pattern definitions

I'm trying to use a grok filter in logstash version 1.5.0 to parse several fields of data from a log file.
I'm able to parse a simple WORD field with no issues, but when I try to define a custom pattern and add that in as well, the grok parse fails.
I've tried using a couple of grok debuggers which have been recommended elsewhere to find an issue:
http://grokconstructor.appspot.com/do/match
and
http://grokdebug.herokuapp.com/
both say that my regex should be fine, and return the fields that I want, but when I add it to my logstash.conf, grok fails to parse the log line and simply passes through the raw data to elasticsearch.
My sample line is as follows:
APPERR [2015/06/10 11:28:56.602] C1P1405 S39 (VPTestSlave002_001)| 8000B Connect to CGDialler DB (VPTest - START)| {39/A612-89A0-A598/60B9-1917-B094/9E98F46E} Failed to get DB connection: SQLConnect failed. 08001 (17) [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
My logstash.conf grok config looks like this:
grok
{
patterns_dir => ["D:\rt\Logstash-1.5.0\bin\patterns"]
match => {"message" => "%{WORD:LogLevel} \[%{KERNELTIMESTAMP:TimeStamp}\]"}
}
and the contents of my custom pattern file are:
KERNELTIMESTAMP %{YEAR}/%{MONTHNUM}/%{MONTHDAY} %{HOUR}:?%{MINUTE}(?::?%{SECOND})?%{ISO8601_TIMEZONE}?
I am expecting this to return the following set of data:
{
"LogLevel": [
[
"APPERR"
]
],
"TimeStamp": [
[
"2015/06/10 11:28:56.602"
]
],
"YEAR": [
[
"2015"
]
],
"MONTHNUM": [
[
"06"
]
],
"MONTHDAY": [
[
"10"
]
],
"HOUR": [
[
"11",
null
]
],
"MINUTE": [
[
"28",
null
]
],
"SECOND": [
[
"56.602"
]
],
"ISO8601_TIMEZONE": [
[
null
]
]
}
Can anyone tell me where my issue is?

Chaining grok filter patterns for logstash

I am trying to configure logstash to manage my various log sources, one of which is Mongrel2. The format used by Mongrel2 is tnetstring, where a log message will take the form
86:9:localhost,12:192.168.33.1,5:57089#10:1411396297#3:GET,1:/,8:HTTP/1.1,3:200#6:145978#]
I want to write my own grok patterns to extract certain fields from the above format. I received help on this question trying to extract the host. So if in grok-patterns I define
M2HOST ^(?:[^:]*\:){2}(?<hostname>[^,]*)
and then in the logstash conf specify
filter {
grok {
match => [ "message", "%{M2HOST}" ]
}
}
it works as expected. The problem I now have is I want to specify multiple patterns e.g. M2HOST, M2ADDR etc. I tried defining additional ones in the same grok-patterns file
M2HOST ^(?:[^:]*\:){2}(?<hostname>[^,]*)
M2ADDR ^(?:[^:]*\:){3}(?<address>[^,]*)
and changing the logstash conf
filter {
grok {
match => [ "message", "%{M2HOST} %{M2ADDR}" ]
}
}
but now I just get the error _grokparsefailure.
with your sample input from other question and with some guessing about the values names the full match would be:
(?:[^:]*:){2}(?<hostname>[^,]*)[^:]*:(?<address>[^,]*)[^:]*:(?<pid>[^#]*)[^:]*:(?<time>[^#]*)[^:]*:(?<method>[^,]*)[^:]*:(?<query>[^,]*)[^:]*:(?<protocol>[^,]*)[^:]*:(?<code>[^#]*)[^:]*:(?<bytes>[^#]*).*
Producing:
{
"hostname": [
[
"localhost"
]
],
"address": [
[
"192.168.33.1"
]
],
"pid": [
[
"57089"
]
],
"time": [
[
"1411396297"
]
],
"method": [
[
"GET"
]
],
"query": [
[
"/"
]
],
"protocol": [
[
"HTTP/1.1"
]
],
"code": [
[
"200"
]
],
"bytes": [
[
"145978"
]
]
}

Code Coverage with chutzpah resulting in timeout error

I am using Chutzpah Version 3.2.3 with Typescript and nUnit.
I am able to successfully run the unit tests. But when i do cod coverage for the same unit tests i get
Error: Timeout occurred when executing test file
I have no clue where to even start looking to fix it. I have been banging my head about this issue for a day now, Any leads are highly appreciated.
Below is my chutzpah.json
{
"Framework": "qunit",
"TestHarnessLocationMode": "Custom",
"TestHarnessDirectory": "../example.exampleTest.Client.Excel.Web/App",
"Compile": {
"Mode": "External",
"Extensions": [ ".ts" ],
"ExtensionsWithNoOutput": [ ".d.ts" ],
"SourceDirectory": "../../Example.exampleTest/",
"OutDirectory": "../../Example.exampleTest/"
}
}
I was able to resolve the issue by being specific about which files to include in code coverage and which files to exclude. Below is my updated chutzpah.json
{
"Framework": "qunit",
"EnableCodeCoverage ": "true",
"CodeCoverageIncludes": [
"*Orchestrator*",
"*Transformer*",
"*Processor*"
],
"CodeCoverageExcludes": [
"*\\Example.Example.Client.Excel.Web\\App\\Workstreams\\AX-AX\\*",
"*\\Example.Example.Client.Excel.Web\\App\\Workstreams\\CS\\v1.0\\CS-ICS\\*",
"*\\Example.Example.Client.Excel.Web\\App\\Workstreams\\CAD-CAD\\*",
"*\\Example.Example.Client.Excel.Web\\App\\AddInModules\\*",
"*\\Example.Example.Client.Excel.Web\\Scripts\\*",
"*\\Example.Example.Client.Excel.Web\\Mocks\\*"
],
"TestFileTimeout":"200000",
"Compile": {
"Mode": "External",
"Extensions": [ ".ts" ],
"ExtensionsWithNoOutput": [ ".d.ts" ],
"SourceDirectory": "../../Example.Example/",
"OutDirectory": "../../Example.Example/"
}
}

using c++11 with GYP project

I am trying to create a simple cross platform C++ project with gyp. Currently I'm just trying this on a mac - but would like to get it to build for windows, Linux, ios and android eventually.
HEre is the simple gyp file that I'm using.
I would like to be able to use ninja as well as xcode/msvc projects from this gyp.
I know that I need to be able to add
-std=c++11 and -libstdc++ to the commandline for clang, but right now I only see the generated build files using g++ instead of clang.
This is my gyp file.
{
'targets': [
{
'target_name': 'libtest',
'product_name': 'test',
'type': 'static_library',
'sources': [
'./src/lib.cpp',
],
'include_dirs': [
'include',
],
},
{
'target_name': 'testapp',
'type': 'executable',
'sources': [
'./test/test.cpp',
],
'include_dirs': [
'src',
],
'dependencies': [
'libtest'
],
},
],
}
I've sort of figured out this to a certain extent. At lesast I got it working on the mac for a makefile build ( not ninja which was my original hope).
First I had to get gyp to use clang instead of g++ , to do this I had to add a make_global_settings to the gyp file as so. This doesn't seem like a good plan for a crossplatform build. I was also able to set these with environment variables, I'm guessing I can probably do something with conditions to make this specific to the mac.
'make_global_settings': [
['CXX','/usr/bin/clang++'],
['LINK','/usr/bin/clang++'],
],
'targets':
[
......
The other thing I had to do was add an xcode_settings dictionary with OTHER_CPLUSPLUSFLAGS and OTHER_LDFLAGS depending on the target type. Full example below.
{
'make_global_settings': [
['CXX','/usr/bin/clang++'],
['LINK','/usr/bin/clang++'],
],
'targets': [
{
'target_name': 'mylib',
'product_name': 'mylib',
'type': 'static_library',
'sources': [
'src/implementation.cc',
],
'include_dirs': [
'include',
],
'conditions': [
[ 'OS=="mac"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS' : ['-stdlib=libc++'],
},
}],
],
},
{
'target_name': 'myapp',
'type': 'executable',
'sources': [
'./bin/myapp.cc',
],
'conditions': [
[ 'OS=="mac"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11','-stdlib=libc++'],
'OTHER_LDFLAGS': ['-stdlib=libc++'],
},
}],
],
'include_dirs': [
'include',
],
'dependencies': [
'mylib'
],
},
],
}
So I just tried this on the clang++ 6 OSX 10.10 and I ran into the same problem that drewish hit.
Adding -mmacosx-version-min=10.7 to the OTHER_CPLUSPLUSFLAGS and OTHER_LDFLAGS arrays fixed the issue.
EDIT
An even better way that I found to fix this is to add "MACOSX_DEPLOYMENT_TARGET": "10.7" into the xcode_settings array. This will override any defaults that Node sets in its common.gypi file.
So it should look something like this
{
'targets': [
{
'target_name': 'myApp',
'sources': [ 'myApp.cc' ]
'conditions': [
['OS=="mac"', {
'xcode_settings': {
'MACOSX_DEPLOYMENT_TARGET': '10.7'
}
}]
]
}
]
}
johnhaley81's solution is really the simplest one to get this working (at least on OSX), however I had to add a few more settings:
"conditions": [
[ 'OS=="mac"', {
"xcode_settings": {
'MACOSX_DEPLOYMENT_TARGET': '10.9',
"CLANG_CXX_LIBRARY": "libc++",
"GCC_ENABLE_CPP_RTTI": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
},
}],
],
As you can see, you can directly use the name/value pairs from an XCode project here. Pretty handy.
The previous answers were helpful, but all that must actually be added to xcode_settings are 'MACOSX_DEPLOYMENT_TARGET': '10.7' and 'CLANG_CXX_LIBRARY': 'libc++'
{
'targets': [
{
'target_name': 'myApp',
'sources': [ 'myApp.cc' ]
'conditions': [
['OS=="mac"', {
'xcode_settings': {
'MACOSX_DEPLOYMENT_TARGET': '10.7',
'CLANG_CXX_LIBRARY': 'libc++'
}
}]
]
}
]
}
Specifically, the option 'CLANG_CXX_LIBRARY': 'libc++' is what's getting us what we want. If you add this option without 'MACOSX_DEPLOYMENT_TARGET': '10.7' then you might see the following error:
clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
This error indicates that 10.7 is a more appropriate value than 10.9 for MACOSX_DEPLOYMENT_TARGET if you're interested in compatibility.