-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct inline plugin example? #1247
Comments
Happy to submit a PR if my assumption is verified... I'll also play with inline plugins a little on my own. |
I don't know if this is useful, but it is my local karma override file with a custom plugin that runs my delcom build light. var exec = require('child_process').exec;
var DelcomReporter = function(helper, logger) {
console.log('i am a delcom reporter');
var log = logger.create('reporter.delcom');
function delcom(colour) {
log.info('setting delcom to ', colour);
exec('/usr/local/bin/delcom-stoplight ' + colour, function(error, stdout, stdin) {
}).unref();
}
this.adapters = [];
this.browserCount = 0;
this.buildOk = false;
this.onRunStart = function(browsers) {
this.browserCount = browsers.length;
this.buildOk = true;
delcom('blue');
};
this.onBrowserComplete = function(browser) {
var results = browser.lastResult;
if (results.disconnected || results.error || results.failed) {
this.buildOk = false;
}
};
this.onRunComplete = function() {
delcom(this.buildOk ? 'green' : 'red');
};
};
DelcomReporter.$inject = ['helper', 'logger'];
config.set({
//browsers: ['Chrome', 'Firefox', 'Safari']
browsers: ['Chrome'],
plugins: [
// Karma will require() these plugins
'karma-jasmine',
'karma-chrome-launcher',
'karma-ng-html2js-preprocessor',
// inlined plugins
{
'reporter:delcom': ['type', DelcomReporter]
}
],
reporters: ['progress', 'delcom']
}); |
I have tried to do this recently and can confirm that it doesn't work. With the following simple configuration frameworks: [
{
'framework:xyz': ['factory', function (files, extraConfig) {
console.log(files);
}]
},
'sinon',
'chai'
], I get the following error message
It appears that the di injector is trying to fetch the factory from the known set of node_modules only (those that start with karma-) and doesn't know that this is its own function. I'm using Karma 1.3.0 |
@steveworkman it's supposed to be in |
@steveworkman Unfortunately documentation isn't helpful in this case. After few hours of investigating the same thing, it seems that "low-level" config options like "frameworks", "preprocessors", "launchers" and "reporters" are used only to declare that you want to use this given tool. However, to be able to use for example "xyz" in frameworks section, you need to register this framework in "plugins". That's the missing part in documentation. In plugins you need to expose a module, which will have defined plugin type, and i.e. factory function. So first, register "xyz" in plugins using for example require function and path to your module, and then in frameworks just add "xyz" string. |
This has been on the backlog for a long time! Doesn't seem like it's a difficult thing to fix up and it'd be handy as I found (was linked to) the documentation on inlining far before I found this issue... |
I want to coment one thing. For framework inline plugin, factory function must not be arrow function, otherwise it gives error |
Changes: - Promote `require('karma-plugin')` form over `'karma-plugin'` form. Former makes it more clear that plugin is imported from an NPM package and it is a regular JS object, there is no magic behind it. This is inspired by karma-runner#3498 where user is not aware that it is even possible. This also should make it easier with plug'n'play package managers (like Yarn 2). - Explain that `plugins` array does not activate plugins, but only registers them to clarify karma-runner#1247 (comment). - Explain the plugin structure, DI and how to build a new plugin. - Re-arrange "Developing plugins" page to make it easier to add more information about every plugin type. Adding actual information should be done in the separate PRs though. Fixes karma-runner#1247
Changes: - Promote `require('karma-plugin')` form over `'karma-plugin'` form. Former makes it more clear that plugin is imported from an NPM package and it is a regular JS object, there is no magic behind it. This is inspired by karma-runner#3498 where user is not aware that it is even possible. This also should make it easier with plug'n'play package managers (like Yarn 2). - Explain that `plugins` array does not activate plugins, but only registers them to clarify karma-runner#1247 (comment). - Explain the plugin structure, DI and how to build a new plugin. - Re-arrange "Developing plugins" page to make it easier to add more information about every plugin type. Adding actual information should be done in the separate PRs though. Fixes karma-runner#1247
Changes: - Promote `require('karma-plugin')` form over `'karma-plugin'` form. Former makes it more clear that plugin is imported from an NPM package and it is a regular JS object, there is no magic behind it. This is inspired by #3498 where user is not aware that it is even possible. This also should make it easier with plug'n'play package managers (like Yarn 2). - Explain that `plugins` array does not activate plugins, but only registers them to clarify #1247 (comment). - Explain the plugin structure, DI and how to build a new plugin. - Re-arrange "Developing plugins" page to make it easier to add more information about every plugin type. Adding actual information should be done in the separate PRs though. Fixes #1247
🎉 This issue has been resolved in version 6.1.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@zyf0330 thanks for mentioning it, I ran into the same issue and you helped me solve it! |
Changes: - Promote `require('karma-plugin')` form over `'karma-plugin'` form. Former makes it more clear that plugin is imported from an NPM package and it is a regular JS object, there is no magic behind it. This is inspired by karma-runner#3498 where user is not aware that it is even possible. This also should make it easier with plug'n'play package managers (like Yarn 2). - Explain that `plugins` array does not activate plugins, but only registers them to clarify karma-runner#1247 (comment). - Explain the plugin structure, DI and how to build a new plugin. - Re-arrange "Developing plugins" page to make it easier to add more information about every plugin type. Adding actual information should be done in the separate PRs though. Fixes karma-runner#1247
On the Plugins page of the documentation, the following example is presented:
Although I haven't needed to write my own inline plugins yet, I doubt the example provided is correct, since it's not even valid JavaScript syntax. Should it be
{ 'framework:xyz' : [ 'factory', factoryFn ] }
instead? A little explanation on that point would be appreciated.The text was updated successfully, but these errors were encountered: