You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Karma can't find unit tests in Angular 2 project #499
I have created an Angular 2 project with unit tests. However, when I run 'npm test' I get the following result even though an example test is included with the counter component.
Can you give repro steps? For example, I just did the following:
mkdir myproject
cd myproject
yo aspnetcore-spa
npm test
... and get the expected result: Executed 2 of 2 SUCCESS
If those steps don't produce the same result on your machine, can you describe your environment in some more detail that might make it possible to reproduce the issue? Thanks!
@craigktreasure Have you confirmed that it really is an issue with Node 6? I know @Krishna-teja worked around it by installing Node 7, but maybe his Node 6 installation was just broken in some way.
If it really is an issue in Node 6, can you say what specifically about Node 6 causes the incompatibility?
@SteveSandersonMS I see the same behavior on two different Windows machines. Unfortunately, i don't know what causes the incompatibility right now. I assumed (and hoped) that the suggestion to try Node 7 meant that someone had a hint as to what it might be.
Unfortunately I don't know exactly what's causing it in 6, but I'd imagine in a minor release update within 6.x that it might be fixed. Fortunately on the dev-side using 7.x is safe enough, so whatever is happening there fixes the issue.
I tracked it down. As suspected, it's nothing to do with your Node version. It's to do with your Chrome version. Newer versions of Chrome are stricter about the MIME types on script files, and the Karma config didn't specify a MIME type for .ts files.
To fix it, add the following to your karma.conf.js:
Activity
SteveSandersonMS commentedon Dec 8, 2016
Can you give repro steps? For example, I just did the following:
... and get the expected result:
Executed 2 of 2 SUCCESSIf those steps don't produce the same result on your machine, can you describe your environment in some more detail that might make it possible to reproduce the issue? Thanks!
danoleary commentedon Dec 8, 2016
I followed those same steps, with the following options:
Framework? Angular 2 Do you want to include unit tests? Y Your project name? myprojectOS: Windows 10
npm: 4.0.3
node: v6.9.2
Are there any other details that would be helpful?
Krishna-teja commentedon Dec 25, 2016
@SteveSandersonMS I am also receiving the same error.
OS: Windows 10
npm: 3.10.9
node: v6.9.2
MarkPieszak commentedon Dec 25, 2016
Can you guys upgrade to the latest node 7.x and give it a shot by any chance? @Krishna-teja @danoleary
Also if you can, do a clean npm install as well.
Krishna-teja commentedon Dec 25, 2016
@MarkPieszak Doing a clean install and upgrading to node 7.x worked. Thanks!
MarkPieszak commentedon Dec 25, 2016
great, glad to hear it!
craigktreasure commentedon Jan 3, 2017
Is there a way to get this to work on Node 6 LTS?
SteveSandersonMS commentedon Jan 3, 2017
@craigktreasure Have you confirmed that it really is an issue with Node 6? I know @Krishna-teja worked around it by installing Node 7, but maybe his Node 6 installation was just broken in some way.
If it really is an issue in Node 6, can you say what specifically about Node 6 causes the incompatibility?
craigktreasure commentedon Jan 3, 2017
@SteveSandersonMS I see the same behavior on two different Windows machines. Unfortunately, i don't know what causes the incompatibility right now. I assumed (and hoped) that the suggestion to try Node 7 meant that someone had a hint as to what it might be.
MarkPieszak commentedon Jan 3, 2017
Unfortunately I don't know exactly what's causing it in 6, but I'd imagine in a minor release update within 6.x that it might be fixed. Fortunately on the dev-side using 7.x is safe enough, so whatever is happening there fixes the issue.
craigktreasure commentedon Jan 3, 2017
I'm running the latest patch release of 6 (6.9.2), so i don't believe it has been fixed. Not in a released build anyway.
SteveSandersonMS commentedon Jan 3, 2017
I tracked it down. As suspected, it's nothing to do with your Node version. It's to do with your Chrome version. Newer versions of Chrome are stricter about the MIME types on script files, and the Karma config didn't specify a MIME type for
.tsfiles.To fix it, add the following to your
karma.conf.js:... as in this commit: 8c456aa
craigktreasure commentedon Jan 3, 2017
@SteveSandersonMS Great news since i just tried it with Node 7 and it still didn't work. Thanks so much! Any insights into how you discovered this?
SteveSandersonMS commentedon Jan 3, 2017
I just opened the Chrome developer tools in the Karma window and saw a nice clear error message saying what the problem was :)
craigktreasure commentedon Jan 3, 2017
Odd. That was the first place i looked and it didn't say anything was wrong in the console or in the requests. Regardless, thanks for your help.