I found several similar question but none of the suggestions fixed my issue. Basically they are suggesting add some dependency (I am using only native webcomponents so it doesn't appliy to my case) or check the path. I checked carefully and the path is 100% correct. I found a bit strange that the warnning message shows absolute before the real path. BTW, the path is really coorect.
Whole code github
Karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ["jasmine"],
files: [
"../node_modules/#webcomponents/webcomponentsjs/webcomponents-bundle.js",
{ pattern: "../test/*-test.js", type: "module", included: true }
],
exclude: [],
preprocessors: {},
reporters: ["spec"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["Chrome"],
singleRun: true,
concurrency: Infinity
});
};
console message
# npm test
> sktscanner-flight-search#0.1.0 test C:\_d\WSs\rapidapi-vanilla-webcomponents\skyscanner-webcomponents
> karma start config/karma.conf.js
06 08 2019 19:22:55.229:INFO [karma-server]: Karma v4.2.0 server started at http://0.0.0.0:9876/
06 08 2019 19:22:55.251:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
06 08 2019 19:22:55.261:INFO [launcher]: Starting browser Chrome
06 08 2019 19:22:58.972:INFO [Chrome 75.0.3770 (Windows 10.0.0)]: Connected on socket xwPc3314bVDtrBgaAAAA with id 78516319
06 08 2019 19:22:59.161:WARN [web-server]: 404: /absoluteC:/_d/WSs/rapidapi-vanilla-webcomponents/skyscanner-webcomponents/public/skyscanner-flight-search/skyscanner-flight-search.js
06 08 2019 19:22:59.165:WARN [web-server]: 404: /absoluteC:/_d/WSs/rapidapi-vanilla-webcomponents/skyscanner-webcomponents/test/test-utils.js
Chrome 75.0.3770 (Windows 10.0.0): Executed 0 of 0 ERROR (0.008 secs / 0 secs)
npm ERR! Test failed. See above for more details.
unit test
import { SkyscannerFlightSearch } from "../public/skyscanner-flight-search/skyscanner-flight-search.js";
import { TestUtils } from "./test-utils.js";
describe("simplest test", () => {
it("first try (using TestUtils)", async() => {
const { shadowRoot } = await TestUtils.render("skyscanner-flight-search");
expect(shadowRoot.querySelector("#firstdiv")).toBeTruthy();
});
});
Because Karma by default runs on port 9876, it doesn't have ability to look too deep into your project. Instead it hijacks your component and assumes everything is accessible from that port (which it is not)....
You can redirect Karma to your "real ports" using this guide
Related
I'm having an odd error logging my app into B2C using auth code flow with PKCE using the #azure/msal-angular library. I'm redirecting back to the B2C login, get redirected back to my app, my app successfully gets a token back from the token api but then a JS error is logged and prevents my app from continuing to load. Here is the console output:
[Thu, 27 Jan 2022 22:34:53 GMT] : #azure/msal-angular#2.1.0 : Info - Interceptor - 1 scopes found for endpoint
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-angular#2.1.0 : Info - Interceptor - 1 scopes found for endpoint
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-angular#2.1.0 : Info - Interceptor - 1 scopes found for endpoint
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-angular#2.1.0 : Info - Interceptor - 1 scopes found for endpoint
core.js:40853 Angular is running in the development mode. Call enableProdMode() to enable the production mode.
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-browser#2.21.0 : Info - Emitting event: msal:handleRedirectStart
core.js:40853 Angular is running in the development mode. Call enableProdMode() to enable the production mode.
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-angular#2.1.0 : Error - Interceptor - acquireTokenSilent rejected with error. Invoking interaction to resolve.
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-browser#2.21.0 : Info - Emitting event: msal:loginStart
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-angular#2.1.0 : Error - Interceptor - acquireTokenSilent rejected with error. Invoking interaction to resolve.
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-browser#2.21.0 : Info - Emitting event: msal:loginStart
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-angular#2.1.0 : Error - Interceptor - acquireTokenSilent rejected with error. Invoking interaction to resolve.
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-browser#2.21.0 : Info - Emitting event: msal:loginStart
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-angular#2.1.0 : Error - Interceptor - acquireTokenSilent rejected with error. Invoking interaction to resolve.
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-browser#2.21.0 : Info - Emitting event: msal:loginStart
4msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-browser#2.21.0 : Info - Emitting event: msal:loginFailure
4core.js:6241 ERROR Error: Uncaught (in promise): BrowserAuthError: interaction_in_progress: Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API. For more visit: aka.ms/msaljs/browser-errors.
BrowserAuthError: interaction_in_progress: Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API. For more visit: aka.ms/msaljs/browser-errors.
at BrowserAuthError.AuthError [as constructor] (AuthError.js:27:1)
at new BrowserAuthError (BrowserAuthError.js:169:1)
at Function.push.../../node_modules/#azure/msal-browser/dist/error/BrowserAuthError.js.BrowserAuthError.createInteractionInProgressError (BrowserAuthError.js:236:1)
at RedirectClient.<anonymous> (StandardInteractionClient.js:216:51)
at step (_tslib.js:75:1)
at Object.next (_tslib.js:56:45)
at _tslib.js:49:1
at new ZoneAwarePromise (zone-evergreen.js:960:1)
at __awaiter (_tslib.js:45:1)
at RedirectClient.push.../../node_modules/#azure/msal-browser/dist/interaction_client/StandardInteractionClient.js.StandardInteractionClient.preflightInteractiveRequest (StandardInteractionClient.js:207:25)
at resolvePromise (zone-evergreen.js:798:1)
at zone-evergreen.js:705:1
at zone-evergreen.js:721:1
at ZoneDelegate.invoke (zone-evergreen.js:364:1)
at Object.onInvoke (core.js:41667:1)
at ZoneDelegate.invoke (zone-evergreen.js:363:1)
at Zone.run (zone-evergreen.js:123:1)
at zone-evergreen.js:857:1
at ZoneDelegate.invokeTask (zone-evergreen.js:399:1)
at Object.onInvokeTask (core.js:41645:1)
defaultErrorLogger # core.js:6241
handleError # core.js:6294
next # core.js:42627
schedulerFn # core.js:37132
__tryOrUnsub # Subscriber.js:183
next # Subscriber.js:122
_next # Subscriber.js:72
next # Subscriber.js:49
next # Subject.js:39
emit # core.js:37092
(anonymous) # core.js:41707
invoke # zone-evergreen.js:364
run # zone-evergreen.js:123
runOutsideAngular # core.js:41501
onHandleError # core.js:41704
handleError # zone-evergreen.js:368
runGuarded # zone-evergreen.js:136
api.microtaskDrainDone # zone-evergreen.js:670
drainMicroTaskQueue # zone-evergreen.js:576
Promise.then (async)
scheduleMicroTask # zone-evergreen.js:552
scheduleTask # zone-evergreen.js:388
onScheduleTask # zone-evergreen.js:272
scheduleTask # zone-evergreen.js:378
scheduleTask # zone-evergreen.js:210
scheduleMicroTask # zone-evergreen.js:230
scheduleResolveOrReject # zone-evergreen.js:847
resolvePromise # zone-evergreen.js:785
(anonymous) # zone-evergreen.js:705
webpackJsonpCallback # bootstrap:25
(anonymous) # mcl-portal-order.js:1
capture_page_info.js:954 Gather controls: 2.934814453125 ms
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : [64b25cee-dd82-4679-8a9e-b4eb65289ff3] : #azure/msal-common#6.0.0 : Info - in acquireToken call
DevTools failed to load source map: Could not load content for chrome-extension://lkoeejijapdihgbegpljiehpnlkadljb/browser-polyfill.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
client:52 [WDS] Live Reloading enabled.
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-browser#2.21.0 : Info - Emitting event: msal:loginSuccess
msal-config.module.ts:27 [Thu, 27 Jan 2022 22:34:54 GMT] : #azure/msal-browser#2.21.0 : Info - Emitting event: msal:handleRedirectEnd
If refresh my app after this happens the app loads fine and calls all my api endpoints appropriately using the token it got. So it's just the inital process of bootstraping my app, redirecting to the login, getting redirected back to my app, posting the token request then something fails inbetween the time the token is received but before the api requests are made?
Have I configured this wrong?
my MsalConfigModule that sets up the configuration of the MsalModule:
const isIE = window.navigator.userAgent.indexOf("MSIE ") > -1 || window.navigator.userAgent.indexOf("Trident/") > -1; // Remove this line to use Angular Universal
export function loggerCallback(logLevel: LogLevel, message: string) {
console.log(message);
}
export function MSALInstanceFactory(config: ConfigService): IPublicClientApplication {
const authConf = config.getSettings()['oauthConfig'][0] as any;
const authConfig = new PublicClientApplication({
auth: {
clientId: authConf['client_id'],
authority: authConf.authority,
knownAuthorities: [authConf.authority],
redirectUri: authConf['redirect_uri'],
postLogoutRedirectUri: authConf['redirect_uri'],
navigateToLoginRequestUrl: true
},
cache:{
cacheLocation: BrowserCacheLocation.SessionStorage,
storeAuthStateInCookie: isIE
},
system: {
loggerOptions: {
loggerCallback,
logLevel: LogLevel.Info,
piiLoggingEnabled: false
}
}
});
return authConfig;
}
export function MSALInterceptorConfigFactory(config: ConfigService): MsalInterceptorConfiguration {
const resourceMap = new Map<string, Array<string>>();
// iterate over the urlMappings config and create a protectedresourcemap
const configUrls = config.getSettings()['urlMappings'] as Array<any>;
const scope = config.getSettings()['oauthConfig'][0].scope as string;
configUrls.map(urlMap => resourceMap.set(`${urlMap.url}/*`, [scope]));
return {
interactionType: InteractionType.Redirect,
protectedResourceMap: resourceMap
};
}
export function MSALGuardConfigFactory(): MsalGuardConfiguration {
return {
interactionType: InteractionType.Redirect
};
}
#NgModule({
providers: [],
imports: [MsalModule]
})
export class MsalConfigModule {
static forRoot() {
return {
ngModule: MsalConfigModule,
providers: [
{
provide: MSAL_INSTANCE,
useFactory: MSALInstanceFactory,
deps: [ConfigService]
},
{
provide: MSAL_GUARD_CONFIG,
useFactory: MSALGuardConfigFactory,
deps: [ConfigService]
},
{
provide: MSAL_INTERCEPTOR_CONFIG,
useFactory: MSALInterceptorConfigFactory,
deps: [ConfigService]
},
MsalService,
MsalGuard,
MsalBroadcastService,
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}
]
};
}
}
part of my main app module:
#NgModule({
declarations: [AppComponent],
imports: [
...
MsalConfigModule.forRoot()
],
providers: [
DatePipe,
SlicePipe
],
bootstrap: [AppComponent, MsalRedirectComponent],
})
export class AppModule {}
The solution to this was for me to add the
canActivate:[MsalGuard]
guard to all my routes. I think the underlying problem was that the interceptor was looking for a token to send in the api requests before we had a token to send. Adding the guard prevented the activation of the route until we are authenticated and then once the the route was activated my api requests would fire, the interceptors would have thier token to send along and everything just worked.
I guess the take way is that you do need to add the MsalGuard, it's not enough to provide the interceptors and configure the protected resource map.
I'm working on a project to begin testing Node/Angular applications using Protractor and Jasmine. I have a POC working in most browsers but having a lot of trouble with MS Edge. Here's my environment:
OS: Windows 10 Pro (Version 1709, OS Build 16299.98)
Edge: 41.16299.15.0
EdgeHTML: 16.16299
MS Web Driver: 10.0.16299.15
Node: 6.12.0
Protractor: 5.2.1
Jasmine: 2.8.0
Selenium: 3.8.1
When I run the tests in Chrome, Firefox, and IE (11) the behavior is fine (tests run with expected results). However, with MS Edge the process fails before the test spec can even run.
Example code/output use the Protractor tutorial but I have the same issue when working with our application.
Working conf.js (for Chrome and Firefox)
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['./spec/spec.js'],
multiCapabilities: [
{ 'browserName': 'chrome' },
{ 'browserName': 'firefox', 'marionette': true, 'firefox_binary': "C:\\Program Files\\Mozilla Firefox\\firefox.exe" }//,
]
}
Failing conf.js (for MS Edge)
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:17556',
specs: ['./spec/spec.js'],
capabilites: { browserName: 'MicrosoftEdge' }
}
spec.js
// spec.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
When I run the test for MS Edge after starting the Microsoft Web Driver the following occurs:
$ protractor conf.js
[14:14:18] I/launcher - Running 1 instances of WebDriver
[14:14:18] I/hosted - Using the selenium server at http://localhost:17556
[14:14:20] E/launcher - Error code: 135
[14:14:20] E/launcher - Error message: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:17556
[14:14:20] E/launcher - Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:17556
at ClientRequest.<anonymous> (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:238:15)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at Socket.socketErrorListener (_http_client.js:310:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
From: Task: WebDriver.createSession()
at Function.createSession (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
at Function.createSession (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\chrome.js:761:15)
at createDriver (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:170:33)
at Builder.build (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:626:16)
at Hosted.getNewDriver (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\driverProviders\driverProvider.js:53:33)
at Runner.createBrowser (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\runner.js:195:43)
at q.then.then (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\runner.js:339:29)
at _fulfilled (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
[14:14:20] E/launcher - Process exited with error code 135
The problem seems to be somewhere around that it says it is using the server on 'localhost' but then makes requests on '127.0.0.1' instead. In theory, they are the same. But in operation, only 'localhost' is responsive. If I try to access 127.0.0.1:17556 it doesn't respond.
This website could not be found
Error Code: INET_E_RESOURCE_NOT_FOUND
I've been looking around a long time (here, SQA, and, the Protactor discussions on GitHub) for info on this but have not found a resolution. Some discussion on GitHub indicates MS Edge testing with Protractor was working at one point. Has anyone been able to successfully run Protractor tests with this version of MS Edge and MS Webdriver?
One final bit of info: I have access to another Windows 10 machine that has an older version of Edge (10240). On that machine I don't have this problem (localhost vs 127.0.0.1), but, it is old enough to still have issues with async and I'm not able to use it for testing with Protractor.
Thanks!
UPDATE
The spec file has not changed but I have updated the config file (conf.js):
// conf.js
exports.config = {
directConnect: false,
framework: 'jasmine',
specs: ['./spec/spec.js'],
seleniumAddress: 'http://localhost:4444/wd/hub',
multiCapabilities: [
//{ 'browserName': 'chrome' },
//{ 'browserName': 'firefox', 'marionette': true, 'firefox_binary': "C:\\Program Files\\Mozilla Firefox\\firefox.exe" },
{ 'browserName': 'MicrosoftEdge' }
]
};
When enabled Chrome and Firefox are able to run the test.
Edge fails with the following (timeout waiting for driver server to start):
$ protractor conf.js
[13:13:53] I/launcher - Running 1 instances of WebDriver
[13:13:53] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[13:14:13] E/launcher - Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'QA-01', ip: '10.1.1.80', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9.0.1'
Driver info: driver.version: unknown
[13:14:13] E/launcher - WebDriverError: Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'QA-01', ip: '10.1.1.80', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9.0.1'
Driver info: driver.version: unknown
at WebDriverError (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:27:5)
at Object.checkLegacyResponse (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:441:30)
at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebDriver.createSession()
at Function.createSession (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
at createDriver (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:170:33)
at Builder.build (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:635:14)
at Hosted.getNewDriver (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\driverProviders\driverProvider.js:53:33)
at Runner.createBrowser (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\runner.js:195:43)
at q.then.then (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\built\runner.js:339:29)
at _fulfilled (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
at C:\Users\USER.NAME\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49
[13:14:13] E/launcher - Process exited with error code 199
As before - the same setup on an older version of Windows 10, Edge (10240), and, the Edge Driver do try to run the tests (albeit with the async execution issue).
This setup is probably better than what I used before but the overall outcome is the same. Protractor tests (on this machine) aren't running in MS Edge (16299).
Any insight or advice is much appreciated.
Thanks!
From what I can gather you need to tell protractor where to find the Edge driver. I found a few blog posts that mention adding seleniumArgs to the config.
seleniumArgs: ['-Dwebdriver.edge.driver=your/path/to/MicrosoftWebDriver.exe']
After additional time and working with yet another Windows 10 machine I have successfully gotten this simple test to run.
I can only conclude that there was something on that particular machine preventing proper execution of the test. I wasn't able to figure out what that was, but, the "does it work?" question is answered. It does (which is what one would expect).
conf.js:
// conf.js
exports.config = {
directConnect: false,
framework: 'jasmine',
specs: ['./spec/spec.js'],
seleniumAddress: 'http://localhost:4444/wd/hub',
multiCapabilities: [
{ 'browserName': 'chrome' },
{ 'browserName': 'firefox', 'marionette': true },
{ 'browserName': 'MicrosoftEdge' }
]
};
spec.js:
// spec.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
Results:
[10:07:15] I/launcher - 0 instance(s) of WebDriver still running
[10:07:15] I/launcher - chrome #01 passed
[10:07:15] I/launcher - MicrosoftEdge #21 passed
[10:07:15] I/launcher - firefox #11 passed
I am having issues testing my NW.js app using Karma. Tests that used to work now don't after updating ??? (I'm not sure which update killed me)
START:
13 07 2016 08:33:30.517:INFO [karma]: Karma v1.1.1 server started at http://localhost:9876/
13 07 2016 08:33:30.519:INFO [launcher]: Launching browser NodeWebkitTest with unlimited concurrency
13 07 2016 08:33:30.531:INFO [launcher]: Starting browser node-webkit
13 07 2016 08:33:36.221:INFO [Chrome 41.0.2272 (Windows 7 0.0.0)]: Connected on socket /#6fJGXLlwDNlOGXukAAAA with id 21855637
Chrome 41.0.2272 (Windows 7 0.0.0) ERROR
Uncaught TypeError: Cannot read property 'setup' of undefined
at C:/Users/ethomps2/IdeaProjects/evidentia3/node_modules/karma-mocha/lib/adapter.js:209
Finished in 0.331 secs / 0 secs
At the point in the adapter where it is failing, the adapter is looking for window.mocha.
Here is my karma config:
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai', 'sinon'],
'plugins': [
'karma-nodewebkit-launcher',
'karma-mocha',
'karma-chai',
'karma-sinon',
'karma-coverage',
'karma-mocha-reporter'
],
// list of files / patterns to load in the browser
files: [
<my code including test files>
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'../build/js/controllers/*.js': ['coverage'],
'../build/js/services/*.js': ['coverage'],
'../build/js/filters/*.js': ['coverage'],
'../build/js/directives/*.js': ['coverage']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'coverage'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['NodeWebkitTest'],
customLaunchers: {
'NodeWebkitTest': {
base: 'NodeWebkit',
paths: ['node_modules'],
options: {
"name": "Evidentia",
"main": "index.html",
"description": "Evidence management software for your genealogy research",
"version": "3.0.0",
"ver": "300",
"webkit": {
"page-cache": false
},
"window": {
"title": "Evidentia",
"icon": "img/Evidentia128x128.png",
"toolbar": true,
"frame": true,
"width": 1100,
"height": 700,
"show": false
}
}
}
},
// optionally, configure the reporter
coverageReporter: {
type: 'html',
dir: '../coverage/',
instrumenterOptions: {
istanbul: {noCompact: true}
}
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
})
};
As you can see I am using karma-nodewebkit-launcher as my browser. My understanding was that nwjs global got linked to the window.
Use karma-nodewebkit-mocha in your project.
See https://github.com/karma-runner/karma-mocha/issues/184 for more details.
I ran a simple karma init and pressed enter throughout the process to get the following karma.conf.js:
// Karma configuration
// Generated on Thu Jan 21 2016 10:32:15 GMT-0600 (CST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'**/*.spec.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
However, after trying to run a simple test that looks like:
describe('test', function() {
it('should return true', function() {
expect(true).toEqual('true');
})
});
While it runs, I get the following output:
1 01 2016 10:32:47.879:WARN [karma]: No captured browser, open http://localhost:9876/
21 01 2016 10:32:47.888:INFO [karma]: Karma v0.13.19 server started at http://localhost:9876/
21 01 2016 10:32:47.892:INFO [launcher]: Starting browser Chrome
21 01 2016 10:32:50.192:INFO [Chrome 47.0.2526 (Mac OS X 10.11.3)]: Connected on socket /#RpTiNDwYyXuP29hTAAAA with id 21512010
Chrome 47.0.2526 (Mac OS X 10.11.3) ERROR
Uncaught ReferenceError: require is not defined
at /Users/sgarcia/dev/karma/hello-karma/node_modules/karma-chrome-launcher/test/jsflags.spec.js:1
Why does it say it can't find requireJS despite me not using it?
The problem is your list of files:
files: [
'**/*.spec.js'
],
That will catch ALL your *.spec.js files, which is why it found "/Users/sgarcia/dev/karma/hello-karma/node_modules/karma-chrome-launcher/test/jsflags.spec.js" which is a test for the developers of karma-chrome-launcher itself, which does indeed have a call to requireJS, and which you probably don't want to include in your test suite :-)
Consider place all your test files in ./test and changing you karma.conf.js files section to something like:
files: [
'js/**/*.js',
'tests/**/*.spec.js'
],
I'm using the following grunt tasks
grunt-sass
grunt-contrib-watch
grunt-autoprefix
node-bourbon
(there are a few other tasks, such as uglify, spritesmith, and haml, which i have left out of this example)
My grunt file looks like this:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
options: {
sourceMap: true,
outputStyle: 'compressed',
imagePath: 'assets/css/img',
includePaths: require('node-bourbon').includePaths
},
dist: {
files: {
'assets/css/app.css': 'assets/sass/app.scss'
}
}
},
autoprefixer: {
options: {
browsers: ['last 2 version', 'ie 8', 'ie 9'],
silent : false
},
dev: {
src: 'assets/css/app.css',
dest: 'assets/css/post.css'
},
},
watch: {
options: {
livereload: true
},
sass: {
files: ['assets/sass/**/*.scss', 'assets/sass/*.scss'],
tasks: ['sass:dist', 'autoprefixer:dev']
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.registerTask('default', ['watch', 'sass']);
};
This is working. However, if there is an error in my sass file nothing is reported. For instance if I try and use an $variable that doesn't exist, no errors are reported in my terminal
Here are two subsequent logs, the first compiles successfully with no errors. The second doesn't compile (as there is an undefined variable in the scss file)
Completed in 1.712s at Sun Sep 28 2014 15:23:17 GMT+0100 (GMT Daylight Time) - Waiting...
>> File "assets\sass\app.scss" changed.
Running "sass:dist" (sass) task
File assets/css/app.css created.
File assets/css/app.css.map created.
Running "autoprefixer:dev" (autoprefixer) task
File assets/css/post.css created.
Done, without errors.
C:\wamp\www\_bp2>grunt
Running "watch" task
Waiting...
>> File "assets\sass\app.scss" changed.
Running "sass:dist" (sass) task
Completed in 1.656s at Sun Sep 28 2014 15:29:25 GMT+0100 (GMT Daylight Time) - Waiting...
Does anyone know why no errors are being logged?
I'm in the process of rebuilding my sass boilerplate to use libsass and bourbon instead of compass. So I'm expecting to come across loads of errors during the process, so I really need to know what these errors are.
Thanks