Skip to content

Conversation

@Vinai
Copy link
Contributor

@Vinai Vinai commented Jan 12, 2015

All global functions in the CLI script have been moved into a new class JsTestDriver located within the dev/tests/js/framework/JsTestDriver.php file.
The goal of the refactoring is to make the code more reusable and maintainable and make the script run on OS X without killing running PHPStorm instances.
The script itself is now just an entry point to call functionality within the new class.
The public interface of the JsTestDriver class is:

  • JsTestRunner::fromConfigFile()- static factory method
  • runTests() - functionality formerly within the run_js_tests.php script
  • buildJsTestRunnerConfig() - rebuild the jsTestDriver.conf file

The functionality of the script has been decomposed into smaller functions.

A new entry point script has been added, build_js_test_conf.php, to just
rebuild the test configuration, without executing JsTestDriver.

@Vinai
Copy link
Contributor Author

Vinai commented Jan 12, 2015

According to https://travis-ci.org/magento/magento2/builds the static_phpcs testsuite has been broken by the commit a1ab120

Running the tests locally doesn't list the JsTestDriver class or the files run_js_tests.php or build_js_test_conf.php in the report.

Rebasing the branch on the latest develop HEAD just in case.

@Vinai
Copy link
Contributor Author

Vinai commented Jan 13, 2015

Close and reopen PR to restart travis build.

@Vinai Vinai closed this Jan 13, 2015
@Vinai Vinai reopened this Jan 13, 2015
All global functions in the CLI script have been moved into a new class JsTestDriver.php
located within the dev/tests/js/framework directory.
The script itself is now just an entry point to call functionality within the new class.

Purpose of this refactoring is to

* Make the code more reusable and maintainable
* Make the script work on OS X (without killing PHPStorm)
* Provide an way to rebuild the jsTestDriver.conf without running the tests

The public interface of the JsTestDriver class is:

* JsTestRunner::fromConfigFile() - static factory method
* runTests() - functionality formerly within the run_js_tests.php script
* buildJsTestRunnerConfig() - rebuild the jsTestDriver.conf file

The functionality of the script has been decomposed into smaller functions.

A new entry point script has been added, build_js_test_conf.php, to just
rebuild the test configuration, without executing JsTestDriver.

This should be considered not the final solution, but rather a step on the way
to a flexible and cross-plattform way to run the js tests.
@vpelipenko vpelipenko added CS and removed CS labels Jan 15, 2015
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this class more maintainable? I agree with some refactorings but what's the benefit of having functions namespaced in class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course it s not mandatory, using global scope and functions is great, but it just felt like a way to bind the methods to the config data set without using global variables or always passing the array as an argument.

I find smaller methods generally easier to understand and refactor.
To hide the larger number of methods, the class only exposes two public methods, which makes it easier to use, and also document the purpose.

Also, I find it easier to refactor code if I can see which methods are private, that is, implementation details, so they are safe to change.

I expect most of the command line scripts in Magento to be refactored sooner or later to use a common entry point (simply because that is what most PHP devs know from various frameworks).
Having the code in a class might make it easier to reuse some of it in that case.

I've also written some hacky tests (not commited) which compared the output of the class to the output of the originial script, and that also was easier to do with this version of the code in a class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Moving scripting behavior to class doesn't help. Also because all of the helper methods are private and on the same class, it's impossible to configure it differntly. Also different entry points should get different instances of different classes. writeJsTestRunnerConfig() has nothing to do with runTests()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As stated in the commit message I didn't see this as the final result, it just was some refactoring along the way, to leave the code in a better state then it was. Decomposing the class would probably be one of the next steps.
For now it got me where I wanted, that is, understand what the code does and make future changes easier.

I actually don't expect this code to hang around for long. Based on @vkorotun's comments in #954 I expect the JS testing framework will change quite a lot, maybe completely removing JsTestDriver (I hope so).

@vkorotun
Copy link
Contributor

vkorotun commented Feb 3, 2015

Hi @Vinai,
We have started working on new JavaScript testing framework (based on Jasmine), and few days ago pushed first portion of the tests (documentation will follow up soon). New tests are placed under dev/tests/js/spec/unit and dev/tests/js/spec/integration paths for Unit and Integration tests correspondingly.

Short description of the workflow:

Preconditions:

  • NodeJS is installed and runs
  • NPM is installed (often installed by NodeJS itself)
  • Grunt is installed

To install and configure environment, run these two commands in project root:
npm install -g grunt grunt-cli
npm install

To run unit tests:
grunt spec unit

To run integration tests:
grunt spec integration

@vpelipenko
Copy link
Contributor

@Vinai, JavaScript testing framework changes mentioned by @vkorotun will be delivered with the next public GitHub update at the end of this week.

@vpelipenko vpelipenko added CS and removed PS labels Feb 3, 2015
@vpelipenko
Copy link
Contributor

@Vinai, the latest 0.42.0-beta7 version includes new JavaScript testing framework (based on Jasmine).

@Vinai
Copy link
Contributor Author

Vinai commented Feb 8, 2015

Thank you so much for the updates. I've moved house and still don't have internet there (in hotel currently) so I was unable to participate any further. I'm looking forward to trying out the new JS testing framework 👍

@vpelipenko
Copy link
Contributor

@Vinai, if you have any updates, please, share them with us.

@vpelipenko
Copy link
Contributor

Closed due to publishing new JS testing framework and contributor's inactivity during 2 weeks. @Vinai, if you want to add something, please, feel free to reopen this PR or create new one.

@vpelipenko vpelipenko closed this Mar 2, 2015
magento-team pushed a commit that referenced this pull request Mar 27, 2017
MAGETWO-58729: [Generator] Add images to performance profile generator
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.

4 participants