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

Add unit tests and improve page identification logic #1

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

thelearned1
Copy link

What

This PR makes several improvements to testing, testability, and to the logic around which Wikia/Fandom pages correspond to which UESP pages.

Why

The overarching goal is to improve UX and to generally increase the utility of what is already an awesome extension.

That said, I do recognize that this PR is somewhat out of the blue. It seemed to me that there is already some logic in the present version of the extension that attempts to correctly identify the UESP namespace of a given ESWiki page based on its title. However, because the default strategy is to search UESP for whatever title is identified, the current iteration has some drawbacks for pages of certain types. My additions try to reduce some of those drawbacks.

As evidenced by the provided tests, this has been somewhat successful (though admittedly I wrote them :-P). Coverage at identifying the exact correct UESP name, or name that redirects to correct UESP page, increases from 27 to 96 of 274 pages (9.8% to 35%). See the "Testing" section for a thorough breakdown and description of my testing approach.

How

  • Separate out the logic for generating a page name into a function (for testability, maintainability, and elegance).
  • Create build script for recombining function and module into background script (as Firefox does not currently support loading background scripts as ES6 modules in extensions)
  • Add Jest unit tests for the aforementioned function
  • Add additional heuristics for determining which UESP page should result from a given ESWiki url in function:
    • If an ESWiki page is in the "Portal" namespace and contains the name of a game X, redirect to the UESP page X:X (e.g. "Portal:Skyrim" redirects to "Skyrim:Skyrim")
    • If the user navigates to a Skyrim Wiki page, send them to the corresponding page in the "Skyrim" UESP namespace (e.g. https://skyrim.fandom.com/wiki/Guild_Master's_Gloves searches UESP for the page "Skyrim:Guild Master's Gloves")
    • If the user navigates to the home page of the Skyrim wiki, they are redirected to the Skyrim homepage on UESP (Skyrim:Skyrim)
    • If the user navigates to the home page of the Elder Scrolls wiki, they are redirected to the main page of the UESP (https://en.uesp.net/wiki/Main_Page)

Testing

I add tests only for the function that maps ES Wiki pages to UESP pages, since the rest of the extension remains unchanged.

There are three categories of tests from four data sources:

  1. Tests of ES Wiki page names from a set of 200 random ES Wiki pages (collected via the Mediawiki API)
  2. Tests of Skyrim Wiki page names from a set of 50 random Skyrim Wiki pages (collected via the Mediawiki API)
  3. Tests of "special" pages on either wiki:
    1. All pages on the ES wiki in the "Portal" namespace
    2. A set of 9 possible URLs for the home page of the ES and Skyrim wikis

Tests were run with Jest, and are located in the __tests__ directory.

Results

Results for the original extension were as follows:

__tests__/randomPage.test.js
  random elderscrolls.fandom.com pages: 
     PASS:  27
     FAIL: 173
    TOTAL: 200

__tests__/skyrimWiki.test.js
  random skyrim.fandom.com pages: 
     PASS:   0
     FAIL:  50
    TOTAL:  50

__tests__/homepage.test.js
  elderscrolls.fandom.com portal pages:
     PASS:   0
     FAIL:  15
    TOTAL:  15
  URLs that point to the main page of either wiki:
     PASS:   0
     FAIL:   9
    TOTAL:   9

Test Suites: 3 failed, 3 total
Tests:       247 failed, 27 passed, 274 total
Snapshots:   0 total
Time:        0.89 s
Ran all test suites.

Results for the variation in this PR:

__tests__/randomPage.test.js
  random elderscrolls.fandom.com pages: 
     PASS:  27
     FAIL: 173
    TOTAL: 200

__tests__/skyrimWiki.test.js
  random skyrim.fandom.com pages: 
     PASS:  47
     FAIL:   3
    TOTAL:  50

__tests__/homepage.test.js
  elderscrolls.fandom.com portal pages:
     PASS:  14
     FAIL:   1
    TOTAL:  15
  URLs that point to the main page of either wiki:
     PASS:   8
     FAIL:   1
    TOTAL:   9

Test Suites: 3 failed, 3 total
Tests:       178 failed, 96 passed, 274 total
Snapshots:   0 total
Time:        0.971 s, estimated 1 s
Ran all test suites.

I aggregated these data for the purpose of this PR; the raw outputs of the test suite can be found in the attachments under "testResults-old.txt" and "testResults-revised.txt", respectively.

Supplemental Note: Testing Methodology

I should start by noting that my baseline assumption was that the extension is correct only when it has successfully redirected an ESWiki page to the most closest-corresponding UESP page. Thus, I considered a case where the correct UESP page appeared in the search results a failure for the purpose of unit testing, despite this having only a slight negative impact on UX. That said, I constructed my tests such that a test case would pass if any of the following was true:

  1. There is a single UESP page corresponding to the ES Wiki page, and the UESP wiki is searched for the title of that page exactly (and thus sent to the page). Example: "Hammerfell (Arena)" is redirected to "Arena:Hammerfell", and "Yashurah" is redirected to "Online:Yashura".
  2. There are multiple UESP pages corresponding to a single ES Wiki page, and the UESP wiki is a searched for a search term which includes all such pages in the search results. Example: "The Vagaries of Magicka" results in searching for "The Vagaries of Magicka" (the ESWiki page includes information about this book in both Morrowind and Battlespire)
  3. There is no UESP page corresponding to the ES Wiki page, but the relevant information is contained within a different page, and the extension redirects to this page. Example: "Steel Claymore (Arena)" redirects to "Arena:Claymores", and "Characters (Dragonborn)" redirects to "Skyrim:People"
  4. There is no UESP page corresponding to the ES Wiki page and the relevant information is not found anywhere on the UESP wiki; the extension does not redirect anything. Example: Copperhouse Manor (a Daggerfall dungeon) does not have a UESP page and is not included on any of the UESP lists of Daggerfall dungeons.

testResults-revised.txt
testSummary-old.txt

Ned Watson and others added 27 commits February 26, 2023 15:53
On the homepage of the Elder Scrolls wiki, there are several links
which point towards main pages for each Elder Scrolls game.  These
pages have titles of the form "Portal:[Elder Scrolls Game]".  In UESP,
the corresponding page has the title '[Game]:[Game]', and there is no
page with a title matching /^Portal:/ in all of the UESP wiki.

This commit is intended to address this issue by adding another phase
in the generation of the redirect link where, if the Wikia page name
matches the pattern /^Portal:(.+)$/, the user is redirected to the
page /\1:\1/, i.e. the UESP namespace is whatever the Wikia page is
called in the Wikia "Portal" namespace.
This commit aims to address another major category of pages which the
original extension leaves unaltered: typically, pages on the Skyrim
wiki will belong to the "Skyrim:" namespace on the UESP wiki.

Doing this cleanly requires a significant refactor of the code as
previously written.  As a result, the namespace and page name are now
determined seperately, rather than all being found at once with
a single regex.  This has not caused any new bugs to emerge, at least
not in my testing.

Subsequent to this commit, two more changes are expected:
* Tests will be created to verify that my revisions have not created
  any major bugs
* One additional edge case will be accounted for --- the case when
  the user navigates directly to "elderscrolls.fandom.com" or
  "skyrim.fandom.com", which should redirect to the UESP home page
  and the Skyrim mainspace portal, respectively.
This commit creates unit tests for the procedure for coming up with
a title for the redirected page.  redirect page title.  This required
changes in three distinct stages:

First, I refactored out this procedure into a separate function, now
located in the file `getUespPage.js`.

Second, because Firefox does not presently support modules in
extensions, this is packaged (along with `background-module.js`) into
the new background script at build time using esbuild (now registered
as a dev dependency).

Third, I added JestJS unit tests and corresponding test cases stored
in JSON format in the newly-created `__tests__` directory.  This also
necessitated the creation of a second node script, `node test`.  When
this script is run, test results are output to `testResults.txt`
(which is untracked).
Because there are now modules installed via Node Package Manager, it
is probably advisable to have a .gitignore file that excludes
node_modules and the output of the test script.  This commit adds
such a file.
This commit fixes an issue where, if the user navigates to
'skyrim.fandom.com' or 'elderscrolls.fandom.com' directly, instead of
being correctly redirected to the UESP pages 'Skyrim:Skyrim' or
'Main Page', the wiki is instead searched for the string '/'.
@thelearned1
Copy link
Author

The README will also need to be updated to reflect changes in how the extension is built, but I will wait until I have a response on this PR first. Sorry — totally spaced on that!

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

Successfully merging this pull request may close these issues.

1 participant