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

Testing: Add missing unit tests to packages #13812

Closed
2 of 25 tasks
gziolo opened this issue Feb 11, 2019 · 8 comments
Closed
2 of 25 tasks

Testing: Add missing unit tests to packages #13812

gziolo opened this issue Feb 11, 2019 · 8 comments
Labels
Needs Dev Ready for, and needs developer efforts npm Packages Related to npm packages [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality

Comments

@gziolo
Copy link
Member

gziolo commented Feb 11, 2019

Raised by @georgestephanis on WordPress.org Slack (link requires registration at https://make.wordpress.org/chat/):
https://wordpress.slack.com/archives/C02QB2JS7/p1549826915372300

Some of the students I'm mentoring like Ashwin are interested in contributing more unit tests to Gutenberg -- is there any list somewhere of areas that need better test coverage?

There is no list like this. There used to be a similar task in the past but we closed it as it became very outdated. I can't find the link at the moment.

This is going to be a living document where we should collectively collect all API methods that are exposed in WordPress packages but aren't unit tested. I would prefer to skip UI components in this issue as they are usually harder to cover with tests.

Please make sure to comment on the issue if you plan to work on adding unit tests. Remember about sharing all details of the work planned to avoid duplication of efforts. Thanks!

  1. @wordpress/autop
  2. @wordpress/blob
    • createBlobURL
    • getBlobByURL
    • revokeBlobURL
  3. @wordpress/compose
    • ifCondition (complex)
    • withSafeTimeout (complex)
  4. @wordpress/date
    • format (complex)
  5. @wordpress/dom
    • computeCaretRect
    • documentHasSelection
    • getOffsetParent
    • getScrollContainer
    • getRectangleFromRange
    • isEntirelySelected
    • isVerticalEdge
    • placeCaretAtVerticalEdge
    • tabbable.isTabbableIndex
  6. @wordpress/keycodes
  7. @wordpress/priority-queue
    • createQueue (complex++)
@gziolo gziolo added Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality labels Feb 11, 2019
@dsab123
Copy link

dsab123 commented Feb 18, 2019

I'd be happy to look at some of these! I've never used jest before 😍

I'm working on writing a test for createBlobURL() right now. I'll probably end up using something like babel-rewire-plugin to mock some non-exported properties I'd like to get access to, if that's alright. Or maybe there's a better way?

const cache = {};

export function createBlobURL( file ) {
	const url = createObjectURL( file );

	cache[ url ] = file;

	return url;
}

@gziolo
Copy link
Member Author

gziolo commented Feb 19, 2019

I'll probably end up using something like babel-rewire-plugin to mock some non-exported properties I'd like to get access to, if that's alright. Or maybe there's a better way?

Is that necessary to verify internals through mocking library? I think getBlobByURL operates on cache only, so you can use it as a way to access the internal cache.

@dsab123
Copy link

dsab123 commented Feb 19, 2019

Well, that would work. But then the test does not strictly test the functionality of createBlobURL(). The test could fail in the future if getBlobByURL() changes in some way, say, no longer writes to the cache.

What's the likelihood of getBlobByURL() changing? If its not likely then I can test createBlobURL() using it, but it still makes me a bit uncomfortable..

@gziolo
Copy link
Member Author

gziolo commented Feb 19, 2019

Well, that would work. But then the test does not strictly test the functionality of createBlobURL(). The test could fail in the future if getBlobByURL() changes in some way, say, no longer writes to the cache.

Those methods aren't pure and therefore are hard to test. I wouldn't spend too much time on it. Very basic verification is fine as this is a tiny wrapper over URL API.

@dsab123
Copy link

dsab123 commented Feb 19, 2019

👍 okie doke! I'll get a few tests in for blob sometime this afternoon or tomorrow. Thanks @gziolo !

@dsab123
Copy link

dsab123 commented Feb 20, 2019

I think this is related: https://stackoverflow.com/a/52969731 and jestjs/jest#7645; thinking of some possible solutions.

In a nutshell: jest ships with jsdom, which does not have support for URL.createObjectURL and URL.revokeObjectURL as per jsdom/jsdom#1721

@ashwin-pc
Copy link
Contributor

Thanks for the list @gziolo

Ill take a stab at the keycodes test case first.

@gziolo gziolo added the Needs Dev Ready for, and needs developer efforts label Apr 10, 2019
@gziolo gziolo added the npm Packages Related to npm packages label May 9, 2020
@gziolo gziolo added the [Status] In Progress Tracking issues with work in progress label May 15, 2020
@gziolo
Copy link
Member Author

gziolo commented Jun 14, 2022

I don't see any movement on this issue. Let's close this one and work on adding more unit tests as we update the functionality rather than independently from production changes.

@gziolo gziolo closed this as completed Jun 14, 2022
@gziolo gziolo removed Good First Issue An issue that's suitable for someone looking to contribute for the first time [Status] In Progress Tracking issues with work in progress labels Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Dev Ready for, and needs developer efforts npm Packages Related to npm packages [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

No branches or pull requests

3 participants