Repository navigation
[testharness.js] Formalize test types - #11010
Conversation
Ms2ger
left a comment
There was a problem hiding this comment.
Please do change the PR summary / commit message to clarify that this is about th.js self-tests, not all tests that use th.js.
Please do wait for jgraham to review, but this SGTM.
| must include a summary of the expected results as a JSON string within a | ||
| `<script>` tag with an `id` of `"expected"`, e.g.: | ||
|
|
||
| <script type="text/json" id="expected"> |
|
|
||
| actual = driver.execute_async_script('runTest("%s", "foo", arguments[0])' % server.url(str(self.filename))) | ||
|
|
||
| summarized = self._summarize(actual) |
There was a problem hiding this comment.
Extract everything up to and including the self._summarize() call into another helper method? (Unless you have specific plans to diverge the two methods.)
There was a problem hiding this comment.
Yes, I do have plans for these two methods to diverge further
I'm guessing you need to update a path in |
I'm happy to clarify, but I'm short on ideas. As written, the commit message body begins with the phrase, "Previously, tests for the testharness.js framework [...]" and I'm not sure how/where I can better communicate the distinction. Could you say more on how this could be improved?
Right you are |
Previously, tests for the testharness.js framework were validated according to an implicit heuristic based on the presence of a `<script>` tag. Introduce a file naming convention to make this distinction explicit. This pattern makes the validation behavior easier to understand. It also supports future additions which further differentiate the way the two test types are interpreted.
81723ec to
bfce63b
Compare
|
Strangely, GitHub.com was reporting a merge conflict with Whatever the case, that problem will block merging from the web UI, so I've rebased the branch for convenience's sake. The original version of this branch is available at: master...bocoup:testharness-tests-explicit-mode-2-prebase Do you think this is ready for |
Ms2ger
left a comment
There was a problem hiding this comment.
Please fix the last few comments, and do squash when landing.
| parser.addoption("--binary", action="store", default=None, help="path to browser binary") | ||
|
|
||
| def pytest_collect_file(path, parent): | ||
| test_type = os.path.relpath(str(path), HERE).split(os.path.sep)[1] |
There was a problem hiding this comment.
I feel a little queasy about this line, but I guess it's fine if you add a comment along the lines of "Tests are organized in directories by type".
|
|
||
| if path.ext.lower() == '.html': | ||
| return HTMLItem(str(path), parent) | ||
| return HTMLItem(str(path), test_type, parent) |
There was a problem hiding this comment.
Nit: only compute test_type if you need it.
| if self.type == 'unit': | ||
| self._run_unit_test() | ||
| elif self.type == 'functional': | ||
| self._run_functional_test() |
There was a problem hiding this comment.
else:
raise NotImplementedErrorThere was a problem hiding this comment.
Will do.
I didn't know that Python instantiates classes when they are a raised value. I'm trying to think of when that would be necessary.
That's the critical difference between this patch and the previous version. I'm not married to this one, but I did think that a filesystem-based approach would be easier to discover and use. If your preference is for the |
|
No, the filesystem-based approach is fine, but I felt there should have been a slightly more readable way to write it (which I didn't find). Anyway, this is good to go. |
|
Thanks, @Ms2ger! |
Previously, tests for the testharness.js framework were validated
according to an implicit heuristic based on the presence of a
<script>tag.
Introduce a file naming convention to make this distinction explicit.
This pattern makes the validation behavior easier to understand. It also
supports future additions which further differentiate the way the two
test types are interpreted.
@Ms2ger @tobie @gsnedders This may look familiar because we worked on a similar patch late last year: gh-8597. That fell out of sync with
master, but while I was rebasing it, I decided that a different approach would be better. Instead of detecting test type via a custom<meta>tag, this patch references the test file's location on disk. I think this will be easier for others to discover and maintain.As noted in the commit message, this patch is intended to facilitate future work. I'd like to extend the way the functional tests are interpreted. Strengthening the delineation between those tests and the unit test should limit confusion as they become more distinct.
This change is