Conversation
|
Do we need a type |
lib/getConfig.js
Outdated
| let configObject = json.readToObjSync(pathString); | ||
|
|
||
| if (!configObject) { | ||
| if (configObject) { |
There was a problem hiding this comment.
This should be !configObject. If altPath or cwd/.sgcrc does not exist it should read the package.json
There was a problem hiding this comment.
good point, how about:
let package = json.readToObjSync(path.join(cwd, 'package.json'));
configObject = typeof package === 'object' ? package.sgc : package;
package.json
Outdated
| { | ||
| "emoji": ":white_check_mark:", | ||
| "prefix": "Test:", | ||
| "description": "Adding missing tests or correcting existing tests" |
There was a problem hiding this comment.
package.json and test/fixtures/ .sgcrc just need one or two "types" - these are just for testing, so we can keep it small 😊
.sgcrc_default are the default types the user actually see, if there is no .sgcrc or (package.json).sgc available - so this is fine
There was a problem hiding this comment.
Yes that is true.
How can we test the second if stmt for branch coverage?
If there is a sgc, present in the package.json we never get into the second stmt.
There was a problem hiding this comment.
I thought about the same, the only thing I thought of is to remove the sgc in package.json temporarily.
In the tests it could be like following:
- copy
package.jsontopackage.json.back - modify the original
package.json - test
- rm original
package.json - mv
package.json.backtopackage.json
There was a problem hiding this comment.
I think we should temporary add the sgc in the package.json. Because by default it should use the .sgcrc_default and not only one type we just have in the package.json for testing purposes.
There was a problem hiding this comment.
It will always use .sgcrc_default as default if the user did not specify any config files - the difference is process.cwd() and __dirname. But we can add it temporarily - which would be easier to manage.
Easier because we will take the config from test/fixtures/.sgcrc and add it to the package.json object. So there will be just one file to change if there would be an issue. 👍
|
Files added is not really meaningful. All of the time when you add files you do this because you add |
|
Yap exactly: we got |
test/getConfig.js
Outdated
| }).then(() => { | ||
| // restore package.json from package.json.back | ||
| fs.rename(cwd + '/package.json.back', cwd + '/package.json'); | ||
| }); |
There was a problem hiding this comment.
Quite confusing for a test with a quite long promise chain. I would suggest to use fs-extra and use its sync methods, as test perfomance is not an issue right now but readability is. Methods such as: moveSync(), writeFileSync() (not fs-extra), removeSync() , ...
test/getConfig.js
Outdated
| fs.rename(cwd + '/package.json.back', cwd + '/package.json'); | ||
| }); | ||
| fs.createReadStream(cwd + '/package.json') | ||
| .pipe(fs.createWriteStream(cwd + '/package.json.back')); |
There was a problem hiding this comment.
I know I am picky 😅, but this can be shortened to:
fs.copySync(`${cwd} /package.json`, `${cwd} /package.json.back`);
test/getConfig.js
Outdated
| fs.writeFileSync(cwd + '/package.json', JSON.stringify(packageJson)); | ||
| t.deepEqual(getConfig(), sgcrc); | ||
| fs.unlinkSync(cwd + '/package.json'); | ||
| fs.renameSync(cwd + '/package.json.back', cwd + '/package.json'); |
There was a problem hiding this comment.
I totally forgot to change the directory for the linting. You might get some errors - can you change the directory tests in (package.json).scripts.lint to test?
from
"lint": "eslint lib tests",to
"lint": "eslint lib test",|
Thanks @rudolfsonjunior |
Added all types that we discussed.