I'm trying to add some unit tests to one of my projects.
So far I've installed and configured karma, and have installed jasmine. I've one test file in my test/ folder.
The karma server has started, the browser page is ready, but karma run fails as follows:
$ karma run karma-conf.js
[2014-06-14 15:19:11.046] [DEBUG] config - Loading config /foo/test/karma-conf.js
Waiting for previous execution...
Chrome 35.0.1916 (Linux) ERROR
You need to include some adapter that implements __karma__.start method!
This error message doesn't Google well.
Is this something obvious, or do I need to provide more information?
It does seem like this is a very general error, however in my case the problem was either that I didn't run karma start from the correct folder, or that I didn't restart it after changing the configuration.
I'll leave this question open and hopefully it can become a resource for others who experience this error message.
If you name your karma config file karma.conf.js, you can simply type karma start.
Otherwise specify the filename karma start karmafile.js
(I was in the right directory, but was not specifying a file name.)
You need to run your karma run or whatever function in the folder where karma-conf.js is in.
In my case I had to rename the file to karma.conf.js then do karma start
I had a problem with karma.conf.js file code format:
files: [
// Modules
,"client/bower_components/angular/angular.min.js"
,"client/bower_components/angular-mocks/angular-mocks.js"
// App
,"client/app/app.module.js"
// Test
// ,"test/**/*.spec.js"
],
The extra comma in files array have cause this error:
You need to include some adapter that implements __karma__.start method!
I was not running karma start command from the path where my karma.conf.js was. I switched to that folder and ran the same command. Thats all
I was facing this issue while running specs on the Angular.js codebase. I had to run npm install karma-jasmine -g to get this working.
If you typing "karma start", you must have a karma.conf.js file in the current folder. or just "karma start /path/karma.conf.js"
Try to create a new karmar.conf.js by "karma init /path/karma.conf.js"
In my case, I was applying by mistake the commonjs preprocessor to the karma-* modules and the adapter.js from karma-chrome and karma-firefox was broken this way.
Unfortunately, this is a very generic error.
I was getting the same error because the project was using Babel 6 and I had forgotten to add the babelrc file. Just sharing in case this could help.
In my case, the message was in fact very descriptive: I forgot to add an adapter, in my case Jasmine, into the config file. Thus:
module.exports = function(config) {
config.set({
browsers: ['Chrome'],
singleRun: true,
frameworks: ['jasmine'],
files: [
// ... files ...
],
// other configs
});
};
You need to configure your "my.conf.js" file, because it contains all the info to use to test your code.
All what you need to write is this:
The configuration file can be generated using karma init:
$ karma init my.conf.js
Which testing framework do you want to use?
Press tab to list possible options. Enter to move to the next question.
jasmine
Do you want to use Require.js?
This will add Require.js plugin.
Press tab to list possible options. Enter to move to the next question.
no
Do you want to capture a browser automatically?
Press tab to list possible options. Enter empty string to move to the next question.
Chrome
What is the location of your source and test files?
You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js".
Press Enter to move to the next question.
*.js
test/**/*.js
Should any of the files included by the previous patterns be excluded?
You can use glob patterns, eg. "**/*.swp".
Press Enter to move to the next question.
Do you want Karma to watch all the files and run the tests on change?
Press tab to list possible options.
yes
Config file generated at "/Users/vojta/Code/karma/my.conf.js".
You must specify the karma configuration file to karma.
karma start karma.config.js
It works for me
I must add that in my case karma was giving me the error because I had [square] brackets in the name of one of the parent folders.
Tt's complaining about the adapter which is probably jasmine or mocha.
Either the adapter is missing, either is not setup correctly, either it's an outdated or buggy version of the adapter.
In my case I had an old version of mocha 2.5.3 which was not compatible with karma 1+.
I updated the mocha dependency to the latest version available 3.2.0 and the problem solved.
While working on numerous vaguely described errors, I tried setting basePath: '../', After correcting other errors (like missing commas that were described as object content errors) the last change back to basePath: '', got karma to work. karma's error statements need a lot of work. It is not simple to get it going.
I had the same issue. My browser would open but on my terminal it threw the following error
30 08 2017 11:19:28.272:INFO [Chrome 58.0.3029 (Linux 0.0.0)]: Connected `enter code here`on socket 5sSs6E5KmpUVRp6LAAAB with id 93886631
Chrome 58.0.3029 (Linux 0.0.0) ERRORSome of your tests did a full page reload!
I checked my karma.conf.js file. In the framework array , i had included jasmine and requirejs. But i had only installed karma-jasmine.Removing requireJS and rerunning the karma start worked!
I've been struggling with this too. What I came up to is that this error occurs because one of the following reasons
No test adapter installed or defined (frameworks property in karma.conf.js
No karma configuration found (ie, no karma.conf.js in current dir or no config file specified in command)
My problem was that my config file was named karma.config.js instead of karma.conf.js.
If you've installed the test adapter but it still doesn't work, try running karma init and go through the guided config setup.
You will have to specify the directory of karma.config.js when you run start karma.
Try
karma start karma.config.js
I had a bad 'files' configuration in my karma.conf.js
files: ['**/*.js'],
this caught up all the files in node_modules/ including those of the karma-jasmine plugin, as it was seen as sourde files it wasn't loaded on startup. Changing to
files: [
'src/*.js',
'spec/*.js'
],
solved the problem in my case
FWIW - sourcing the file path of karma.conf.js worked for me locally, but not on my jenkins builder. I have zero clue why this is the case, but on jenkins it was throwing this error unless the karma.conf.js file was in the root directory where the karma command was given. I'm using rails and running the js specs through a rake task. Code is below which might be helpful for some.
https://gist.github.com/daino3/a39486ff8bfc1668e923
The issue in my case was that karma didn't pick up any files. Fixing it in karma.conf.js solved the issue.
Same issue happened to me, and it was due to an outdated module.
Running npm update solved it.
In my case, it was not karma-related at all! I run karma from gulp, with ES6/babel, and there was actually a code syntax error, flagged by a babel error above my karma:
ERROR [preprocessor.babel]: xxx.js: Unexpected token (19:83)
I fixed that in my src and karma was happy again.
In my case, the configuration file name was different. So, running the command specifying the conf file solved my issue.
>> karma start unit-tests.conf.js
No captured browser, open http://localhost:9876/
...
And for 'PhantomJS', opening the link specified(localhost:9876) in the browser executes the test cases.
Hope it helps. :)
EDIT 1: My Karma Config File
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: [
'./node_modules/angular/angular.js',
'./node_modules/angular-ui-router/release/angular-ui-router.js',
'./node_modules/angular-mocks/angular-mocks.js',
'./app/services/users/users.js',
'./app/app.js',
'./app/services/users/users.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: ['spec'],
// 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
})
}
I received this error because I required the same dependency twice!
Removing the duplicate file dependency removed the error for me. Circled in blue below.
Given this is the first result on google for this error message, I figured I'd mention my resolution here.
I was getting this error after converting an AngularJS 1.8 project to Typescript and trying to change over my Karma tests to use the typescript preprocessor.
I finally realized that adding import angular from 'angular' resolved the issue on Karma's side, but then angular turned up as undefined in webpack's build.
Eventually thanks to this answer on a question about that error message, I updated my import statements to import * as angular from 'angular', and finally it worked! (Ultimately I had to resolve every compilation error on every typescript file for complete resolution, which I had been somewhat ignoring since the webpack build worked.)
Hopefully this can help someone with this problem!
I had the same problem but above mentioned solutions didn't work for me. What I eventually found out is that my karmaWebpackConfig was using "babel-loader" as loader. I just removed that line and it worked for me.
Related
I'm trying to add functionality to the serviceworker that create-react-app provides out of the box. Thankfully, cra-append-sw lets me do that without needing to eject from cra.
However, when installing cra-append-sw, npm gives me a warning that #babel/polyfill#7.4.4 has been deprecated (#babel/polyfill is listed as a cra-append-sw dependency):
As of Babel 7.4.0, this package has been deprecated in favor of directly including core-js/stable (to polyfill ECMAScript features) and regenerator-runtime/runtime (needed to use transpiled generator functions):
import "core-js/stable";
import "regenerator-runtime/runtime";
Then, when I try to npm run build to append a custom service worker, the build spits out a long error message, the top of which is:
ERROR in multi ./custom-sw.js
Module not found: Error: Can't resolve './custom-sw.js' in '/Users/michaelmersiades/workspace/vanilla-cra'
resolve './custom-sw.js' in '/Users/--/workspace/vanilla-cra'
using description file: /Users/--/workspace/vanilla-cra/package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
and custom-sw.js is not showing up in the build folder.
Is this fixable? If so, how? Or is this an issue for the good ira-append-sw folk?
My thanks in advance to anyone who can help.
Silly error. The custom-sw.js file was inside /src, but it needed to be in / (the root folder).
Moving it to / solved the problem.
I am trying to deploying my website on Netlify from my GitHub.
However I am stuck to the following error:
11:37:19 AM: failed during stage 'deploying site': Invalid filename 'node_modules/es5-ext/date/#/format.js'. Deployed filenames cannot contain # or ? characters
I tried to delete and upgrade the module es5-ext but the error persists.
I don't know if i'm too late to this but I just ran into this issues
here's what I did which fixed my issues
base directory : yourApps
build command : CI= npm run build
publish directory : yourApps/build
I used craco in my react apps because I needed it to work with Tailwind css , I don't know if this will work for you , but that solution worked for me
My first answer is a question: Why are you deploying your node_modules folder? That is generally not needed on static websites: they're used to build the site, but then not needed at runtime, since, well, "runtime" is just "send this file" not "run this code" on the Netlify CDN server. Perhaps you've set your "publish directory" wrong in the site's build & deploy settings and are deploying your source code too, rather than just the finished build?
In case you do for some reason need to deploy node_modules for some reason, you can in general do so. The message is quite clear - don't send filenames with # or ? in them. Those are not valid filenames per the HTTP spec - # is for designating anchors, and everything after the # is used client-side and thus won't map correctly to your file. ? is for denoting query string parameters and similarly won't work as you're intending to read the file whose name contains ? but rather cutting off the filename that the server will (attempt to) serve, before the ? character.
I had integrated OpenTok.js library for video call in my electron app, for which i want to use logitech device and to use it i need node-hid library using which my app can detect device.
I had done all the needful mentioned for using node-hid in Electron projects, package did get installed
but when i require it in my js file using :-
var HID = require('node-hid');
var devices = HID.devices();
And run my app , it gives an error
Error: Module version mismatch. Expected 50, got 51. So please help me
with this issue .
Thanks
Use electron-rebuild for rebuild modules for suitable for electron. Some node modules are not exactly suitable for electron, because electron uses it's own build of Node. So, electron-rebuild will sort out any incompatibility or functional issues of node modules we use. The recommended way it to add "postinstall": "electron-rebuild --force" line to scripts of package.json file.
One other thing, on linux when you run dev mode, you have to run the script as sudo. Otherwise it'll rise another issue like cannot open device with path...
hope this help someone... :)
I encountered this issue myself, and thought I would share the solution that worked for me. #Tharanga is correct - the recommended way to get around this is to include the below in package.json "scripts" section:
"postinstall": "electron-rebuild --force"
However, I have experienced inconsistent success with that approach.
Another approach is, after installing "node-hid", run this (if on mac):
.\node_modules\.bin\electron-rebuild
Or for Windows:
.\node_modules\.bin\electron-rebuild.cmd
Finally, if you are using webpack in your project, you must add this line to your webpack.config.js file (within module.exports block):
externals: {
"node-hid" : 'commonjs node-hid'
}
I hope this helps some folks in the future!
I've been thinking about using React as the frontend for a Grails application, but I'm having a bit of trouble getting started.
So far, I've become accustomed to write a React app using Node/NPM with the help of Webpack, and that's been pretty easy because there is plenty of documentation for that setup.
However, I'm struggling to find anything concrete integrating React seamlessly with Grails.
Ideally, I would just do grails run-app and it should take care of everything. I do not want other team members to worry about starting up two different servers or something along those lines.
Please let me know if anyone has done this before.
Webpack can be configured to work quite well with Grails. The key is to have webpack generate its bundle whenever the app is started up, and to output the bundle in a directory where it can be served from the GSP. You do not want your source JavaScript (I.e, React/ES6 code) in the asset pipeline if your using Webpack, instead you want to keep those source files in another directory (such as src/webapp), and configure Webpack to bundle these files and output the result to the asset pipeline (assuming you're using AP at all).
Here's an example configuration for Webpack:
var path = require('path');
module.exports = {
entry: {
index: './src/webapp/index.js'
},
output: {
path: './grails-app/assets/javascripts',
publicPath: '/assets/',
filename: 'bundle.js'
},
Finally, to achieve the integrated webpack/Grails startup, you can use the Gradle node plugin and attach the webpack run script to the application startup in a custom task in your build.gradle (this is assuming that you have a npm script named "webpack" defined to run webpack)
assetCompile.dependsOn(['npmInstall', 'npm_run_webpack'])
Please note that if you want to run webpack in "watch" mode, you'll need to do that seperately from starting up the Grails app, so that that script can run continuously (there actually is support for this in the Gradle mode plugin but it's currently broken).
See this link for a more in-depth explanation of this approach, with a sample application: http://grailsblog.objectcomputing.com/posts/2016/05/28/using-react-with-grails.html
Also checkout the React profile for Grails 3: https://github.com/grails-profiles/react
It has not been released yet but should be in the next few days. It makes use of the same approach outlined here and in the linked post.
You could use npm's scripts feature to combine all steps necessary to start up the development environment into a single command, e.g.:
// package.json
{
...
"scripts": {
"start": "npm start-grails & npm start-react",
"start-grails": "grails run-app",
"start-react": "node server.js"
},
...
}
Now all it takes is a simple npm start to launch all relevant applications.
I installed dart-sdk and downloaded dart plugin to Phpstorm 8.0.3, but I cant figure out how to transpile dart to js. When I am trying to make file watcher I dont have any Dart2Js predefined template in settings.
Thank you
I know only WebStorm 9 and 10. Maybe you can still derive how it might work in PHPStorm.
Usually you don't want to build to JavaScript on each file change because this would slow your machine down.
During development you use pub serve which is automatically launched by WS 9 and 10 and which transpiles Dart files to JavaScript only on demand (when requested by a browser) and only compiles what it didn't compile previously.
For deployment WebStorm can use the Pub: build ... context menu of the pubspec.yaml file in the project view.
See #Günter Zöchbauer answer.
Using dart2js is not the recommended approach, as it runs on file level instead of project, creates output in the src folder, etc. - but the main reason is that it is not clear when/why to use it. If you need to build your project, use 'pub build' (available in pubspec.yaml right-click menu). When debugging in browser, 'pub serve' is always used implicitly - it performs all needed transformations...
But, if you still need this watcher, you can easily configure it yourself by adding a watcher of 'custom' type.
Program: path/to/dart2js
Arguments: --out=$FilePath$.js $FilePath$
Working directory: $FileDir$
Output paths: $FileName$.js:$FileName$.js.map:$FileName$.js.deps