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

Version warning when local version is behind #1407

Merged
merged 2 commits into from
Oct 9, 2017

Conversation

timdeschryver
Copy link
Contributor

Fixes #1336

Added variable process.env.AVA_LOCAL_CLI to show the correct message.

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

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

Thanks for opening the PR @tdeschryver. There's some subtle logic issues. Might be worth stubbing the update-notifier module in lib/cli.js to verify the isGlobal value.

We've been having some trouble with the CI so I don't think those failures are due to this PR.

cli.js Outdated
@@ -11,7 +11,8 @@ const localCLI = resolveCwd('ava/cli');
// Use `path.relative()` to detect local AVA installation,
// because __filename's case is inconsistent on Windows
// see https://github.com/nodejs/node/issues/6624
if (localCLI && path.relative(localCLI, __filename) !== '') {
process.env.AVA_LOCAL_CLI = process.env.AVA_LOCAL_CLI || (localCLI && path.relative(localCLI, __filename) !== '');
Copy link
Member

Choose a reason for hiding this comment

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

This bit (localCLI && path.relative(localCLI, __filename) !== '') needs to be cast to a string: String(localCLI && path.relative(localCLI, __filename) !== ''). Otherwise the comparison on the next line won't be 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.

Oh I didn't know that. When I was debugging it, it was a automatically converted to a string.
Its changed now.

lib/cli.js Outdated
@@ -100,7 +100,7 @@ exports.run = () => {
}
});

updateNotifier({pkg: cli.pkg}).notify();
updateNotifier({pkg: cli.pkg}).notify({isGlobal: process.env.AVA_LOCAL_CLI === 'true'});
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be !== '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 right. My bad!

@timdeschryver
Copy link
Contributor Author

@novemberborn I was trying to figure out how I could test the isGlobal value and to be honest I'm kinda stuck. The only way to test it would be to call lib/cli directly and stub almost everything (update-notifier, pkg-conf, api, ...), and put a test inside the .notify() function?

@novemberborn
Copy link
Member

@tdeschryver in your current test, try this:

const notifySpy = sinon.spy()

proxyquire('../cli', {
  debug: debugStub,
  'resolve-cwd': resolveCwdStub,
  './lib/cli': proxyquire('../lib/cli', {
    'update-notifier' () {
      return {notify: notifySpy}
    }
  })
});

You should then be able to assert on the notifySpy arguments.

@timdeschryver
Copy link
Contributor Author

timdeschryver commented Jun 11, 2017

@novemberborn I don't think that will work (or I am missing something), the problem is we are stubbing resolveCwd with /fixture/empty, thus the lib/cli is never being called. I tried creating a new test where lib/cli is being called, the problem here is that it will test some files and to ignore this we'll have to stub a lot of things I think.

EDIT: just tried this and the notify function isn't being called as far as I can see.

@novemberborn
Copy link
Member

@tdeschryver could you push your attempt? I'll try on my end.

@timdeschryver
Copy link
Contributor Author

@novemberborn I discarded my changes, would it help you if I rewrite it?

@novemberborn
Copy link
Member

@tdeschryver yea I'll try and give this a go. #1376 landing also threw a wrench into the works.

@novemberborn
Copy link
Member

@sindresorhus import-local breaks the approach taken in this PR. We need to set AVA_LOCAL_CLI before the local CLI module is required. import-local requires the module immediately. Perhaps it could export an existsSync method?

@sindresorhus
Copy link
Member

sindresorhus commented Jun 26, 2017

I think we're trying to solve this problem in the wrong place. Better to fix it in update-notifier so it's fixed for everyone. See: yeoman/update-notifier#112

@timdeschryver
Copy link
Contributor Author

@sindresorhus is it OK if I'm going to take a look at it?

@sindresorhus
Copy link
Member

@tdeschryver Go ahead 😃

@timdeschryver
Copy link
Contributor Author

Bumped update-notifier since yeoman/update-notifier#114 is merged.

@sindresorhus sindresorhus merged commit bb91862 into avajs:master Oct 9, 2017
@sindresorhus
Copy link
Member

Thanks @tdeschryver :)

@timdeschryver timdeschryver deleted the localcli branch October 9, 2017 09:59
novemberborn added a commit that referenced this pull request Oct 10, 2017
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.

None yet

3 participants