Describe the bug
When using Dredd as a JavaScript Library, endpoint must be nested even though the documentation says it shouldn't.
To Reproduce
This should work, but doesn't (see output from this under _Does dredd --loglevel=debug uncover something_?):
const Dredd = require('dredd');
let configuration = {
endpoint: 'http://127.0.0.1:3000',
loglevel: 'debug',
path: ['petstore.yaml'],
};
let dredd = new Dredd(configuration);
dredd.run(function (err, stats) {
if (err) {
console.error('Encountered problems!');
console.error(err);
process.exit(1);
}
console.log(stats);
})
The code below works:
const Dredd = require('dredd');
let configuration = {
options: {
endpoint: 'http://127.0.0.1:3000'
},
loglevel: 'debug',
path: ['petstore.yaml'],
};
let dredd = new Dredd(configuration);
dredd.run(function (err, stats) {
if (err) {
console.error('Encountered problems!');
console.error(err);
process.exit(1);
}
console.log(stats);
})
Expected behavior
When using Dredd as a JavaScript library, I expect that it should work according to the documentation.
It is also slightly confusing that we use path for the API documentation when using Dredd as a library, but if I were to use dredd.yml I assume I should use blueprint.
What is in your dredd.yml?
No dredd.yml
What's your dredd --version output?
dredd v11.1.0 (Linux 4.15.0-50-generic; x64)
Does dredd --loglevel=debug uncover something?
...
2019-05-21T09:04:59.253Z - debug: Configuring HTTP transactions
/home/user/temp/test-dredd/node_modules/dredd/lib/TransactionRunner.js:293
if (!serverUrl.match(/^https?:\/\//i)) {
^
TypeError: Cannot read property 'match' of undefined
at TransactionRunner.parseServerUrl (/home/user/temp/test-dredd/node_modules/dredd/lib/TransactionRunner.js:293:20)
at TransactionRunner.configureTransaction (/home/user/temp/test-dredd/node_modules/dredd/lib/TransactionRunner.js:227:50)
at Array.map (<anonymous>)
at emitStart (/home/user/temp/test-dredd/node_modules/dredd/lib/TransactionRunner.js:53:35)
at configuration.emitter.emit (/home/user/temp/test-dredd/node_modules/dredd/lib/TransactionRunner.js:81:34)
at EventEmitter.emitter.on (/home/user/temp/test-dredd/node_modules/dredd/lib/reporters/CLIReporter.js:32:5)
at EventEmitter.emit (events.js:202:15)
at TransactionRunner.emitStart (/home/user/temp/test-dredd/node_modules/dredd/lib/TransactionRunner.js:76:32)
at TransactionRunner.run (/home/user/temp/test-dredd/node_modules/dredd/lib/TransactionRunner.js:46:10)
at prepareAPIdescriptions (/home/user/temp/test-dredd/node_modules/dredd/lib/Dredd.js:193:30)
Can you send us failing test in a Pull Request?
The code I use can be seen above, except petstore.yml. If you need this I can create a pull request.
@philiplarsson Thank you Philip, this is a bug resulting from a recent refactoring we did. I believe we should be able to fix it fast.
Thank you for the issue. I've adderessed it in #1375 and will publish once the CI passes.
The issue has appeared during the resolving of Dredd configuration. Since we are slowly deprecating the nested options key in the Dredd configuration and still support it, we flatten the configuration internally to have a unified references to its options. During the flattening we are performing an aliasing of server option to endpoint option:
It's also tricky that this aliasing is performed on the resolving layer, as opposed to the normalization layer where you would expect it to happen. This is because aliasing of
serveroption cannot happen on the flattened config (see the naming conflicts below).
This is necessary because root configuration (i.e. dredd.yml) and nested options key in the configuration contain the same serverproperty, but it does different things based on where it's defined:
server in dredd.yml acts as a server invocation command (i.e. npm start)server in Dredd configuration (as a library) used to define a _server url_ (whereas dredd.yml has a dedicated endpoint option for this).To preserve the current behavior, we are aliasing root server option to root endpoint option, removing the root server entirely (it's not a valid option and it conflicts with both YML and programatic usage configurations).
However, during this options aliasing there has been no check to verify the root server option is set. In case when it's not set (like the scenario @philiplarsson has reported), the endpoint option is still created with the value of undefined. This results into invalid configuration and fails further Dredd execution.
server option is set before aliasing it to the endpoint option. :tada: This issue has been resolved in version 11.1.3 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
@philiplarsson please update to the latest Dredd version and let us know if the issue is resolved. Thank you.
@artem-zakharchenko I've verified that the issue is solved in version 11.1.3. This was fixed impressively fast!
Thank you @artem-zakharchenko and @honzajavorek 馃憦
Most helpful comment
@artem-zakharchenko I've verified that the issue is solved in version 11.1.3. This was fixed impressively fast!
Thank you @artem-zakharchenko and @honzajavorek 馃憦