#25 Adding automated test suite
Merged by quidam. Opened by gioma1.
gioma1/librejs testing  into  master

Download 25.patch

This PR adds an extensible, BDD, Jasmine-based test suite for the HTML processor, the external script processor and the external license checker (web labels) components.

From the new "TESTING" section of the README:

An automated test suite runs automatically in its own tab whenever the extension is loaded as a "temporary add-on" from about:debugging.
Otherwise (if included in the xpi, see BUILD above) it can be launched from the UI by clicking the [Automated self test...] button.

1 new commit added

  • Restored testing page tab removal after completion.

I needed to make these changes for it to work correctly:

--- a/test/spec/LibreJSSpec.js
+++ b/test/spec/LibreJSSpec.js
@@ -177,7 +177,7 @@ describe("LibreJS' components", () => {
     beforeAll(async () => {
       let documentUrl = tab.url;
       let args = {tabId: tab.id, frameId: 0, documentUrl};
-      let resolve = url => new URL(url, documentUrl).href;
+      let resolve = url => new URL(browser.extension.getURL(url), documentUrl).href;
       check = async url => await ExternalLicenses.check(Object.assign({url: resolve(url)}, args));
       await browser.tabs.executeScript(tab.id, {
         file: "/content/externalLicenseChecker.js"
@@ -185,22 +185,22 @@ describe("LibreJS' components", () => {
     });
     it("should recognize free licenses", async () => {
-      let scriptInfo = await check("jquery.js");
+      let scriptInfo = await check("/test/resources/jquery.js");
       console.debug(scriptInfo);
       expect(scriptInfo.free).toBeTruthy();
     });
     it("should accept scripts if any of multiple licenses is free", async () => {
-      let scriptInfo = await check("app-trilicensed.js");
+      let scriptInfo = await check("/test/resources/app-trilicensed.js");
       console.debug(scriptInfo);
       expect(scriptInfo.free).toBeTruthy();
     });
     it("should block scripts declaring only proprietary license(s)", async () => {
-      let scriptInfo = await check("proprietary.js");
+      let scriptInfo = await check("/test/resources/proprietary.js");
       console.debug(scriptInfo);
       expect(scriptInfo.free).toBeFalsy();
     });
     it("should block scripts not declaring any license", async () => {
-      let scriptInfo = await check("tracker.js");
+      let scriptInfo = await check("/test/resources/tracker.js");
       console.debug(scriptInfo);
       expect(scriptInfo).toBeNull();
     });

Other than that, excellent work!

I needed to make these changes for it to work correctly:

Really strange: documentUrl being tab.url (an absolute, full, URL including protocol), new URL(relativeURL, documentURL) should have worked correctly anyway (as it actually did in my environment).
If we use browser.extension.getURL() with absolute URLs like "/test/resources/tracker.js" we can do without new URL(...).href, which is redundant.
But I still find the old approach slightly more elegant and DRY, and I'm curious about what's broken in the original patch: did you try it both in about:debugging and in the XPI?

it should be noted that there is a comprehensive test suite in the librejs codebase already that was used for v0.6 - its test are probably still 95% relevant so it may save a lot of guess-work by converting them to whatever new testing tool is used - it is on the 'legacy' branch now which was the previous 'master' branch

there is an open task for that on savannah

https://savannah.gnu.org/task/?14616

1 new commit added

  • Work around for documentUrl = tab.url = about:blank if tests are launched from XPI

rebased onto 9adcb36524c91da63e99ec747707ef10f57e4171

rebased onto 7ef9967c8a17215575be6dca47fbddcd614bafbe

Pull-Request has been merged by quidam

Metadata