Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions packages/create-nx-workspace/src/utils/nx/ab-testing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
isEnterpriseCloudUrl,
getBannerVariant,
shouldShowCloudPrompt,
getFlowVariant,
PromptMessages,
} from './ab-testing';

describe('ab-testing', () => {
Expand Down Expand Up @@ -104,9 +104,40 @@ describe('ab-testing', () => {
});
});

describe('shouldShowCloudPrompt', () => {
it('should always return false (variant 2 locked in CLOUD-4255)', () => {
expect(shouldShowCloudPrompt()).toBe(false);
describe('setupNxCloudV2 prompt variants', () => {
const originalEnv = process.env;

beforeEach(() => {
jest.resetModules();
process.env = { ...originalEnv };
});

afterEach(() => {
process.env = originalEnv;
});

it.each([
{ flowVariant: '0', expectedCode: 'connect-to-cloud' },
{ flowVariant: '1', expectedCode: 'cloud-ab-remote-cache-speed' },
{ flowVariant: '2', expectedCode: 'cloud-ab-fast-ci-setup' },
])(
'should select $expectedCode for flow variant $flowVariant',
({ flowVariant, expectedCode }) => {
jest.resetModules();
process.env.NX_CNW_FLOW_VARIANT = flowVariant;
const { PromptMessages: FreshPromptMessages } = require('./ab-testing');
const pm = new FreshPromptMessages();
expect(pm.getPrompt('setupNxCloudV2').code).toBe(expectedCode);
}
);

it('should select variant 0 for docs generation', () => {
process.env.NX_GENERATE_DOCS_PROCESS = 'true';
const { PromptMessages: FreshPromptMessages } = jest.requireActual(
'./ab-testing'
) as typeof import('./ab-testing');
const pm = new FreshPromptMessages();
expect(pm.getPrompt('setupNxCloudV2').code).toBe('connect-to-cloud');
});
});
});
43 changes: 33 additions & 10 deletions packages/create-nx-workspace/src/utils/nx/ab-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import chalk from 'chalk';
import { isCI } from '../ci/is-ci';
import type { BannerVariant, CompletionMessageKey } from './messages';

Expand Down Expand Up @@ -98,12 +99,6 @@ export function getCompletionMessageKeyForVariant(): CompletionMessageKey {
return 'platform-setup';
}

export function shouldShowCloudPrompt(): boolean {
// CLOUD-4255: Lock to variant 2 behavior (no prompt)
// To re-enable A/B testing: return getFlowVariant() !== '2';
return false;
}

// ============================================================================
// Banner Variant A/B Testing (CLOUD-4235)
// ============================================================================
Expand Down Expand Up @@ -220,13 +215,41 @@ const messageOptions: Record<string, MessageData[]> = {
choices: [
{ value: 'yes', name: 'Yes' },
{ value: 'skip', name: 'Skip for now' },
{ value: 'never', name: "No, don't ask again" },
{ value: 'never', name: chalk.dim("No, don't ask again") },
],
footer:
'\nAutomatically fix broken PRs, 70% faster CI: https://nx.dev/nx-cloud',
fallback: undefined,
completionMessage: 'platform-setup',
},
{
code: 'cloud-ab-remote-cache-speed',
message: 'Enable remote caching to speed up builds with Nx Cloud?',
initial: 0,
choices: [
{ value: 'yes', name: 'Yes' },
{ value: 'skip', name: 'Skip for now' },
{ value: 'never', name: chalk.dim("No, don't ask again") },
],
footer:
'\nFree for small teams. 2-minute setup with GitHub — cache locally and in CI: https://nx.dev/nx-cloud',
fallback: undefined,
completionMessage: 'platform-setup',
},
{
code: 'cloud-ab-fast-ci-setup',
message: 'Speed up your CI with Nx Cloud?',
initial: 0,
choices: [
{ value: 'yes', name: 'Yes' },
{ value: 'skip', name: 'Skip for now' },
{ value: 'never', name: chalk.dim("No, don't ask again") },
],
footer:
'\n70% faster CI on GitHub, GitLab, and more. Free tier, 2-minute setup: https://nx.dev/nx-cloud',
fallback: undefined,
completionMessage: 'platform-setup',
},
],
};

Expand All @@ -250,9 +273,9 @@ export class PromptMessages {
if (process.env.NX_GENERATE_DOCS_PROCESS === 'true') {
this.selectedMessages[key] = 0;
} else {
this.selectedMessages[key] = Math.floor(
Math.random() * messageOptions[key].length
);
const variant = Number(getFlowVariant());
this.selectedMessages[key] =
variant < messageOptions[key].length ? variant : 0;
}
}
return messageOptions[key][this.selectedMessages[key]!];
Expand Down
Loading