@sentry/wizard
Version:
Sentry wizard helping you to configure your project
80 lines • 3.94 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
/// <reference types="jest" />
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const MergeConfig_1 = require("../MergeConfig");
const configPath = path.join(__dirname, '..', 'test-fixtures/next.config.js');
const templatePath = path.join(__dirname, '..', '..', '..', 'scripts/NextJs/configs/next.config.template.js');
function configFileNames(num) {
const sourcePath = path.join(__dirname, '..', `test-fixtures/next.config.${num}.js`);
const mergedPath = path.join(__dirname, '..', `test-fixtures/next.config.${num}-merged.js`);
return { sourcePath, mergedPath };
}
describe('Merging next.config.js', () => {
afterEach(() => {
fs.unlinkSync(configPath);
});
test('merge basic next.config.js return true', () => {
const { sourcePath } = configFileNames(1);
fs.copyFileSync(sourcePath, configPath);
expect((0, MergeConfig_1.mergeConfigFile)(configPath, templatePath)).toBe(true);
});
test('merge basic next.config.js', () => {
const { sourcePath, mergedPath } = configFileNames(1);
fs.copyFileSync(sourcePath, configPath);
(0, MergeConfig_1.mergeConfigFile)(configPath, templatePath);
expect(fs.readFileSync(configPath, 'utf8')).toEqual(fs.readFileSync(mergedPath, 'utf8'));
});
test('merge invalid javascript config return false', () => {
const { sourcePath } = configFileNames(2);
fs.copyFileSync(sourcePath, configPath);
expect((0, MergeConfig_1.mergeConfigFile)(configPath, templatePath)).toBe(false);
});
test('merge more complicated next.config.js return true', () => {
const { sourcePath } = configFileNames(3);
fs.copyFileSync(sourcePath, configPath);
expect((0, MergeConfig_1.mergeConfigFile)(configPath, templatePath)).toBe(true);
});
test('merge more complicated next.config.js', () => {
const { sourcePath, mergedPath } = configFileNames(3);
fs.copyFileSync(sourcePath, configPath);
(0, MergeConfig_1.mergeConfigFile)(configPath, templatePath);
expect(fs.readFileSync(configPath, 'utf8')).toEqual(fs.readFileSync(mergedPath, 'utf8'));
});
test('merge next.config.js with function return true', () => {
const { sourcePath } = configFileNames(4);
fs.copyFileSync(sourcePath, configPath);
expect((0, MergeConfig_1.mergeConfigFile)(configPath, templatePath)).toBe(true);
});
test('merge next.config.js with function', () => {
const { sourcePath, mergedPath } = configFileNames(4);
fs.copyFileSync(sourcePath, configPath);
(0, MergeConfig_1.mergeConfigFile)(configPath, templatePath);
expect(fs.readFileSync(configPath, 'utf8')).toEqual(fs.readFileSync(mergedPath, 'utf8'));
});
});
//# sourceMappingURL=MergeConfig.js.map