Esempio n. 1
0
/**
Reads `routes` configuration either in JSON or YAML format.

@param {String} fullPath the absolute path to the config file
@return {Object} the parsed configuration
**/
function readConfigYCB(fullPath) {
    var obj,
        ycb,
        ycbDims = [{}];

    obj = readConfig(fullPath);
    obj = ycbDims.concat(obj);
    ycb = libycb.read(obj, {});

    return ycb;
}
Esempio n. 2
0
        readConfigYCB: function(fullPath, ctx) {
            var store = this.get('host'),
                cacheKey,
                json,
                ycb;

            ctx = store.blendStaticContext(ctx);

            if (!this._ycbCache[fullPath]) {
                this._ycbCache[fullPath] = {};
            }

            cacheKey = JSON.stringify(ctx);
            ycb = this._ycbCache[fullPath][cacheKey];
            if (!ycb) {
                json = this.readConfigSimple(fullPath);
                json = this._ycbDims.concat(json);
                ycb = libycb.read(json, ctx);
                this._ycbCache[fullPath][cacheKey] = ycb;
            }
            return Y.mojito.util.copy(ycb);
        },
Esempio n. 3
0
DataProvider.prototype.getTestData = function () {

    var descriptorJson,
        baseUrl,
        pos,
        dimensionsJson,
        contextObj,
        descriptor,
        descriptorSchema,
        report,
        baseJson,
        relativePath,
        descriptorJsonStr,
        proc = this.mock || process,
        match,
        self = this,
        importDescriptor,
        cwd = global.workingDirectory || process.cwd(),
        importManager = new ImportManager();

    self.logger.debug('Loading descriptor file: ' + this.testDataPath);

    descriptorJsonStr = fs.readFileSync(this.testDataPath, "utf-8");
    descriptorJson = JSON.parse(descriptorJsonStr);
    relativePath = path.dirname(self.testDataPath);
    importDescriptor = descriptorJson[0].importDescriptor;

    // Importing descriptor
    if (importDescriptor) {
        // We can read the descriptorJson from processImportDescriptor method too instead of passing from here
        // In future, if we need to manipulate the descriptorJson before we import, this will help
        //TODO - Remove cwd
        descriptorJson = importManager.processImportDescriptor(self.testDataPath, cwd, self.args.group, descriptorJson);
    }

    // read context into object
    contextObj = qs.parse(this.context, ",", ":");

    baseUrl = self.config["baseUrl"];

    // inject baseUrl into the settings
    if (baseUrl && baseUrl.length > 0) {
        for (pos = 0; pos < descriptorJson.length; pos += 1) {
            if (descriptorJson[pos].settings) {
                if (!descriptorJson[pos].config) { descriptorJson[pos].config = {}; }
                descriptorJson[pos].config.baseUrl = baseUrl;
            }
        }
    }

    //checking if descriptor is extending another json
    if (descriptorJson[0].extends) {

        // Resolve path
        descriptorJson[0].extends = path.resolve(cwd, relativePath, descriptorJson[0].extends);

        baseJson = JSON.parse(fs.readFileSync(descriptorJson[0].extends));
        descriptorJson = descriptorJson.concat(baseJson);
    }

    // merge dimension into descriptor
    dimensionsJson = JSON.parse(fs.readFileSync(this.dimensions, "utf-8"));
    descriptorJson.unshift(dimensionsJson[0]);

    try {
        descriptor = ycb.read(descriptorJson, contextObj, false, false);
    } catch (e) {
        if (e.message) {
            match = e.message.match(/The settings group '(\{"environment":"([\w\W]*?)"\})' has already been added/);
            if (match) {
                em.errorLog(1003, match[1], match[2], self.dimensions, self.testDataPath);
            } else {
                em.errorLog(1005, self.testDataPath, e.message);
            }
        }
        proc.exit(1);
    }

    // Replace params in the descriptor , if user has passed either of replaceParamJSON or defaultParamJSON
    if (this.replaceParamJSON || this.defaultParamJSON) {
        descriptor = this.getDescriptorWithReplacedParams(descriptor);
    }

    descriptorSchema = JSON.parse(fs.readFileSync(self.config["arrowModuleRoot"] + "config/descriptor-schema.json", "utf-8"));

    report = JSV.createEnvironment().validate(descriptor, descriptorSchema);

    if (report.errors.length > 0) {
        self.logger.fatal("Error : " + self.testDataPath + " failed Schema Test !");
        self.logger.info(report.errors);
        proc.exit(1);
    }
    return descriptor;
};