-
Notifications
You must be signed in to change notification settings - Fork 8
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
NodeJS: Do not execute all rulesets #15
Comments
I think it's reasonable to want to run top-level rulesets on a discretionary basis. I could supply a In regards to a meta-syntax: have you looked into Bas' annotation system? You could do something like this in your sheet: /*@url:http://example.com/abc?def=123*/
@all {
status-code: 200;
}
/*@url:http://example2.net/ghi?klm=456*/
@all {
status-code: 302;
} And then in your core code you could extract the URLs like so: testSuite.rules.forEach(function(rule) {
var urls =
rule.annotations
.filter(function(annotation) {
return annotation.match(/^\s*url\:/i);
})
.map(function(annotation) {
return (
annotation
.replace(/(^\s+|\s+$)/g)
.substr(4)
);
});
urls.forEach(function(url) {
request(url,function(err, res, body) {
if (err) { /* handle err */ }
rule.run(url, res, body);
});
});
}); (Please note, I haven't tested that, and it depends on the currently fictitious As a side note, please be aware that testSuite.loadSheet("example.bas")
.yep(function() { /* handle success */ })
.nope(function() { /* handle failure */ }); |
I hadn't looked at annotations. As mentioned I parse the URL from As for |
We've partially talked about this on ADN. To recap:
I want to be able to write a sheet file where every ruleset is meant for a specific URL. To avoid writing URLs twice I want to parse the URL from the ruleset's conditions.
When that's done I want to loop through all rulesets. For each ruleset I would fetch the desired URL and then run the one ruleset over it.
My sheet file looks like this:
What I have so far: First I load a sheet and use
rules.forEach
to get each one (simplified, my actual code includes a little error checking):The function
myGetRuleUrl
parses the rule.input and extracts the URL from the ruleset's conditions (it understands url, protocol, domain and path). In my use case I only use simple strings for comparison. Regular expressions would not work for what I have in mind.The
myCallback
function then loops through each result and does this (again, simplified for readability):So essentially I'm setting up a new Bas instance for every URL, and then I run the entire sheet over it, even though I already know that only one of the rulesets is going to match.
Perhaps it is silly to worry over this since Bas is probably pretty quick about evaluating conditions on all the rulesets. But it's not elegant :)
I can think of two ways to simplify this.
First, add a method to add a rule object (as returned by
BAS.rules.forEach
) to a test suite:Second option: Convert a rule object back into its string representation, so I can pass it back into
BAS.loadSheet
:I hope it's clear what I'm trying to accomplish.
But perhaps I'm approaching this from the wrong angle. I'm currently doing complicated things only to avoid writing the same URL twice.
Maybe I would be better off inventing a meta-syntax (or simple two-column database) for URL => ruleset. Then each ruleset could simply be of the
@all
type and I would have no problem running each test separately.The text was updated successfully, but these errors were encountered: