问题
I'm trying to get the intern-cucumber plugin working. I get the following error:
Error: A plugin named "cucumber" has not been registered
at Node.BaseExecutor.getPlugin @ src\lib\executors\Executor.ts:387:12
@ tests\addition.js:6:29
at runFactory @ node_modules\dojo\dojo.js:1134:43
at execModule @ node_modules\dojo\dojo.js:1262:5
at execModule @ node_modules\dojo\dojo.js:1253:12
@ node_modules\dojo\dojo.js:1297:6
at guardCheckComplete @ node_modules\dojo\dojo.js:1277:5
at checkComplete @ node_modules\dojo\dojo.js:1292:4
at contextRequire @ node_modules\dojo\dojo.js:835:6
at req @ node_modules\dojo\dojo.js:124:11
@ src\loaders\dojo.ts:36:8
at new Promise @ anonymous
at Node._loader @ src\loaders\dojo.ts:29:13
at Node._loadFunctionalSuites @ src\lib\executors\Node.ts:593:29
@ src\lib\executors\Node.ts:882:24
@ node_modules\@theintern\common\index.js:16:7174
Any ideas on how to solve this? My intern.json configuration file looks like:
{
"loader": {
"script": "dojo",
"options": {
"packages": [
{
"name": "features",
"location": "features"
},
{
"name": "models",
"location": "models"
},
{
"name": "dojo",
"location": "node_modules/dojo"
}
]
}
},
"functionalSuites": "tests/**.js",
"environments": [ "chrome" ],
"browser": {
"plugins": [
"node_modules/intern-cucumber/browser/plugin.js"
]
},
"node": {
"plugins": "node_modules/intern-cucumber/plugin.js"
}
}
And my test file, where the error is happening, addition.js looks like:
define([
'models/calculator',
'dojo/text!features/addition.feature'
], function (calculator, featureSrc) {
const cucumber = intern.getPlugin('cucumber');
const assert = intern.getPlugin('chai').assert;
cucumber.registerCucumber('Calculator addition', featureSrc, function () {
cucumber.Given('the calculator is cleared', function () {
});
cucumber.When(/^I add (\d+) and (\d+)$/, function (x, y) {
var calc = new Calculator(x, y)
})
cucumber.Then(/^the result should be (\d+)$/, function (z) {
var result = calc.sum();
assert.equal(z,result,'Expected result to be: ' + z)
})
}
)
}
)
Does anyone have ANY idea how to solve this? No idea why the plugin wouldn't work, is there something wrong with my intern.json file??
回答1:
The code is calling intern.getPlugin('cucumber')
. It should actually be calling intern.getPlugin('interface.cucumber')
or intern.getInterface('cucumber')
(the former is preferred).
Intern has an API specifically for registering and retrieving interfaces (registerInterface
and getInterface
). However, it's just a thin wrapper around the general plugin API (registerPlugin
and getPlugin
) that adds interface.
to the plugin name. The interface API will likely be removed in the future in favor of just having the single plugin API.
来源:https://stackoverflow.com/questions/59313397/intern-cucumber-plugin-error-a-plugin-named-cucumber-has-not-been-registered