Skip to content

[testharness.js] Formalize test types - #11010

Merged
Ms2ger merged 4 commits into
web-platform-tests:masterfrom
bocoup:testharness-tests-explicit-mode-2
May 24, 2018
Merged

Ms2ger merged 4 commits into
web-platform-tests:masterfrom
bocoup:testharness-tests-explicit-mode-2

Conversation

@jugglinmike

@jugglinmike jugglinmike commented May 15, 2018 •

Copy link
Copy Markdown
Contributor

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 Reviewable

@jugglinmike
jugglinmike requested review from Ms2ger, gsnedders and tobie May 15, 2018 15:25
@wpt-pr-bot
wpt-pr-bot requested review from ayg and jgraham May 15, 2018 15:25

@Ms2ger Ms2ger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread resources/test/README.md Outdated
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">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: indentation is odd


actual = driver.execute_async_script('runTest("%s", "foo", arguments[0])' % server.url(str(self.filename)))

summarized = self._summarize(actual)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract everything up to and including the self._summarize() call into another helper method? (Unless you have specific plans to diverge the two methods.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I do have plans for these two methods to diverge further

@Ms2ger

Ms2ger commented May 15, 2018

Copy link
Copy Markdown
Contributor
ERROR:lint:resources/test/tests/functional/add_cleanup.html:45: setTimeout used; step_timeout should typically be used instead (SET TIMEOUT)
ERROR:lint:resources/test/tests/functional/api-tests-1.html:174: setTimeout used; step_timeout should typically be used instead (SET TIMEOUT)
ERROR:lint:resources/test/tests/functional/api-tests-1.html:181: setTimeout used; step_timeout should typically be used instead (SET TIMEOUT)
ERROR:lint:resources/test/tests/functional/api-tests-1.html:185: setTimeout used; step_timeout should typically be used instead (SET TIMEOUT)
ERROR:lint:resources/test/tests/functional/generate-callback.html:15: generate_tests used (GENERATE_TESTS)
ERROR:lint:resources/test/tests/functional/generate-callback.html:21: generate_tests used (GENERATE_TESTS)
ERROR:lint:resources/test/tests/functional/generate-callback.html:31: generate_tests used (GENERATE_TESTS)
ERROR:lint:resources/test/tests/functional/generate-callback.html:42: generate_tests used (GENERATE_TESTS)
ERROR:lint:resources/test/tests/functional/generate-callback.html:53: generate_tests used (GENERATE_TESTS)
ERROR:lint:resources/test/tests/functional/worker.js:25: setTimeout used; step_timeout should typically be used instead (SET TIMEOUT)

I'm guessing you need to update a path in lint.whitelist.

@jugglinmike

Copy link
Copy Markdown
Contributor Author

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.

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?

I'm guessing you need to update a path in lint.whitelist.

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.
@jugglinmike
jugglinmike force-pushed the testharness-tests-explicit-mode-2 branch from 81723ec to bfce63b Compare May 21, 2018 17:58
@jugglinmike

Copy link
Copy Markdown
Contributor Author

Strangely, GitHub.com was reporting a merge conflict with master that I could not reproduce locally. My best guess is that we were experiencing the situation reported in this GitHub support ticket--that the conflict has been resolved since the conflict detection logic last ran.

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 master, @Ms2ger?

@Ms2ger Ms2ger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

Comment thread resources/test/conftest.py Outdated

if path.ext.lower() == '.html':
return HTMLItem(str(path), parent)
return HTMLItem(str(path), test_type, parent)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: only compute test_type if you need it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

if self.type == 'unit':
self._run_unit_test()
elif self.type == 'functional':
self._run_functional_test()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else:
    raise NotImplementedError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jugglinmike

Copy link
Copy Markdown
Contributor Author

I feel a little queasy about this line,

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 <meta> tag-based solution (and you're up for another round of review), I'd be happy to close this and rebase that patch. Let me know!

@Ms2ger

Ms2ger commented May 24, 2018

Copy link
Copy Markdown
Contributor

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.

@Ms2ger
Ms2ger merged commit f39e58d into web-platform-tests:master May 24, 2018
@jugglinmike

Copy link
Copy Markdown
Contributor Author

Thanks, @Ms2ger!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants