Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Testing

Sean McGregor edited this page Oct 1, 2013 · 14 revisions

The components comprising the Privly system often require different testing strategies, but they can effectively be divided into two groups: JavaScript and Not JavaScript.

JavaScript Testing

JavaScript testing is nearly unheard of in the browser extension world. To make things more challenging, Privly integrates with (1) the web, (2) many different content servers, (3) many different extensions, and (4) many different Injectable Applications.

For consistency accross all the JavaScript projects, Privly is using the Jasmine testing library for running tests. Jasmine's testing syntax is out of scope for this document since there are ample online resources for writing Jasmine tests.

We don't change the way Jasmine works, but for consistency we currently rely on the console reporter which sends test results directly to the JavaScript console.

All test specs are bundled with the application that they are testing and can be referenced by a relative path. By default all Privly JavaScript projects should have access to a version of a meta_loader.js script. The meta loader performs several important tasks for the application being tested. First it assumes the presence of the JavaScript and meta tags as below:

<script type="text/javascript" src="../shared/javascripts/meta_loader.js">
</script>
<meta name="PrivlySpec" content="test/some_tests.js,more_tests.js">

The meta_loader.js finds the PrivlySpec meta tag and uses it to inject the appropriate testing scripts and specs.

Meta Loader Process

  1. A developer issues runTests() in a script or in the JavaScript console.
  2. The meta_loader.js adds script tags to the HTML document for jasmine.js and jasmine.console_reporter.js
  3. The meta_loader.js finds the PrivlySpec meta tag and adds scripts with the paths of the content attribute's CSV. For example, in the meta tag displayed above, JavaScripts will be added for test/some_tests.js and more_tests.js.
  4. The meta_loader.js finally adds one more script to execute the defined specs.
  5. Test results are reported to the console.

Two types of code bases make heavy use of the meta loader approach.

Injectable (AKA Privly) Applications

Testing Privly applications fully can be challenging because you have to account for differences between the platform types they may run on. In practice you can usually test against the platform you are developing with, and easily add support for additional platforms.

Browser Extensions

The chrome extension currently uses the meta loader approach, but the Firefox extension does not currently integrate any testing code.

Not JavaScript Testing

test.privly.org

The Privly extensions integrate with the entire web, which is difficult to test. To test the detection of Privly-type links accross the web, we have a web app available at test.privly.org that contains the cases Privly currently tests for. When adding tests to this repository do not add the specific case as you found it. Instead, you should add a generalized test case that could be found on any website. The Privly extensions do not currently integrate explicitly with any website.

Content Server

The Privly Content server is currently implemented in Rails, which has a well-conventioned approach to testing. You can take a look at the current test coverage on the privly-web repository.

Clone this wiki locally