Conversation
2624ff2 to
d100798
Compare
|
@fenduru I'm not sure about decorator approach.
|
There was a problem hiding this comment.
In previous implementation suite builder created functions inside constructor because suite needs to be private. This needed because if suite will be modified gemini may fail.
|
@SwinX the reason I went with the decorator pattern is because I want the plugin I'm going to write to change the way that Gemini acts, but not change the way that I need to write tests. My use case is to automatically run the same test multiple times, changing the theme between each capture. My plugin wraps the I think that any plugin decorating the suite shouldn't modify public API, but that doesn't mean that they shouldn't be able to wrap the API so that it can enhance existing functions. I want to write my tests like this: gemini.suite('foo', function(suite) {
// this test doesn't need to know/care that it will be tested in multiple themes
// it is valid regardless of if my plugin is loaded
suite.capture('bar')
.capture('baz');
});not gemini.suite('foo', function(suite) {
suite.captureAllThemes('bar')
.captureAllThemes('baz');
}); |
|
@SwinX any further thoughts on this? |
|
@fenduru sorry for delayed response.
Sorry, but it seems like not a good approach. The first question is why you need to keep existing API if you need different behavior from it? If you need to capture theme, then more obvious is some custom command like As I told earlier, Gemini expects some standard behavior from suite APIs. If it will not act as expected, this will lead to Gemini malfunction. gemini.decorateSuite(function(builder) {
builder.oldCapture = builder.capture;
builder.capture = function() {
builder.oldCapture('theme1', function(actions) {
actions.executeJS(function(window) {
window.setTheme('theme1');
});
})
.oldCapture('theme2', function(actions) {
actions.executeJS(function(window) {
window.setTheme('theme2');
});
});
};
});In this case Gemini probably will not fail, because in updated API you're going to use standard APIs, but if you will just exchange function without triggering old one, most likely you will have bad results. One more point against decorator approach is that it is much less obvious than adding commands. Comparing I'm still against opening In general, for your case I'd pick a way with custom commands instead of decorators. |
|
I completely disagree that having a separate
I agree that Obviously the wrapped
It isn't the data inside that I'm interested in, but having an object to store my own data on that gets inherited by nested suites. For instance, in my theming example, it would be nice to add a function called suite.setUrl()
.setCaptureElements()
.setThemes()
.capture()EDIT: This last point is strictly a "nice to have" for me - I'm much more interested in the suite decoration than exposing the |
This is not a concern at all. If you need less typing then you will name all your variables and functions using one letter.
But this will not work! If you replace original
It's ok situation to change code and tests if requirements change. I can't see any problem here. Also if I understand it right, you will just have to refactor
In your case you're altering the existing API behavior, not creating new one. Nobody looks what inside plugins. If you will alter standard behavior and will not pass your knowledge to anybody in your team then when something will break people will blame gemini, not your plugin. And the debug will look like hell.
You can just have variable in your test file and use it. Why this does not fit? /cc @SevInf |
|
@SwinX I'll update the PR to use the approach you prefer to get this moving.
The themes to be tested are defined in the plugin's configuration, however in some rare cases we want to override this for particular components. I could make the signature of the // I would like to write this:
gemini.suite('foo', function(suite) {
suite
.setUrl('...')
.setCaptureElements('...')
.setThemes(['themes', 'to', 'test'])
.captureThemes('initial')
.captureThemes('after something happened', function(actions) {
actions.doSomething();
});
gemini.suite('nested inside of foo', function(suite) {
suite
.setCaptureElements('different from above')
.captureThemes('initial'); // inherit the themes set in parent suite
});It seems that the only way the setUrl and setCaptureElements can support this nesting behavior is by having access to the suite object that gets inherited. I'd like my plugin to have the same capabilities to avoid this: var themes = ['themes', 'to', 'test'];
gemini.suite('foo', function(suite) {
suite
.setUrl('...')
.setCaptureElements('...')
.captureThemes('initial', themes)
.captureThemes('after something happened', function(actions) {
actions.doSomething();
}, themes);
gemini.suite('nested inside of foo', function(suite) {
suite
.setCaptureElements('different from above')
.captureThemes('initial', themes); // inherit the themes set in parent suite
}); |
d100798 to
4a412f0
Compare
130df9b is only there because I needed it for testing in my application. It will be removed before this is merged, but check out #282
Just want to get some eyes on this to make sure the approach is generally okay. I decided to go with a decorator approach rather than something like
addCustomFunctionbecause it is more flexible. In my particular use case, I want to override the existingcapturefunction, so I need to store a copy of it first.I will add tests and docs if this looks okay.
Fixes #197