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 JS Jasmine tests to Travis CI #9013

Merged
merged 18 commits into from
Mar 31, 2017

Conversation

Igloczek
Copy link
Contributor

@Igloczek Igloczek commented Mar 25, 2017

JS tests are already written, but not used on Travis CI pipeline, so I added the necessary config to enable them.

@ishakhsuvarov
Copy link
Contributor

Hi @Igloczek
Thank you for this PR. It is really a great idea to add JS Jasmine tests to the Travis-ci.

Could you please look into some questions I've left in the comments? Thanks!

@Igloczek
Copy link
Contributor Author

@ishakhsuvarov I'm pretty sure you forgot to hit "Submit review" 😉

@@ -0,0 +1,360 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding a hard-coded configuration may be too fragile, since it may be a subject for modification. Please consider installing to get the generated file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was following docs in this matter, b/c installing the whole application, just to get statics, it's serious overhead for me.

Maybe simpler option will be to work on source files, rather than processing them through M core, before running tests? It should be also easier for development purposes.

Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation in question is about generating static on a non-production machine, so this is a slightly different case. Providing a hard-coded configuration file is not the best practice and needs to be maintained all the time.

I would still suggest installing application for now, at least for consistency, since internally this is what we do to run Jasmine tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ishakhsuvarov could you move some internal code to public maybe so that we don't have two different implementations?

From https://github.com/magento/magento2/blob/develop/dev/travis/before_script.sh#L61 it looks it is not so easy to steal application installation from integration tests and it is placed somewhere inside framework.

As to me hardcoded config seems fine at least as a temporary solution if we add comment on top of it how to regenerate file.

Copy link
Contributor

Choose a reason for hiding this comment

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

@orlangur It is executed under different infrastructure then Travis CI. Would not solve the issue in question.
"Stealing" application from the integration tests is not a good solution either. Clean install should do the trick for now, while no better solution is available.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ishakhsuvarov what do you mean by clean install? :) I thought installation in scope of integration tests is clean. Is it possible to install application without database at all, for example?

Copy link
Contributor Author

@Igloczek Igloczek Mar 27, 2017

Choose a reason for hiding this comment

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

@ishakhsuvarov Could you share part of your tests configuration related to installation? Will be much easier to copy-paste(-adjust) working solution 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

@Igloczek So, I've done some brief experiments with Travis CI and here is what seems to be working:

  1. Instead of bundling config.php add the minimum installation as follows (it does not add too much time to the execution):

echo "Installing Magento"
mysql -uroot -e 'CREATE DATABASE magento2;'
php bin/magento setup:install -q --admin-user="admin" --admin-password="123123q" --admin-email="admin@example.com" --admin-firstname="John" --admin-lastname="Doe"

  1. You may do some experiments with the static content deployment settings to add a bit more performance. Here is what worked for me (may not be the best solution, just experiment):

echo "Deploying Static Content"
php bin/magento setup:static-content:deploy -f -q -j=2 --no-css --no-less --no-images --no-fonts --no-misc --no-html-minify


cp package.json.sample package.json
cp Gruntfile.js.sample Gruntfile.js
npm install -g yarn
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really viable to install yarn just to install grunt-cli?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not only grunt-cli, all dependencies defined in package.json are downloaded using yarn in line 90 (yarn is replacement for npm install).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for clarification.

@ishakhsuvarov
Copy link
Contributor

@Igloczek You are so right

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
nvm install --lts
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it would be more robust to specify some concrete version, like in https://github.com/BanzaiMan/travis_production_test/blob/9c02aef/.travis.yml#L15, so that we see in environment variable which version we test against

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if we really need to care about precise versioning, b/c in Oct 2017 we should be ready to use v7 without any issues and necessary updates in code base.

Node.js LTS plan is precisely described here - https://github.com/nodejs/LTS

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understood the doc right v7 is not LTS and will not be used in such code.

The point is that I don't see any value in dynamic Node.js version, it can only bring us some headache when the LTS version will switch. Explicit is better than implicit.

As soon as v8 stable is released we can change value in our config if the tests still pass. Current version is like specifying php: stable version instead of concrete value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, v8, not v7.
LTS means more than stable, b/c stable v8 will be released in April 2017, but will be marked as LTS in Oct 2017. It's a different approach than PHP takes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it guaranteed that using v6 for tests before, we will not have any issues under v8 when it become LTS? What's BC police?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OFC there are BC between major releases, but major becomes LTS after half year and most of the packages get updates during this period, so migration is in most of the cases are seamless.

Copy link
Contributor

Choose a reason for hiding this comment

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

It does not mean all our tests will work without changes.

Just answer the simple question - what is the value of NOT specifying a concrete version but using LTS instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, package.json.sample bundled with Magento also has version requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are always up to date, don't have to follow releases schedule etc. When new LTS version will be up, your tests will start using it.

But to just quit discussion, I'll change it to 6 and this will be good enough till next LTS.

Docs about engines option from package.json

this field is advisory only will produce warnings when your package is installed as a dependency.

So in our case, we can simply remove this param.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

When new LTS version will be up, your tests will start using it.

Yeah, that's a scary part as to me, as put our builds a bit out of control.

before_install: ./dev/travis/before_install.sh
install: composer install --no-interaction --prefer-dist
before_script: ./dev/travis/before_script.sh
script:
- test $TEST_SUITE = "static" && TEST_FILTER='--filter "Magento\\Test\\Php\\LiveCodeTest"' || true
- phpunit -c dev/tests/$TEST_SUITE $TEST_FILTER
- if [ $TEST_SUITE != "js" ]; then phpunit -c dev/tests/$TEST_SUITE $TEST_FILTER; fi
- if [ $TEST_SUITE == "js" ]; then grunt spec; fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at https://travis-ci.org/magento/magento2/jobs/215020317 - is there some less verbose mode? Display only failed tests maybe...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea, for now I just focuses on make this test running, then we can think about some adjustments / improvements.

PS. I really hate Grunt, so if I don't have to modify this, I will be more than happy to leave it as it is 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I didn't use it as well, and didn't google for a solution just in case you know the answer.

It can wait until it become a problem "output is too big" some day (hopefully never).

@ishakhsuvarov ishakhsuvarov added this to the March 2017 milestone Mar 27, 2017
@ishakhsuvarov
Copy link
Contributor

@Igloczek Looks good to me now! Thanks for the fixes.
I am going to restart Travis build, to get rid of the Some checks were not successful error, and proceed with the merge.

@Igloczek
Copy link
Contributor Author

You are faster than my thoughts, I was going to do same thing 😄

@Igloczek
Copy link
Contributor Author

Please stop the merging process, I found a bug related to NVM and we are now using some built-in Node.js version.

@ishakhsuvarov
Copy link
Contributor

@Igloczek Thanks for reporting

@Igloczek
Copy link
Contributor Author

Fixed.

@@ -80,8 +80,8 @@ case $TEST_SUITE in
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
bash -c "nvm install $NODE_JS_VERSION" || true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why there was bash used at all in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just b/c I'm a dumb copy-paster 🙄

Copy link
Contributor

Choose a reason for hiding this comment

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

That's absolutely fine as I had just an approximate understanding of what is going on when reviewed your code as well 👍

Hope we have some decent DevOps in Magento Community or in Magento Team to review Travis scripts :)

@okorshenko
Copy link
Contributor

@Igloczek thank you for your contribution!

@Igloczek Igloczek deleted the js-ci-test-on-travis branch April 1, 2017 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants