Non cached files are not preprocessed
See original GitHub issueI noticed this because I’m using rollup (+ babel) to transpile ES2015 tests into ES5. With the ‘default’ configuration, tests are transpiled but then cached, so when I change the source, the cached version is served.
Expected behavior
Using
karma.conf.js
module.exports = function(config) {
config.set({
files: [
{ pattern: 'test/*.js', nocache: true }
],
preprocessors: {
'test/**/*.js': ['rollup']
}
I expect test files to run through the preprocessor and not being cached.
Actual behavior
Files are not cached, but are not even processed
Enviroment Details
- Karma version (output of
karma --version
): 1.1.1
The logic is defined around these lines and introduced in this commit.
Clearly the intent of the committer (@nmalaguti) was to avoid preprocessing, but I feel like nocache
is now serving two purposes
- don’t cache the file
- don’t preprocess
In my use case I’d like to have use (1.) without (2.), best of both worlds would be to have
{ pattern: '*.js', included: Boolean, watched: Boolean, served: Boolean, nocache: Boolean, preprocess: Boolean }
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:10 (4 by maintainers)
Top Results From Across the Web
ccache(1)
Clean up the cache by removing old cached files until the ... “Preprocessing failed” (if the non-precompiled header file is not available).
Read more >What is a difference between ccache preprocessor and direct ...
"direct" in "direct mode" refers to "reading header files directly without using the preprocessor". This is done because most preprocessors ...
Read more >The cache - Hugging Face
The cache. The cache is one of the reasons why Datasets is so efficient. It stores previously downloaded and processed datasets so when...
Read more >Ubuntu Manpage: ccache - a fast C/C++ compiler cache
DESCRIPTION. Ccache is a compiler cache. It speeds up recompilation by caching the result of previous compilations and detecting when the same compilation...
Read more >ccache(1): fast C/C++ compiler cache - Linux man page
Clean up the cache by removing old cached files until the specified file number ... counter "preprocessor error" (if the non-precompiled header file...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would expect
nocache
to run the preprocessor on a file everytime it is served. That would be equivalent to serving “static” files from disk.This also prevents css preprocessors that include other files from working properly. If an included file is changed, karma does not pick up on these changes and serves the old version. I think this issue should be addressed in one of two ways:
nocache
is incompatible with preprocessors that do not write to disk. The change mentioned by @johnjbarton only works, if the preprocessor writes the file to the disk, becauseserveFile
will try to read it from the disk.nocached: true
preprocessed files by preprocessing them every time they are served. I dug around the codebase a little and implemented this feature here: https://github.com/fvclaus/karma/commit/ddc74beda2b7cd3b588d02da29d34d523ed9a9d3 It flags files that are preprocessed withfile.isPreprocessed = true
. If they also havenocache
set to true, it preprocesses them withchangeFile(..., true)
and greps the new version of the file. The code is a little awkward, becausechangeFile
returns all files instead of the changed file andserveFile
does not work with files at all. I also had to forcedoNotCache = false
for preprocessed files that havenocache: true
withfile.doNotCache && !file.isPreprocessed
, otherwiseserveFile
will try to read them from the disk. Let me know if this could be a candidate for a PR and I will be happy to better integrate it into the existing codebase.@maksimr the way that preprocessing worked at the time (and may still work - I haven’t been working with karma in a while) is that each file was preprocessed once at start or on change and the result was cached in memory. If
nocache
is enabled, there is nowhere to store the result of preprocessing (unless you write it to disk, which karma doesn’t do), so preprocessing doesn’t make sense.nocache
only makes sense for files that either won’t be changing while karma runs, or will be changed by a separate process (e.g. gulp watch) and can be served up as is.The problem I was solving for with nocache was that I didn’t need potentially thousands of files being watched and cached in memory (e.g. including all of
node_modules
for somecss
files) when I knew that I would never be making changes to them and there was no processing to be done.