-
Notifications
You must be signed in to change notification settings - Fork 45
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
Added functional and unit tests #37
Conversation
And improved elapsedToString according to the tests fsdfsfs
And increase the timeout as the first time it can take a while
@erwindon could you review this pull request before merging? And I have one request for you, see: https://github.com/maerteijn/SaltGUI/blob/nightmarejs/tests/unit/parsecmdline.js#L21 Could you add some more assertions there? :) |
This is really cool! |
Debian 9:
any suggestions? edit: actually only the first line is the actual error. everything else is from the cleanup procedure in the script |
@erwindon You have the wrong yarn I think. See: yarnpkg/yarn#2821 and then the second answer, and the installation manual of yarn: https://yarnpkg.com/lang/en/docs/install/#debian-stable |
I needed an additional |
next one...
I removed
Since this is a complaint about the file we are testing, I guess it is working. |
This sounds like an ancient version of nodejs. Which version do you have installed? See https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions how to install version 10. See also the note about |
Seems I cannot trust the Debian distributions any more. |
Still, I need to use: |
The 3333 was intentional yes as it’s referred to it further in the readme. |
I dropped zombie.js as it took way too much time to write working tests. It is a bit buggy and there is no up to date documentation. Nightmare.js works pretty awesome and is well documented. Tests can be debugged with a debugger which is pretty neat. The only thing is yes, you’ll need a display driver. |
I would put the updated parser and the tests for it here in this branch |
tests/functional/login.js
Outdated
const url = 'http://localhost:3333/'; | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for the extra new lines here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I changed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left some comments with some feedback, mainly style based rather than around the implementation. It's great to see the work going on with SaltGUI and while I am still too busy to contribute, I want to try and look at PRs more often when I can 😅
Thanks for keeping the project alive! ❤️
tests/functional/login.js
Outdated
typeInterval: 20, | ||
// uncomment this to show the browser and the debug window | ||
// openDevTools: { | ||
// mode: "detach" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to have the script take in a parameter which could be used to change this setting. The default should probably be a hidden browser window and it should be shown only if requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, then the bash script should parse them, add them to the testing script which is implicitly invoked with yarn, then I need to parse the command again in javascript.
So I think WAY to much work (and hassle for me) for a small feature in the testrunner. But if you want it you can make a PR of course 😄
# run the unittests/nightmare.js functional tests | ||
yarn test | ||
|
||
set +e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at the end of this file 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's bash, not javascript 😳 but I've added the newline.
saltgui/static/scripts/utils.js
Outdated
} | ||
if(secondsPassed < 60 * 60 * 24) { | ||
var hours = Math.round(secondsPassed / 60 / 60); | ||
return hours + " hours ago"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we end up with "one hours" here?
saltgui/static/scripts/utils.js
Outdated
return "A long time ago, in a galaxy far, far away"; | ||
} | ||
catch(err) { | ||
return "It did happen, when I don't know"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably log this error the console?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I added it.
|
||
it('we should be redirected to the login page', done => { | ||
browser | ||
.end() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the purpose of the end here? I'm not sure I get it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/segmentio/nightmare#end and the api documented there. See also the beforeEach
handler where we queue the url.
tests/functional/login.js
Outdated
.type('#username', 'salt') | ||
.type('#password', 'salt') | ||
.click('#login-submit') | ||
.wait( ()=> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after the ()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I added it.
tests/helpers/wait-for-docker.js
Outdated
followRedirect: true, | ||
}; | ||
|
||
waitOn(resources, error => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we only use waitOn
once, I wonder if we can write our own method to check every few seconds instead? It just seems like there's the opportunity here to avoid a dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the only way to do this with node.js
(without adding dependencies) is with the shipped http library. (as fetch
does not exist). And this module is really low level, so we have to make all the error handling ourselves (even getting the chunks of partial result data is something you have to do yourselves).
So know I rewrote it with the requests
which is already a dependency of one of the other packages, which means we can drop wait-on
. (And I did).
require('../../saltgui/static/scripts/utils'); | ||
|
||
|
||
describe('Unittests for utils.js', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tests for potential mistakes would be great here (one minutes etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah well, it would be fantastic but this function is now tested enough I think. PR's are welcome 😃
global.window = new Object({}); | ||
|
||
require('../../saltgui/static/scripts/utils'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for two lines over one here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, so I adjusted it.
assert.equal(args.length, 1); | ||
assert.equal(args[0], "NOne"); | ||
assert.equal(Object.keys(params).length, 0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I've left similar comments above, but is there a reason for the newlines after comments, or the multiple lines between code blocks? I just think there is room for some style improvements 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit tests in tests/unit/parsecmdline.js
are grouped in sets. These comments are basically the group titles. 3 empty lines before that to visually separate from the previous group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with oliver that there were 's a bit too much newlines So I adjusted it a bit.
I'm running into an error when trying to use these tests locally:
The Cloudflare URL was quite long, so I've intentionally truncated it. |
@oliverdunk Seems like https:///production.cloudflare.docker.com was offline, as travis was able to download them. Could you try again? I'll review your other comments later. The newlines come from the python style guide, which is unconsciously applied to javascript :-) Would be something to add to the linter btw. |
And now I have to fix the build first :) |
Build is fixed, @oliverdunk can you review again with all the changes? (Please note I already created a new branch which needs to be reviewed later for more explicit linting: nightmarejs...replace-jshint-with-eslint) |
@oliverdunk Any chance to respond the following days? Would be nice to have your feedback and this pull request merged as @erwindon has a lot of work waiting for us 😄 |
Hey @maerteijn, absolutely. Will aim to do so tomorrow. If I'm blocking you and you're happy, feel free to merge without me 👍 |
No description provided.