Skip to content
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

Merged
merged 36 commits into from Aug 19, 2018
Merged

Added functional and unit tests #37

merged 36 commits into from Aug 19, 2018

Conversation

maerteijn
Copy link
Collaborator

No description provided.

@maerteijn
Copy link
Collaborator Author

@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? :)

@oliverdunk
Copy link
Collaborator

This is really cool!

@erwindon
Copy link
Owner

erwindon commented Aug 4, 2018

Debian 9:

$ bash runtests.sh      
ERROR: There are no scenarios; must have at least one.
Removes stopped service containers.

By default, anonymous volumes attached to containers will not be removed. You
can override this with `-v`. To list all volumes, use `docker volume ls`.

Any data which is not in a volume will be lost.

Usage: rm [options] [SERVICE...]

Options:
    -f, --force   Don't ask to confirm removal
    -v            Remove any anonymous volumes attached to containers
    -a, --all     Obsolete. Also remove one-off containers created by
                  docker-compose run

any suggestions?

edit: actually only the first line is the actual error. everything else is from the cleanup procedure in the script
edit: the secondary error is from "docker-compose rm" which does not support -s

@maerteijn
Copy link
Collaborator Author

maerteijn commented Aug 4, 2018

@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

@erwindon
Copy link
Owner

erwindon commented Aug 4, 2018

I needed an additional ln -s /usr/bin/nodejs /usr/bin/node
(found on https://askubuntu.com/questions/404929/node-command-not-found)

@erwindon
Copy link
Owner

erwindon commented Aug 4, 2018

next one...

$ mocha --bail --trace-warnings --reporter spec tests/unit/ tests/functional/
/usr/bin/nodejs: bad option: --trace-warnings
error Command failed with exit code 9.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I removed --trace-warnings from package.json and now the first test result comes in.

/home/erwindon/SaltGUI/saltgui/static/scripts/parsecmdline.js:109
      let str = "";
      ^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

Since this is a complaint about the file we are testing, I guess it is working.
(well, ok that was only the output of yarn lint)

@maerteijn
Copy link
Collaborator Author

maerteijn commented Aug 4, 2018

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 nodejs-legacy package

@erwindon
Copy link
Owner

erwindon commented Aug 4, 2018

$ nodejs --version
v4.8.2

Seems I cannot trust the Debian distributions any more.
Now upgraded to node.js 8.11.3 and yarn 2.7.6
Much better now!

@erwindon
Copy link
Owner

erwindon commented Aug 4, 2018

Still, I need to use:
version 2 in docker-compose.xml
rm -f instead of rm -f -s in package.json
And I'm ignoring a timeout failure in the login test.

@maerteijn
Copy link
Collaborator Author

The 3333 was intentional yes as it’s referred to it further in the readme.

@maerteijn
Copy link
Collaborator Author

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.

@maerteijn
Copy link
Collaborator Author

I would put the updated parser and the tests for it here in this branch

const url = 'http://localhost:3333/';



Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I changed it.

@erwindon erwindon assigned maerteijn and unassigned erwindon Aug 4, 2018
Copy link
Collaborator

@oliverdunk oliverdunk left a 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! ❤️

typeInterval: 20,
// uncomment this to show the browser and the debug window
// openDevTools: {
// mode: "detach"
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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 😉

Copy link
Collaborator Author

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.

}
if(secondsPassed < 60 * 60 * 24) {
var hours = Math.round(secondsPassed / 60 / 60);
return hours + " hours ago";
Copy link
Collaborator

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?

return "A long time ago, in a galaxy far, far away";
}
catch(err) {
return "It did happen, when I don't know";
Copy link
Collaborator

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?

Copy link
Collaborator Author

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()
Copy link
Collaborator

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.

Copy link
Collaborator Author

@maerteijn maerteijn Aug 5, 2018

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 beforeEachhandler where we queue the url.

.type('#username', 'salt')
.type('#password', 'salt')
.click('#login-submit')
.wait( ()=> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after the ()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I added it.

followRedirect: true,
};

waitOn(resources, error => {
Copy link
Collaborator

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.

Copy link
Collaborator Author

@maerteijn maerteijn Aug 5, 2018

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() {
Copy link
Collaborator

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.)

Copy link
Collaborator Author

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');

Copy link
Collaborator

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?

Copy link
Collaborator Author

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);

Copy link
Collaborator

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 😄

Copy link
Owner

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.

Copy link
Collaborator Author

@maerteijn maerteijn Aug 5, 2018

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.

@oliverdunk
Copy link
Collaborator

I'm running into an error when trying to use these tests locally:

ERROR: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/...: Service Unavailable

The Cloudflare URL was quite long, so I've intentionally truncated it.

@maerteijn
Copy link
Collaborator Author

@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.

@maerteijn
Copy link
Collaborator Author

And now I have to fix the build first :)

@maerteijn
Copy link
Collaborator Author

maerteijn commented Aug 5, 2018

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)

@maerteijn
Copy link
Collaborator Author

@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 😄

@oliverdunk
Copy link
Collaborator

Hey @maerteijn, absolutely. Will aim to do so tomorrow. If I'm blocking you and you're happy, feel free to merge without me 👍

@maerteijn maerteijn merged commit f81c06f into master Aug 19, 2018
@maerteijn maerteijn deleted the nightmarejs branch August 19, 2018 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants