-
Notifications
You must be signed in to change notification settings - Fork 34
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
test: use snapshot and split into multiple files #143
Conversation
Started looking over the changes - Will review them fully over the weekend. |
- Added 'husky', and 'commitlint' dev-deps. - Ran 'npx husky init' (which in-turn, creates initial 'pre-commit' hook).
- Added 'commit-msg' hook, and (package) script.
8f661c1
to
cec0454
Compare
@marcalexiei Hey, the changes are pretty lenghty to go through - Could you summarize which tests have been updated to use snapshots, and which tests actually changed (I see a couple are using snapshots, but not all of them)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The majority of test has been converted to snapshot, the change is basically replace one or more assertions with t.snapshot
Here is the list of list which are not using snapshot and why:
test/insertStyle.test.ts
do not use snapshot because is testing just the function itselftest/options.insert.test.ts
should generate chunks with import insertStyle when insert is true
checks output. of bundle to ensure that insertStyle is used once (issue-132 - dedupe insertStyle in output files #139)
test/sourcemap.test.ts
doesn't use snapshots because are testing sourcemaps
After reviewing the changes I noticed tests in these files probably can use snapshots
test/options.output.test.ts
test/watchList.test.ts
I'll update them now.
|
.then((rslt) => { | |
t.not(squash(rslt.toString()).indexOf(expectA), -1); | |
t.not(squash(rslt.toString()).indexOf(expectB), -1); | |
}); |
Right now there isn't much we can do.
I'm going to add a code comment on options.output.test.ts
referencing this PR
# Conflicts: # package-lock.json # package.json
# Conflicts: # package-lock.json # package.json
# Conflicts: # package-lock.json # package.json
cec0454
to
36c02c2
Compare
I'm glad you noticed that bug (I had noticed it too) - Lets connect on the interwebs to discuss this PR - I'm on discord (as edlcmoose) - Note: I'm only asking because this is a large change that we should probably do in smaller pull requests also the value of changing all tests to use snapshots isn't very clear to me so was hoping you could shed light on what the pros/cons are about adapting this approach, and/or if there are any analysis that you have performed on the approach. |
For transparency and because I do not have a Discord account 😅 I will reply here:
I do not have any rush to get this merged so feel free to review when you have time 😀. Note If you stil find hard to review the changes I can close this PR and re-create smaller ones.
IMHO The main benefit is that though the snapshots you have a quick and fast way to compare the string output instead of having to search around for "expect" files that are read through
I used snapshot approach for the first time when implementing a custom webpack loader tests. An additional benefit is that they can easily updated via You can find the code here: https://github.com/marcalexiei/ractive-html-loader |
Ok, thank you for indulging me - I understand the changes better now - |
No problem 😉
Thank you! As I said there is no rush 😃. Have a good weekend! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so generally your changes look good, however they are to many to consume in one PR - You will need to separate it as follow, as well as make the review updates mentioned in the other review comments:
- One PR for dependency updates.
- One for changing all tests to use snapshots, and/or just contain updates, and,
- One for breaking the tests out into their own files.
Like this we would be able to consume the changes without requiring high cognitive load (too many things changing requires more things to keep in mind).
|
||
import sass from "../src/index"; | ||
import { | ||
TEST_UTILS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for TEST_UTILS, could you change the exports to just the methods themselves - Since they already live at 'test/utils' it becomes redundant to export the object TEST_UTILS
- What would be good here would be to rename squash
to stripNewLines
, or something similar!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, getOutputFirstChunkCode
could just be getFirstChunkCode
- since the declaration would read getFirstChunkCode(output: ...) ...
- Would also change output
to chunks
, and/or, outputChunks
for more correlation between what output
constants actually represent.
@marcalexiei Also, the dependency updates can go together with the changing the tests PR. |
Ok... |
Part of #141
Unit tests updates
Split tests between files
Unit tests have been divided into multiple files and now use snapshots.
This should improve readability and, hopefully, maintenance efforts.
All common utilities and variables are now exported by
test/utils/index
fileinsertStyle.test.ts
– replacejsdom
withhappy-dom
Since the test are quite simple I opted out to switch
jsdom
tohappy-dom
(less dependencies and faster)Additional changes
ava
@ava/typescript
nyc
sinon
@types
forsinon
icss-utils