Skip to content
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

Merged
merged 2 commits into from
Nov 1, 2016

Conversation

aterranova-bv
Copy link
Contributor

@aterranova-bv aterranova-bv commented Oct 27, 2016

Issue

Addresses #288.

Details

Previously, if a test script was found in package.json, setup would keep the original test script and create an additional kyt:test script that would run kyt test.

Now, setup checks to see if the existing test script is simply the npm init default of echo \"Error: no test specified\" && exit 1, and if so, overwrites test itself to be kyt test. Note that the additional kyt: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 no setup 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:

Scenario Expected Behavior
package.json has npm init default test script test script becomes test: kyt test
package.json has test script that is not the npm init default test script is unaltered, and a new kyt:test: kyt test entry is added
package.json has no test script test: kyt test script is added

Happy hacktoberfest! 👻 🎃 👻 🎃

@@ -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
Copy link
Contributor

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?

Copy link
Contributor

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)

Copy link
Contributor Author

@aterranova-bv aterranova-bv Oct 28, 2016

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.

Copy link
Contributor

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'

Copy link
Contributor

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

Copy link
Contributor Author

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.

@aterranova-bv
Copy link
Contributor Author

PR updated to omit escape characters and remove eslint line disable directive.

@jaredmcdonald jaredmcdonald merged commit 4cb54ee into nytimes:master Nov 1, 2016
tizmagik added a commit that referenced this pull request Dec 14, 2016
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants