-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Use Blockly consistently in mocha tests #7224
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
Comments
BackgroundTests can ideally be divided into roughly three categories:
In the case of system tests of a software library like Blockly, it behoves one to test against the API that one is shipping. (If it's also a UI library, then one should additionally also be testing the UI—in our case the DOM elements Blockly creates and manages.) So any kind of system tests we are doing ought to be against the exports of In the case of unit tests, it is generally preferable to test against only the module containing the code being tested. This enables the unit tests for a single module to be run without having to compile/load any other modules—most test frameworks have the ability to specify exactly what tests should be run, making it convenient to quickly run the tests for a particular module while working on it, without having to repeatedly run the entire test suite. It also allows testing of interfaces that are not exposed by the public API (which for an app, rather than a library, is basically all of them). (Aside: to facilitate keeping tests and tested code in sync, unit tests are often kept very close to the code being tested. The Go convention is to keep the tests for Blockly is in the curious situation of being a library and still maintaining most of its original
So we have a lot of unit tests that are written against More recently, some test modules have been created/modified to directly import submodules. This is some cases necessary in order to test internal-only APIs (or use test-only APIs for mocking/stubbing), but in other cases (as in the code in #7200) this has happened because of some confusion about what the appropriate approach is. RecommendationsSpecifically on the topic of imports, I would recommend that we adopt the convention that unit tests directly import the module containing the code under test, while system tests continue to test against the top-level API ( I also recommend we:
|
I've moved the work in Christopher's comment above into a new issue: #7250 This issue covers only the removal of the |
To be clear: the build warnings are not due to direct I think due consideration of #7250 remains a prerequisite to this issue, however, because our tests make extensive use of direct imports (the preponderance of which are valid and do not generate warnings):
|
OK, having investigated the invalid
I note that, should we want to convert the tests to TypeScript, we will need to pass |
This resolves the warnings generated during buildDeps by closure-make-deps. This commit does not attempt to address google#7224 or otherwise rationalise the imports and usage thereof.
* fix(tests): Fix invalid import paths in mocha tests This resolves the warnings generated during buildDeps by closure-make-deps. This commit does not attempt to address #7224 or otherwise rationalise the imports and usage thereof. * fix(tests): Fix failing context menu item test Test appears to have been wrong: Block.prototype.getIcon is typed as getIcon<T extends IIcon>(/* ... */): T | undefined and documented as "@returns The icon with the given type if it exists on the block, undefined otherwise." * refactor(tests): Clean up inconsistent usage of CommentIcon Tweak the test files touched by PR #7200 to be consistent with existing usage of Blockly.icons.CommentIcon instead of importing this separately.
Check for duplicates
Description
In mocha test files, sometimes we use
Blockly.foo
and sometimes useimport {foo} from '../build/.......'; foo
we shouldn't use both styles; that's just confusing.
Christopher says there are arguments to both. @cpcallen please elaborate in the comments :)
Without hearing those arguments, I would prefer using
Blockly.foo
because ideally the tests would use Blockly the same way users do and users don't import our individual files.Reproduction steps
Stack trace
No response
Screenshots
No response
Browsers
No response
The text was updated successfully, but these errors were encountered: