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

Initial unit tests for front-end framework #4576

Merged
merged 17 commits into from Sep 25, 2019
Merged

Conversation

bennothommo
Copy link
Contributor

What this does

This is a proof-of-concept for unit tests for our front-end JavaScript libraries and frameworks. This current implementation uses an NPM pipeline to test the framework.js file that is made available to the themes.

The pipeline leverages jsdom to create a virtual DOM to test the scripts and HTML in a fake environment, and mocha and chai to run and assert the test cases.

image

What's included

At this stage, there's just a single test case file for framework.js which can be found in tests/js/cases/system/framework.test.js. In addition, a helper module has been set up to quickly create a fake DOM, found in tests/js/helpers/fakeDom.js.

Future applicability

Ideal candidates for future application of this testing framework would be our form widgets that are controlled primarily through JavaScript, such as the repeater and datatable widgets.

How to test this out

Before starting, you will need Node.js and NPM installed - https://nodejs.org/en/ for more information on this.

  1. Checkout the wip/js-unit-tests branch.
  2. Run npm i to install the necessary dependencies as defined in package.json.
  3. Run npm run test to run the test cases. The test cases can be found in tests/js/cases.

Other changes

One minor change was made to the real framework.js - changing a redirect from window.location.href to window.location.assign, so that it could be mocked in the tests (JS properties cannot be easily mocked). This should have no effect on the functionality.

@LukeTowers LukeTowers added this to the v1.0.459 milestone Aug 27, 2019
@w20k
Copy link
Contributor

w20k commented Sep 24, 2019

@bennothommo could you update Travis? I think we could merge this one after a quick review :)

@bennothommo
Copy link
Contributor Author

@w20k All sync'd up :)

@w20k
Copy link
Contributor

w20k commented Sep 25, 2019

LGTM, @bennothommo. Awesome work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants