-
Notifications
You must be signed in to change notification settings - Fork 95
New API #128
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
New API #128
Conversation
Necessary to make it work with node 4.
@jvanbruegge @eXon Feel free to review as well 😉 |
}) | ||
return (context, util) => util.addLoader( | ||
Object.assign({ | ||
test: context.fileType('text/css'), |
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.
Does this work with sass too?
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.
Don't think so, but never tried it to be honest... Good point 🤔
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.
If not, use a post hook to query all loaders with style loader and use that mime type
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.
I opened a follow-up issue for this: #130.
packages/typescript/index.js
Outdated
@@ -44,6 +42,7 @@ function typescript (options) { | |||
|
|||
function pre (context) { | |||
const registeredTypes = context.fileType.all() | |||
|
|||
if (!('application/x-typescript' in registeredTypes)) { |
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.
Would remove this pre hook, as it is now in the default mime types and the 2.0 update is a breaking one, so you have to update
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.
True
}) | ||
} | ||
``` | ||
|
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.
I'd add group
to this list
t.deepEqual(block(context), {}) | ||
t.deepEqual(block.post(context).module.loaders, [ | ||
t.deepEqual(block(context, { addLoader })({}), {}) | ||
t.deepEqual(block.post(context, { addLoader })({}), {}) |
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.
addLoader is a pure function, so it's usually a better idea to include/use the real one and do state based testing rather than setting it up as a spy. In general, I'd consider pushing towards doing snapshot testing for blocks, but in the meantime at least using the real utility functions would make these tests more valuable imo.
Also, I'm not entirely convinced that unit testing blocks is worthwhile. You get more bang for the buck by actually testing them in createConfig, I think.
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.
Yeah, I have got mixed feelings about unit testing the blocks, too. Integration tests are definitely worth more. But I didn't want to open another construction site right now...
The reason why I didn't use the real helpers was just that the unit test would then not only test this unit, but also the utils. Also using a spy makes testing quite easy.
But yeah, we should consider turning the block unit tests into integration tests.
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 reason why I didn't use the real helpers was just that the unit test would then not only test this unit, but also the utils. Also using a spy makes testing quite easy.
Right, but it's misusing spies imo. Spies should only be used for side effecting things. These are pure functions. It's ok to "test" them, because what you're really testing is that they do what you think they're doing in this specific context. I wouldn't even consider it an integration test. You shouldn't have things that return values be spies, it's like replacing merge
with a spy, or mapValues
.
I don't think there's anything in webpack-blocks that warrants testing w/ sinon, there are no side effects. It's all pure functions which is part of its beauty.
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.
Btw, this is a good video about spies vs mocks vs not using them https://www.youtube.com/watch?v=URSWYvyc42M
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.
I wouldn't even consider it an integration test.
It's not an integration test, right now it's a unit test. But maybe we talk past each other here. It will probably be best to turn it into an integration test, using it in createConfig()
and look at the resulting config.
Agree? Might do it in another PR, though.
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.
Right, and it would still be a unit test even if it used the real util functions. That was my point. I'd urge you to remove sinon as a dependency and do that instead (another pull is fine) or port to a test that uses createConfig
(and still remove sinon). I don't think sinon is a good fit for functional projects and I wouldn't want to encourage contributors to misuse it.
"babel": { | ||
"plugins": [ | ||
[ | ||
"transform-object-rest-spread", |
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.
I thought ava included this by default? https://github.com/avajs/ava#es2017-support
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.
I thought so, too. But it seems quite a lot of features that once were part of the es2017 preset have been removed from it recently. Object-spread isn't included anymore... :-/
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.
Ah, indeed, it's in experimental.
packages/core/src/index.js
Outdated
const configPartial = setter(context, getCompleteConfig(mergedConfig)) | ||
return merge.smart(mergedConfig, configPartial) | ||
(config, setter) => { | ||
const updateFunction = setter(context, helpers) |
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.
helpers -> util
// Now apply them to the config: Remove the existing loaders for that | ||
// file type, add the new loader and add the plugin | ||
|
||
return _addPlugin(_addLoader(_removeLoaders(prevConfig))) |
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.
good place to use group
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.
But it isn't a group of blocks, it's just three update functions... I already thought about util.aggregate([ _removeLoaders, ... ])
or something like that, but I'm hesitating adding more new stuff to util
.
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.
I mentioned flow
before, it's a lodash function. It's what you need here (though you probably don't need to pull it in from lodash unless you want to). And I'd say it's a must have. It's a key part of function composition which is what this api should drive people to.
I prefer my implementation of flow
because it flattens and removes nils allowing you to compose like this:
flow(
option && doThing(),
option2 && [doThing1(), doThing2],
doOtherThing(),
)
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.
Hmm, that might be a candidate to be included in util
...
So as far as I can see there are no immediate issues left to fix for this PR. One topic that might be considered part of this PR is: One topic that relates to this PR, but can be settled later: |
Merged it, since the open topics don't block this PR. |
Introduces the new core API. Resolves #125.
Still using
module.loaders
and webpack-merge's smart merge, though.@aaronjensen