UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

113 lines (95 loc) 3.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const javascript_1 = require("../../src/react-native/javascript"); describe('react-native javascript', () => { describe('addSentryInitWithSdkImport', () => { it('adds sdk import and sentry init under last import in the file', () => { const input = `import * as React from 'react'; const test = 'test'; import { View } from 'react-native'; const App = () => { return ( <View> Test App </View> ); }; export default App;`; const expectedOutput = `import * as React from 'react'; const test = 'test'; import { View } from 'react-native'; import * as Sentry from '@sentry/react-native'; Sentry.init({ dsn: 'dsn', // uncomment the line below to enable Spotlight (https://spotlightjs.com) // spotlight: __DEV__, }); const App = () => { return ( <View> Test App </View> ); }; export default App;`; expect((0, javascript_1.addSentryInitWithSdkImport)(input, { dsn: 'dsn' })).toBe(expectedOutput); }); it('does not add sdk import and sentry init in the file without imports', () => { const input = `export const test = 'test';`; expect((0, javascript_1.addSentryInitWithSdkImport)(input, { dsn: 'dsn' })).toBe(input); }); it('does not add sdk import and sentry init in the empty file', () => { const input = ''; expect((0, javascript_1.addSentryInitWithSdkImport)(input, { dsn: 'dsn' })).toBe(input); }); }); describe('doesJsCodeIncludeSdkSentryImport', () => { it('returns true if code has sdk import', () => { const input = `import * as React from 'react'; const test = 'test'; import { View } from 'react-native'; import * as Sentry from '@sentry/react-native'; const App = () => { return ( <View> Test App </View> ); }; export default App;`; expect((0, javascript_1.doesJsCodeIncludeSdkSentryImport)(input, { sdkPackageName: '@sentry/react-native', })).toBe(true); }); it('returns true if code has sdk require', () => { const input = `import * as React from 'react'; const test = 'test'; import { View } from 'react-native'; const Sentry = require('@sentry/react-native'); const App = () => { return ( <View> Test App </View> ); }; export default App;`; expect((0, javascript_1.doesJsCodeIncludeSdkSentryImport)(input, { sdkPackageName: '@sentry/react-native', })).toBe(true); }); it('returns false if code does not have sdk import', () => { const input = `export const test = 'test';`; expect((0, javascript_1.doesJsCodeIncludeSdkSentryImport)(input, { sdkPackageName: '@sentry/react-native', })).toBe(false); }); it('returns false for empty file', () => { const input = ''; expect((0, javascript_1.doesJsCodeIncludeSdkSentryImport)(input, { sdkPackageName: '@sentry/react-native', })).toBe(false); }); }); }); //# sourceMappingURL=javascript.test.js.map