-
Notifications
You must be signed in to change notification settings - Fork 416
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
fix: Append classnames when extracting to single file #115
Conversation
Codecov Report
@@ Coverage Diff @@
## master #115 +/- ##
==========================================
+ Coverage 97.65% 97.67% +0.02%
==========================================
Files 18 18
Lines 341 344 +3
Branches 59 60 +1
==========================================
+ Hits 333 336 +3
Misses 8 8
Continue to review full report at Codecov.
|
@@ -56,6 +56,37 @@ describe('preval-extract/extractStyles module', () => { | |||
expect(writeFileSync).not.toHaveBeenCalled(); | |||
}); | |||
|
|||
it('should append classnames when writing to single file', () => { |
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.
This test case is a duplication of
it('should append styles only once if the file has not changed', () => { |
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.
not quite, as that other test doesn't test for appending stylesheets, just calling it once.
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.
You should update this one
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.
kk, will do.
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.
my bad, then move your case to with cache enabled
describe block
if (hasCachedStyles(currentFilename, data)) { | ||
return; | ||
} | ||
stylesCache[currentFilename] = data; |
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.
that's the issue, filename is always the same when { single: true, filename: styles.css }
and get's overwritten
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
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.
shouldn't it be currentFilePath
?
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.
Hm, this got me thinking, that if this path is not absolute, we need to process it through parseCurrentFilename
, otherwise we can overwrite cache of 2 unrelated files which have the same names. I'll post a followup later.
Summary
When extracting with
{single: true}
option, classnames were overwritten instead of appended.Test plan
Added a test that verifies proper behavior.