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

fix: Append classnames when extracting to single file #115

Merged
merged 3 commits into from
Sep 22, 2017

Conversation

thymikee
Copy link
Member

Summary

When extracting with {single: true} option, classnames were overwritten instead of appended.

Test plan

Added a test that verifies proper behavior.

@codecov
Copy link

codecov bot commented Sep 22, 2017

Codecov Report

Merging #115 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/babel/preval-extract/extractStyles.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c61aa4...24e5810. Read the comment docs.

@satya164 satya164 requested a review from zamotany September 22, 2017 08:39
@@ -56,6 +56,37 @@ describe('preval-extract/extractStyles module', () => {
expect(writeFileSync).not.toHaveBeenCalled();
});

it('should append classnames when writing to single file', () => {
Copy link
Contributor

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', () => {

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk, will do.

Copy link
Contributor

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;
Copy link
Member Author

@thymikee thymikee Sep 22, 2017

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

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?

Copy link
Member Author

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.

@zamotany zamotany merged commit f738ada into master Sep 22, 2017
@zamotany zamotany deleted the fix/append-single branch September 22, 2017 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants