Page MenuHomePhabricator

Create a "unit-testing" framework for DOM transformers
Closed, ResolvedPublic

Description

For token transformers, we now have the transformTests.js script to help unit test individual token transformers. This lets us feed the same token streams to the JS code and the ported PHP code and (a) verify that the output token streams match (b) evaluate performance.

We need an equivalent functionality for DOM transformations. All DOM transformations now have the ability to dump the DOM before and after the transformation which can be used to generate unit test input and output for comparison on the PHP side.

parse.js script already has the ability to dump DOMs pre/post a dom-pass which can be used for testing and comparing the JS and PHP outputs. parse.js --dump=help lists the dumping options. However, this dump is primarily targeted for debugging and needs to be adapted for generating dom tests. Here is a possible approach:

parse.js already has a --genTest option. Now it accepts `--genTest dom:PASS-NAME,dom:ANOTHER-PASS-NAME --genDIrectory ../tests --genFragments true --pageName Hampi
This produces a pair of test files in the ../test directory called hampi-PASS-NAME-pre.txt and hampi-PASS-NAME-post.txt The default is to not generate fragments but that can be enabled for special reasons with --genFragments true option.

Event Timeline

ssastry triaged this task as Medium priority.Nov 9 2018, 9:18 PM
ssastry moved this task from Backlog to Prototype / Evaluation on the Parsoid-PHP board.

Change 474775 had a related patch set uploaded (by Sbailey; owner: Sbailey):
[mediawiki/services/parsoid@master] Added new genTest capabilities creating two dom dump files

https://gerrit.wikimedia.org/r/474775

I am Rical and I receiveded an email titled :
[Gerrit] mediawiki...parsoid[master]: Added new genTest capabilities creating two dom dump files
sended at 19/11/2018 à 21:40
In which I read : "Sbailey would like Rical to review this change."
I sometime read some change in gerrit, but I am not able to rigthly understand and comment them.

I am Rical and I receiveded an email titled :
[Gerrit] mediawiki...parsoid[master]: Added new genTest capabilities creating two dom dump files
sended at 19/11/2018 à 21:40
In which I read : "Sbailey would like Rical to review this change."
I sometime read some change in gerrit, but I am not able to rigthly understand and comment them.

Hey Rical ... I think @Sbailey might have added you unintentionally .. she has since removed you from it.

Change 474775 merged by jenkins-bot:
[mediawiki/services/parsoid@master] Added genTest capabilities for DOM passes

https://gerrit.wikimedia.org/r/474775

Change 476997 had a related patch set uploaded (by Sbailey; owner: Sbailey):
[mediawiki/services/parsoid@master] WIP domTest.js initial incomplete implementation

https://gerrit.wikimedia.org/r/476997

Change 476997 merged by jenkins-bot:
[mediawiki/services/parsoid@master] Implemented domTests.js for unit testing DOM transformations

https://gerrit.wikimedia.org/r/476997