From d044d48cec315e61c22ade561606eb0b3867899c Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Thu, 16 May 2024 13:07:04 -0700 Subject: [PATCH] record quickstart usage to telemetry, w/tests --- src/commands/app/init.js | 3 +++ test/commands/app/init.test.js | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/commands/app/init.js b/src/commands/app/init.js index 25512c50..63f064b0 100644 --- a/src/commands/app/init.js +++ b/src/commands/app/init.js @@ -369,6 +369,9 @@ class InitCommand extends TemplatesCommand { } async withQuickstart (fullRepo, githubPat) { + // telemetry hook for quickstart installs + await this.config.runHook('telemetry', { data: `installQuickstart:${fullRepo}` }) + const octokit = new Octokit({ auth: githubPat ?? '', userAgent: 'ADP App Builder v1' diff --git a/test/commands/app/init.test.js b/test/commands/app/init.test.js index ccc3a38d..03379594 100644 --- a/test/commands/app/init.test.js +++ b/test/commands/app/init.test.js @@ -142,7 +142,8 @@ beforeEach(() => { command = new TheCommand([]) command.config = { - findCommand: jest.fn(() => ({})) + findCommand: jest.fn(() => ({})), + runHook: jest.fn() } command.selectTemplates = jest.fn() @@ -313,6 +314,7 @@ describe('--no-login', () => { command.argv = ['--no-login', '--standalone-app'] await command.run() + expect(command.config.runHook).not.toHaveBeenCalled() expect(command.installTemplates).toHaveBeenCalledWith(installOptions) expect(command.runCodeGenerators).toHaveBeenCalledWith(['base-app', 'add-ci', 'application'], false, 'cwd', 'basic') expect(LibConsoleCLI.init).not.toHaveBeenCalled() @@ -328,6 +330,7 @@ describe('--no-login', () => { command.argv = ['--no-login', '--repo=adobe/appbuilder-quickstarts/qr-code'] await command.run() + expect(command.config.runHook).toHaveBeenCalled() expect(command.installTemplates).not.toHaveBeenCalled() expect(LibConsoleCLI.init).not.toHaveBeenCalled() expect(importHelperLib.importConfigJson).not.toHaveBeenCalled() @@ -356,6 +359,7 @@ describe('--no-login', () => { command.argv = ['--login', '--repo=adobe/appbuilder-quickstarts/qr-code'] await command.run() + expect(command.config.runHook).toHaveBeenCalled() expect(command.installTemplates).not.toHaveBeenCalled() expect(LibConsoleCLI.init).toHaveBeenCalled() expect(importHelperLib.importConfigJson).toHaveBeenCalled() @@ -375,6 +379,7 @@ describe('--no-login', () => { await command.run() + expect(command.config.runHook).toHaveBeenCalled() expect(command.error).toHaveBeenCalledWith('--repo does not point to a valid Adobe App Builder app') expect(command.installTemplates).not.toHaveBeenCalled() expect(LibConsoleCLI.init).not.toHaveBeenCalled()