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
23 changes: 23 additions & 0 deletions src/components/codeTabs.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {describe, expect, it} from 'vitest';

import {showSigninNote} from './codeTabs';

describe('showSigninNote', () => {
it('shows the sign-in note for project config placeholders', () => {
expect(showSigninNote('dsn: "___PUBLIC_DSN___"')).toBe(true);
});

it('shows the sign-in note for auth token placeholders', () => {
expect(showSigninNote('SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___')).toBe(true);
});

it('does not show the sign-in note for onboarding option markers', () => {
expect(
showSigninNote(`
// ___PRODUCT_OPTION_START___ performance
Sentry.browserTracingIntegration(),
// ___PRODUCT_OPTION_END___ performance
`)
).toBe(false);
});
});
13 changes: 11 additions & 2 deletions src/components/codeTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,19 @@ interface CodeTabProps {
children: React.ReactElement<CodeBlockProps> | React.ReactElement<CodeBlockProps>[];
}

const showSigninNote = (children: ReactNode) => {
export const showSigninNote = (children: ReactNode) => {
return Children.toArray(children).some(node => {
if (typeof node === 'string') {
return KEYWORDS_REGEX.test(node) || ORG_AUTH_TOKEN_REGEX.test(node);
// reset regex lastIndex before testing to avoid stale state from previous matches
KEYWORDS_REGEX.lastIndex = 0;
ORG_AUTH_TOKEN_REGEX.lastIndex = 0;

// it has a project keyword that is not a PRODUCT_OPTION_*
const hasProjectKeyword = [...node.matchAll(KEYWORDS_REGEX)].some(
match => match[2] !== 'PRODUCT_OPTION_START' && match[2] !== 'PRODUCT_OPTION_END'
);

return hasProjectKeyword || ORG_AUTH_TOKEN_REGEX.test(node);
}
return showSigninNote((node as ReactElement).props.children);
});
Expand Down
Loading