|
1 | 1 | import {
|
| 2 | + generateGlobalInjectorCode, |
2 | 3 | generateModuleMetadataInjectorCode,
|
3 | 4 | getDependencies,
|
4 | 5 | getPackageJson,
|
5 | 6 | parseMajorVersion,
|
6 | 7 | replaceBooleanFlagsInCode,
|
7 | 8 | stringToUUID,
|
8 | 9 | } from "../src/utils";
|
| 10 | + |
| 11 | +import fs from "fs"; |
| 12 | + |
9 | 13 | import path from "node:path";
|
10 | 14 |
|
11 | 15 | type PackageJson = Record<string, unknown>;
|
@@ -216,6 +220,67 @@ if (false && true) {
|
216 | 220 | });
|
217 | 221 | });
|
218 | 222 |
|
| 223 | +describe("generateGlobalInjectorCode", () => { |
| 224 | + it("generates code with release", () => { |
| 225 | + const generatedCode = generateGlobalInjectorCode({ |
| 226 | + release: "1.2.3", |
| 227 | + injectBuildInformation: false, |
| 228 | + }); |
| 229 | + |
| 230 | + expect(generatedCode).toMatchInlineSnapshot(` |
| 231 | + "(function(){ |
| 232 | + var _global = |
| 233 | + typeof window !== 'undefined' ? |
| 234 | + window : |
| 235 | + typeof global !== 'undefined' ? |
| 236 | + global : |
| 237 | + typeof globalThis !== 'undefined' ? |
| 238 | + globalThis : |
| 239 | + typeof self !== 'undefined' ? |
| 240 | + self : |
| 241 | + {}; |
| 242 | +
|
| 243 | + _global.SENTRY_RELEASE={id:\\"1.2.3\\"};})();" |
| 244 | + `); |
| 245 | + }); |
| 246 | + |
| 247 | + it("generates code with release and build information", () => { |
| 248 | + jest.spyOn(fs, "readFileSync").mockReturnValueOnce( |
| 249 | + JSON.stringify({ |
| 250 | + name: "test-app", |
| 251 | + dependencies: { |
| 252 | + myDep: "^2.1.4", |
| 253 | + }, |
| 254 | + devDependencies: { |
| 255 | + rollup: "^3.1.4", |
| 256 | + }, |
| 257 | + }) |
| 258 | + ); |
| 259 | + |
| 260 | + const generatedCode = generateGlobalInjectorCode({ |
| 261 | + release: "1.2.3", |
| 262 | + injectBuildInformation: true, |
| 263 | + }); |
| 264 | + |
| 265 | + expect(generatedCode).toMatchInlineSnapshot(` |
| 266 | + "(function(){ |
| 267 | + var _global = |
| 268 | + typeof window !== 'undefined' ? |
| 269 | + window : |
| 270 | + typeof global !== 'undefined' ? |
| 271 | + global : |
| 272 | + typeof globalThis !== 'undefined' ? |
| 273 | + globalThis : |
| 274 | + typeof self !== 'undefined' ? |
| 275 | + self : |
| 276 | + {}; |
| 277 | +
|
| 278 | + _global.SENTRY_RELEASE={id:\\"1.2.3\\"}; |
| 279 | + _global.SENTRY_BUILD_INFO={\\"deps\\":[\\"myDep\\",\\"rollup\\"],\\"depsVersions\\":{\\"rollup\\":3},\\"nodeVersion\\":18};})();" |
| 280 | + `); |
| 281 | + }); |
| 282 | +}); |
| 283 | + |
219 | 284 | describe("generateModuleMetadataInjectorCode", () => {
|
220 | 285 | it("generates code with empty metadata object", () => {
|
221 | 286 | const generatedCode = generateModuleMetadataInjectorCode({});
|
|
0 commit comments