#25088 closed task (blessed) (fixed)
password-strength-meter.js should have unit tests
Reported by: | jorbin | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 3.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Unit Tests | Keywords: | |
Focuses: | Cc: |
Description
As discussed in IRC, our goal is to have unit testable javascript. Thepassword-strength-meter.js file will serve as our initial testbed for testing.
This file was chosen since there will likely be some changes to it in 3.7 and it is small and already largely testable.
Attachments (9)
Change History (43)
#8
follow-up:
↓ 9
@
11 years ago
this works great and is a nice template for writing future tests. thanks! i'm almost afraid to ask, why are you leaving off semicolons for each line?
#9
in reply to:
↑ 8
;
follow-ups:
↓ 10
↓ 13
@
11 years ago
Replying to adamsilverstein:
this works great and is a nice template for writing future tests. thanks! i'm almost afraid to ask, why are you leaving off semicolons for each line?
Semicolons are redundant. http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding
#10
in reply to:
↑ 9
;
follow-up:
↓ 11
@
11 years ago
Replying to jorbin:
Semicolons are redundant. http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding
One of the things mentioned in that article was that some linters, while working fine with no semi-colons, have a hard time with the comma first approach. It looks like you use that format, have you had any issues with linting?
#11
in reply to:
↑ 10
;
follow-up:
↓ 12
@
11 years ago
Replying to aaroncampbell:
One of the things mentioned in that article was that some linters, while working fine with no semi-colons, have a hard time with the comma first approach. It looks like you use that format, have you had any issues with linting?
Using jshint with laxcomma set to true it is never a problem.
#12
in reply to:
↑ 11
@
11 years ago
Replying to jorbin:
Using jshint with laxcomma set to true it is never a problem.
Sweet! I didn't know about the laxcomma option. For anyone interested: http://www.jshint.com/docs/options/#laxbreak
#13
in reply to:
↑ 9
@
11 years ago
Replying to jorbin:
Semicolons are redundant. http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding
Sure, but please follow existing core style. This also includes commas at the end of statements.
#16
@
11 years ago
Based on duck_'s suggestion, I added a bunch (34) of test passwords from zxcvbn https://github.com/lowe/zxcvbn/blob/master/test/test.coffee
#17
@
11 years ago
It'd also be good to have a test to check the user_input
field to make sure that any extra words that are passed are penalized. Currently that's broken because of the modifications that were made to zxcvbn, so a unit test would help make sure that doesn't happen again.
I'm uploading a patch with that added. Note that the test currently fails, which is the expected behavior since Jon's latest patch hasn't been committed yet.
password-strength-meter.js also needs some reworking around the JS coding standards -- it's using spaces instead of tabs, missing whitespace around parenthesis, etc -- but I don't have time for that tonight.
#27
in reply to:
↑ 26
@
11 years ago
- Resolution set to fixed
- Status changed from new to closed
Replying to jorbin:
I think we can close this since we do now have unit tests and that any new tests for password-strength-meter.js we wish to add can be new tickets.
Indeed.
#28
follow-up:
↓ 29
@
11 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Just one more clean-up/spacing/typo patch in 25088-spacing.patch.
#29
in reply to:
↑ 28
@
11 years ago
Replying to TobiasBg:
Just one more clean-up/spacing/typo patch in 25088-spacing.patch.
Nice, I think it's much more readable that way :)
In the "username in password should be penalized" test, though, I think variables that aren't assigned a value are supposed to be on a single line: http://make.wordpress.org/core/handbook/coding-standards/javascript/#the-var-keyword
#31
@
11 years ago
It seems that jQuery uses });
, not } );
, and that seems to be very common for jQuery-like code (including our JS), so we should probably continue to do that.
Our (and jQuery) style also appears to be i++
, not ++i
. There is a space added after a +
at the end of the diff, but not before it. (Look for '+
.) Looks good otherwise!
#32
@
11 years ago
Argh, those +
es :-)
Refreshed patch fixes ++i
and the '+
.
I'm still unsure about the });
to be honest though... That kind of contradicts spaces in brackets.
test( 'whatever', function() { ... });
looks wrong.
However, 25088-spacing-braces.patch will change that, too, whereas 25088-spacing.patch will not.
My patch is up and it contains four tests. Based on nacin's comments during IRC that we would likely be switching to zxcvbn.js for the internals of this function, I didn't test as much as could because what is a "good" password now may not be one with the improved checking.
I suggest using this in combination with the patch up on #25096 to make the testing easier.