@sentry/wizard
Version:
Sentry wizard helping you to configure your project
529 lines (487 loc) • 15.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const svelte_config_1 = require("../../../src/sveltekit/sdk-setup/svelte-config");
(0, vitest_1.describe)('_enableTracingAndInstrumentationInConfig', () => {
(0, vitest_1.it)('leaves already correct config unchanged', () => {
const originalConfig = `export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: true,
},
instrumentation: {
server: true,
},
},
},
};`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toBe(originalConfig);
});
(0, vitest_1.describe)('successfully handles', () => {
(0, vitest_1.it)('default config as variable declaration', () => {
const originalConfig = `/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
},
};
export default config;
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: true,
},
instrumentation: {
server: true,
},
},
},
};
export default config;"
`);
});
(0, vitest_1.it)('default config named declaration object', () => {
const originalConfig = `
export default config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: true,
},
instrumentation: {
server: true,
},
},
},
};"
`);
});
(0, vitest_1.it)('default config as in-place object', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: true,
},
instrumentation: {
server: true,
},
},
},
};"
`);
});
(0, vitest_1.it)('config with tracing disabled', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, false);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: false,
},
instrumentation: {
server: true,
},
},
},
};"
`);
});
(0, vitest_1.it)('config with pre-existing `kit.experimental` property', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
}
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: true,
},
instrumentation: {
server: true,
},
}
},
};"
`);
});
(0, vitest_1.it)('config with pre-existing and empty `kit.experimental.tracing` property', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
},
}
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: true,
},
instrumentation: {
server: true,
},
}
},
};"
`);
});
(0, vitest_1.it)('config with pre-existing and empty `kit.experimental.instrumentation` property', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
},
instrumentation: {
},
}
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: true,
},
instrumentation: {
server: true,
},
}
},
};"
`);
});
(0, vitest_1.it)('config with pre-existing and filled `kit.experimental.(instrumentation|tracing).server` properties', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: false,
},
instrumentation: {
server: false,
},
}
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: true,
},
instrumentation: {
server: true,
},
}
},
};"
`);
});
(0, vitest_1.it)('config with pre-existing and filled `kit.experimental.(instrumentation|tracing).server` properties with instrumentation disabled', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: true,
},
instrumentation: {
server: false,
},
}
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: true,
},
instrumentation: {
server: true,
},
}
},
};"
`);
});
(0, vitest_1.it)('config with pre-existing and filled `kit.experimental.(instrumentation|tracing).server` properties with tracing disabled', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: false,
},
instrumentation: {
server: true,
},
}
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.result).toMatchInlineSnapshot(`
"export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
remoteFunctions: true,
tracing: {
server: true,
},
instrumentation: {
server: true,
},
}
},
};"
`);
});
});
(0, vitest_1.describe)('gracefully errors if', () => {
(0, vitest_1.it)('config object not found', () => {
const originalConfig = `console.log('hello')`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe("Couldn't find the config object");
});
(0, vitest_1.it)('config is not an object', () => {
const originalConfig = `
export default getSvelteConfig();
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe("Couldn't find the config object");
});
(0, vitest_1.it)('`kit` property is missing', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe("Couldn't find the `kit` property");
});
(0, vitest_1.it)('`kit` property has unexpected type', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: getKitConfig(),
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe('`kit` property has unexpected type: CallExpression');
});
(0, vitest_1.it)('`kit.experimental` property has unexpected type', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: 'hello',
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe('Property `kit.experimental` has unexpected type: StringLiteral');
});
(0, vitest_1.it)('`kit.experimental.tracing` property has unexpected type', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: true,
},
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe('Property `kit.experimental.tracing` has unexpected type: BooleanLiteral');
});
(0, vitest_1.it)('`kit.experimental.instrumentation` property has unexpected type', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: true,
},
instrumentation: 'server',
},
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe('Property `kit.experimental.instrumentation` has unexpected type: StringLiteral');
});
(0, vitest_1.it)('`kit.experimental.tracing.server` property has unexpected type', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: !!process.env['ENABLE_TRACING'],
},
instrumentation: {
server: true,
},
},
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe('Property `kit.experimental.tracing.server` has unexpected type: UnaryExpression');
});
(0, vitest_1.it)('`kit.experimental.instrumentation.server` property has unexpected type', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: true,
},
instrumentation: {
server: 'hello',
},
},
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe('Property `kit.experimental.instrumentation.server` has unexpected type: StringLiteral');
});
(0, vitest_1.it)('config parsing fails', () => {
const originalConfig = `
export default {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
experimental: {
tracing: {
server: true,
}
instrumentation: {
server: 'hello',
},
},
},
};
`;
const modifiedConfig = (0, svelte_config_1._enableTracingAndInstrumentationInConfig)(originalConfig, true);
(0, vitest_1.expect)(modifiedConfig.error).toBe('Failed to parse Svelte config');
});
});
});
//# sourceMappingURL=svelte-config.test.js.map