-
Notifications
You must be signed in to change notification settings - Fork 110
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
Overwrites default npm init test script on setup #293
Conversation
@@ -86,6 +86,9 @@ module.exports = (config, flags, args) => { | |||
commands = uniq(commands.concat(tempScripts)); | |||
} | |||
|
|||
// This is the default test script added by 'npm init'. | |||
const npmInitDefaultTestScript = 'echo \"Error: no test specified\" && exit 1'; // eslint-disable-line no-useless-escape |
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 eslint considers it a "useless escape" because the escape character needs to be escaped, i.e., this should be 'echo \\"Error...'
. could you write an end to end test (in e2e_tests/tests
) to verify?
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.
(or, alternately, it just ignores the escape character, in which case it's ok to omit the escapes from npmInitDefaultTestScript
and remove the eslint-disable)
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.
Hi @jaredmcdonald, the npm init
default test script has the escape characters in it, and I wanted to check for that string exactly. I think this may be a valid use case for disabling the lint rule on this line.
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.
@aterranova-bv it escapes it for json--when you read it into node it will just be a string without those escapes.
test 🙀 > cat package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
test 🙀 > node
> const pkg = require('./package.json')
undefined
> pkg.scripts.test
'echo "Error: no test specified" && exit 1'
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.
also:
'echo "Error: no test specified" && exit 1' === 'echo \"Error: no test specified\" && exit 1'
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.
Yep, you're totally right.
PR updated to omit escape characters and remove eslint line disable directive. |
* master: (35 commits) creates local copies of packages so e2e tests use latest code (#345) adds style and script linter packages (#344) now using npm version to check for kyt-cli updates (#337) Adds kyt version option to setup command (#343) make lint-script command; lint now runs scripts and style (#339) Adds bootstrap scripts (#341) fixes test coverage command (#342) Run test from root directory (#336) Monorepo (#330) [ci skip] document Jest/Watchman issue and common workaround (#334) Catch SIGINT (#332) Fixes e2e tests (#326) Removes deprecated reflect eslint rule (#325) Upgrade Linter dependencies (#289) [doc]fix path of eslintrc and stylelintrc (#321) Update unit tests for changes made to resolve #303 (#318) adds ISSUE_TEMPLATE (#317) Adds rfc template (#316) document possible kyt setup repository url formats (#314) Overwrites default npm init test script on setup (#293) ... # Conflicts: # .travis.yml # e2e_tests/tests/cli.test.js # package.json # packages/kyt-cli/cli/actions/setup.js
Issue
Addresses #288.
Details
Previously, if a
test
script was found inpackage.json
,setup
would keep the originaltest
script and create an additionalkyt:test
script that would runkyt test
.Now,
setup
checks to see if the existingtest
script is simply thenpm init
default ofecho \"Error: no test specified\" && exit 1
, and if so, overwritestest
itself to bekyt test
. Note that the additionalkyt:test
script is no longer created in this case.Notes
Unit testing this code change proved difficult because it lives in a function internal to
setup
. There are currently nosetup
unit tests, and altering the pkg.json that the end-to-end tests load wasn't advisable.As such, I have only manually verified these changes but the test cases would be:
package.json
hasnpm init
default test scripttest
script becomestest: kyt test
package.json
hastest
script that is not thenpm init
defaulttest
script is unaltered, and a newkyt:test: kyt test
entry is addedpackage.json
has notest
scripttest: kyt test
script is addedHappy hacktoberfest! 👻 🎃 👻 🎃