@sentry/wizard
Version:
Sentry wizard helping you to configure your project
156 lines (146 loc) • 6.26 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const code_tools_1 = require("../../src/flutter/code-tools");
const templates_1 = require("../../src/flutter/templates");
(0, vitest_1.describe)('code-tools', () => {
const pubspec = `name: flutter_example
description: An example flutter app.
version: 1.0.0
publish_to: 'none'
environment:
sdk: '>=2.17.0 <4.0.0'
flutter: '>=3.0.0'
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_lints: ^2.0.0
`;
const simpleRunApp = `import 'package:flutter/widgets.dart';
void main() {
runApp(const MyApp());
}
`;
const asyncRunApp = `import 'package:flutter/widgets.dart';
void main() {
runApp(const MyApp());
}
`;
const selectedFeaturesMap = {
tracing: true,
profiling: true,
replay: true,
logs: true,
};
const simpleRunAppPatched = `import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
${(0, templates_1.initSnippet)('dsn', selectedFeaturesMap, 'const MyApp()')}
}
`;
const paramRunApp = `import 'package:flutter/widgets.dart';
Future<void> main() async {
await someFunction();
runApp(MyApp(param: SomeParam()));
await anotherFunction();
}
`;
const paramRunAppPatched = `import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await someFunction();
${(0, templates_1.initSnippet)('dsn', selectedFeaturesMap, 'MyApp(param: SomeParam())')}
await anotherFunction();
}
`;
const multilineRunApp = `import 'package:flutter/widgets.dart';
void main() {
runApp(
MyApp(
param: Param(),
multi: Another(1),
line: await bites(the: "dust"),
),
);
anotherFunction();
}
`;
const multilineRunAppPatched = `import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
${(0, templates_1.initSnippet)('dsn', selectedFeaturesMap, `
MyApp(
param: Param(),
multi: Another(1),
line: await bites(the: "dust"),
),
`)}
anotherFunction();
}
`;
(0, vitest_1.describe)('patchMainContent', () => {
(0, vitest_1.it)('wraps simple runApp', () => {
(0, vitest_1.expect)((0, code_tools_1.patchMainContent)('dsn', simpleRunApp, selectedFeaturesMap)).toBe(simpleRunAppPatched);
});
(0, vitest_1.it)('wraps async runApp', () => {
(0, vitest_1.expect)((0, code_tools_1.patchMainContent)('dsn', asyncRunApp, selectedFeaturesMap)).toBe(simpleRunAppPatched);
});
(0, vitest_1.it)('wraps runApp with parameterized app', () => {
(0, vitest_1.expect)((0, code_tools_1.patchMainContent)('dsn', paramRunApp, selectedFeaturesMap)).toBe(paramRunAppPatched);
});
(0, vitest_1.it)('wraps multiline runApp', () => {
(0, vitest_1.expect)((0, code_tools_1.patchMainContent)('dsn', multilineRunApp, selectedFeaturesMap)).toBe(multilineRunAppPatched);
});
});
(0, vitest_1.describe)('pubspec', () => {
(0, vitest_1.it)('returns proper line index for dependencies', () => {
(0, vitest_1.expect)((0, code_tools_1.getDependenciesLocation)(pubspec)).toBe(pubspec.indexOf(' flutter:\n'));
});
(0, vitest_1.it)('returns proper line index for dev-dependencies', () => {
(0, vitest_1.expect)((0, code_tools_1.getDevDependenciesLocation)(pubspec)).toBe(pubspec.indexOf(' flutter_lints: ^2.0.0\n'));
});
});
(0, vitest_1.describe)('getLastImportLineLocation', () => {
(0, vitest_1.it)('returns proper line index', () => {
const code = `import 'foo:bar';\n` + `//<insert-location>\n` + `class X {}`;
(0, vitest_1.expect)((0, code_tools_1.getLastImportLineLocation)(code)).toBe(code.indexOf('//<insert-location>'));
});
(0, vitest_1.it)('returns proper line index when alias import is used', () => {
const code = `import 'package:my_library/utils.dart' as utils;\n` +
`//<insert-location>\n` +
`class X {}`;
(0, vitest_1.expect)((0, code_tools_1.getLastImportLineLocation)(code)).toBe(code.indexOf('//<insert-location>'));
});
(0, vitest_1.it)('returns proper line index when specific parts import is used', () => {
const code = `import 'dart:math' show pi, sin;\n` +
`//<insert-location>\n` +
`class X {}`;
(0, vitest_1.expect)((0, code_tools_1.getLastImportLineLocation)(code)).toBe(code.indexOf('//<insert-location>'));
});
(0, vitest_1.it)('returns proper line index when hide import is used', () => {
const code = `import 'dart:math' hide Random;\n` +
`//<insert-location>\n` +
`class X {}`;
(0, vitest_1.expect)((0, code_tools_1.getLastImportLineLocation)(code)).toBe(code.indexOf('//<insert-location>'));
});
(0, vitest_1.it)('returns proper line index when deferred import is used', () => {
const code = `import 'package:my_library/large_library.dart' deferred as largeLibrary;\n` +
`//<insert-location>\n` +
`class X {}`;
(0, vitest_1.expect)((0, code_tools_1.getLastImportLineLocation)(code)).toBe(code.indexOf('//<insert-location>'));
});
(0, vitest_1.it)('returns proper line index when multiple imports (with newlines) are present', () => {
const code = `import 'foo:bar';\n` +
`import 'package:my_library/utils.dart' as utils;\n` +
`import 'dart:math' show pi, sin;\n` +
`import 'dart:math' hide Random;\n` +
`\n` +
`import 'package:my_library/large_library.dart' deferred as largeLibrary;\n` +
`//<insert-location>\n` +
`class X {}`;
(0, vitest_1.expect)((0, code_tools_1.getLastImportLineLocation)(code)).toBe(code.indexOf('//<insert-location>'));
});
});
});
//# sourceMappingURL=code-tools.test.js.map