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
refactor(server): refactor bundleResource in lib/server.js #3029
refactor(server): refactor bundleResource in lib/server.js #3029
Conversation
lib/server.js
Outdated
function bundleResource (inPath, outPath) { | ||
if (fs.existsSync(outPath)) { |
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.
Moved responsibility to check if outPath
file already exists to bundleResource method.
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.
Please put this comment in the git commit description.
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 mean pull request description ?
if (fs.existsSync(karmaJsPath) && fs.existsSync(contextJsPath)) { | ||
startWebServer() | ||
} else { | ||
this.log.info('Front-end scripts not present. Compiling...') |
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 whole else
block was actually not covered by unit 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.
So this test does not work?
karma/test/unit/server.spec.js
Line 113 in 31d9a08
it('should compile static resources on first run', function (done) { |
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.
Sorry, I was in a hurry. True, this test covers bundleResource
invoke in else
block, but it was possible to remove this line:
Line 181 in 642b177
.then(startWebServer) |
and no unit test fails
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.
Now that I look more carefully the else
case test is not correct because fs
is not injected and the test runs in the same filesystem location every time. If the file system has the static files from a previous run or from a use of karma the test will pass even if bundling code does not work.
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've updated it a bit, now everything should be tested.
lib/server.js
Outdated
function bundleResource (inPath, outPath) { | ||
if (fs.existsSync(outPath)) { |
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.
Please put this comment in the git commit description.
lib/server.js
Outdated
process.exitCode = 1 | ||
process.kill(process.pid, 'SIGINT') | ||
return Promise.all([ | ||
bundleResource(path.join(__dirname, '/../client/main.js'), path.join(__dirname, '/../static/karma.js')), |
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 think the code would be clearer if you create function to compute the paths:
bundleResource(['/../client/main.js', '/../static/karma.js'].map(absPath));
If you also pass the fs
:
bundleResource(fs, ['/../client/main.js', '/../static/karma.js'].map(absPath));
then we can unit test the bundleResource()
properly.
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.
Maybe a bit other way, but done :)
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.
Thanks!
Pull request refactor code around
static/context.js
andstatic/karma.js
bundling. Main changes:browserify
intolib/utils/bundle-utils
BundleUtils.bundleResourceIfNotExist
method