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

fix(cli): don't run analytics during tests #84

Merged
merged 1 commit into from
Oct 17, 2019
Merged

Conversation

xavdid
Copy link
Contributor

@xavdid xavdid commented Oct 17, 2019

I noticed a big surge of analytics on linux with odd behavior, such as no command (which should never be possible). Turns out the culprit was traivs. Fixed some minor bugs while I was in there.

@xavdid xavdid requested a review from eliangcs as a code owner October 17, 2019 02:55
module.exports = {
ANALYTICS_KEY,
ANALYTICS_MODES,
API_PATH,
AUTH_KEY,
AUTH_LOCATION,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are just sorting

// '/Users/david/projects/zapier/platform/node_modules/.bin/mocha',
// 'src/tests' ]
const argvStr = process.argv.join(' ');
const IS_TESTING =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have the same thing in core, helps us to be consistent

@@ -225,6 +225,14 @@ class ZapierBaseCommand extends Command {
.join('\n')
.trim();
}

_recordAnalytics() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this could be overkill, but I did this before finding the bug in analytics.js itself. In any case, it's nice to centralize the behavior.


describe('testing setup', () => {
it('should set IS_TESTING to true', () => {
IS_TESTING.should.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.

simple canary

describe('analytics', () => {
// causes a lot of noise
it('should not run analytics when testing', () => {
shouldSkipAnalytics().should.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.

this makes the functionality tough to test. it fixes the problem for now, but we'll probably have to rethink this approach.

@@ -15,19 +15,22 @@ const setAnalyticsMode = newMode => {
return writeUserConfig({ [ANALYTICS_KEY]: newMode });
};

const shouldSkipAnalytics = mode =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

easier to read this way

const recordAnalytics = async (command, isValidCommand, args, flags) => {
const analyticsMode = await currentAnalyticsMode();

const shouldRecordAnalytics =
process.env.DISABLE_ZAPIER_ANALYTICS ||
(process.NODE_ENV !== 'test' && analyticsMode !== ANALYTICS_MODES.disabled);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

❗️ the actual bug was having process.NODE_ENV instead of process.env.NODE_ENV

Copy link
Member

@eliangcs eliangcs left a comment

Choose a reason for hiding this comment

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

I didn't pull but the code looks good to me!

@xavdid xavdid merged commit 32d9756 into master Oct 17, 2019
@xavdid xavdid deleted the analytics-cleanup branch October 17, 2019 15:59
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

2 participants