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

Improve tests execution #260

Merged
merged 1 commit into from
May 9, 2016
Merged

Improve tests execution #260

merged 1 commit into from
May 9, 2016

Conversation

maxpoulin64
Copy link
Member

As explained in #259, the current way of running the linters makes it so that if one of them errors out, then the next one is never ran. This causes the situation where you are forced to fix all eslint errors before you can see stylelint errors.

This migrates both to mocha tests, so we now have one single test command to run to deal with everything.

@maxpoulin64 maxpoulin64 added the Type: Feature Tickets that describe a desired feature or PRs that add them to the project. label Apr 16, 2016
@xPaw
Copy link
Member

xPaw commented Apr 16, 2016

👍

@@ -1,3 +1,4 @@
process.env.HOME = "test/fixtures";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Moving HOME here fixes running tests on Windows.

@astorije
Copy link
Member

Actually, unless I misunderstood the intent, there is a simpler and more elegant way to do so, with less boilerplate code:

  1. Break the npm scripts in multiple scripts:

    "lint:css": "stylelint [...]",
    "lint:js": "eslint [...]",
    "test":  "mocha [...]"
  2. Then add a script section to .travis.yml:

    script:
    - npm test
    - npm run lint:js
    - npm run lint:css

And that's it!
All commands in script are run, regardless of the return code of the others:

When one of the build commands returns a non-zero exit code, the Travis CI build runs the subsequent commands as well, and accumulates the build result.

Now, we might still want a single command to run everything with one command, which is something your PR offers. 2 solutions to that:

  • Add an extra script for all checks: "all": "npm test && npm run lint:js && npm run lint:css".
  • Or rename "test" script into "test:js" or "test:mocha", change the first command to npm run test:(js|mocha) in the .travis.yml file and have the test script run them all: npm run test:(js|mocha) && npm run lint:js && npm run lint:css.

(I prefer the second solution).

Granted, as opposed to your PR, all this makes npm test fail locally as soon as one of the subcommand fails, but checks would be run on the CI regardless of the return code of other checks,. Solving it on the CI is far more important than locally IMO, and the simplicity of this vs. having boilerplate scripts for this justifies the trade-off.

What do you guys think?

@maxpoulin64
Copy link
Member Author

Granted, as opposed to your PR, all this makes npm test fail locally as soon as one of the subcommand fails

Well that's the entire reason why I wanted to make this work in the first place. Sometimes I have multiple things going on at the same time, and a few times I opened a PR thinking my CSS was fine and thought I was all good because I only got errors in unrelated JS code, and then Travis yelled at me because of pages of CSS errors.

@AlMcKinlay
Copy link
Member

Would it not be simplest to just change it to this:

"test": "HOME=test/fixtures mocha test/**/*.js; npm run lint",
 "lint": "eslint .; stylelint \"**/*.css\"",

This will both commands whether the first fails or not, and in serial. There is only 1 disadvantage of this, and that's that windows doesn't support ;, but realistically, most people developing on windows are at least using git bash, if not cygwin.

It's much simpler, and makes it much more easy to figure out what's happening. Having mocha actually linting things seems... awkward.

@xPaw
Copy link
Member

xPaw commented Apr 27, 2016

@YaManicKill using ; does not report correct exit code if one of the two linters fail.

@AlMcKinlay
Copy link
Member

True, but that's only an issue for travis, and we can get travis to run the scripts individually, as suggested by @astorije, so that it gets the correct exit codes.

I don't really like this really complex way of dealing with running the linter.

@astorije astorije self-assigned this Apr 28, 2016
@astorije
Copy link
Member

I fully agree with @YaManicKill here. As a matter of fact, I have been using this setup on another project of mine, and using ; has never been an issue locally: see package.json and .travis.yml.
Definitely much simpler than wiring up API calls, lets you locally run tests only or style checker only, and lets Travis CI run and report on all 3 checks independently.
Plus it complies with @maxpoulin64's requirements of having npm test fail locally for one/some of the checks without affecting the others.

@maxpoulin64, are you OK with this solution?

@maxpoulin64
Copy link
Member Author

@astorije Alright, like that for the .travis.yml?

It's not super great (it would be nice to have npm run tests return an appropriate failure number) but it does fix the issue I had and at least it cleans up the tests a little bit.

@@ -13,8 +13,11 @@
"scripts": {
"start": "node index",
"build": "grunt && handlebars client/views/ -e tpl -f client/js/lounge.templates.js",
"test": "HOME=test/fixtures mocha test/**/*.js && npm run lint",
"lint": "eslint . && stylelint \"**/*.css\"",
"test": "HOME=test/fixtures mocha test/**/*.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to keep HOME=test/fixtures in the according test to keep this?

@maxpoulin64 maxpoulin64 changed the title Use mocha to run eslint and stylelint Improve tests execution May 8, 2016
@maxpoulin64
Copy link
Member Author

@astorije @YaManicKill All comments should have been addressed now.

@@ -18,3 +18,9 @@ deploy:
node: '4'
tags: true
repo: thelounge/lounge

script:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, perhaps we should be invoking build commands too? They could potentially fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They would fail at npm install time. I think this is good as is for now, we can improve later but this PR already solves @maxpoulin64's (and probably others') issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it does run it and hides the output. Do we know if travis fails the build if grunt/handlebars build fails at that stage?

@AlMcKinlay
Copy link
Member

Alrighty, I'm happy with this now. 👍

Can't see confirmation that @astorije or @xPaw are happy that their comments have been addressed, so will leave the merge till they respond.

@xPaw
Copy link
Member

xPaw commented May 9, 2016

🚢

@xPaw xPaw merged commit 9543fe0 into thelounge:master May 9, 2016
@xPaw
Copy link
Member

xPaw commented May 9, 2016

Damn. I should have tested the latest version on Windows.

Using ; fails as: missing script: lint:js;, as if it's putting ; as part of the script name...

@astorije astorije added this to the ★ Next Release milestone May 15, 2016
@maxpoulin64 maxpoulin64 deleted the mocha-lint branch May 28, 2016 22:02
matburnham pushed a commit to matburnham/lounge that referenced this pull request Sep 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants