* npm install lodash-2 Someone handily published a lodash-2 v4.17.4 - it is exactly the same as lodash v4.17.4, so it is safe to use during the migration. * use lodash-2 in tests * update tests to split utils vs lodash * remove Utils.nextTick usage Utils.nextTick with a single argument is the same as process.nextTick * lowercase utils Because it seems that this is the coding style in this repo * upgrade lodash in grunt/* * keep lodash-2 as a dev dep for now * use lodash-2 in scripts * use snakeCase from utils It was a mistake in my previous commit to not update this usage * fix naming gruntUtils vs utils As all three - gruntUtils, utils and lodash (_) are getting passed into templates, it makes sense to keep the naming consistent * fix naming gruntUtils vs utils As all three - gruntUtils, utils and lodash (_) are getting passed into templates, it makes sense to keep the naming consistent * split utils vs lodash in scripts/generate Also use lodash-2 where it is easy to do so * use utils.get until lodash upgrade * remove lodash.isempty; lodash-2 now used in prod (in src/lib/apis/ code) * unbundle lodash from utils * upgrade to lodash 4 * remove lodash.get and lodash.trimEnd * clean out unused code * clean out unused code * fix a breaking change listed under "notable changes" rather than under "breaking changes"...
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
module.exports = function (branch, done) {
|
|
/**
|
|
* Creates a JSON version of the YAML test suite that can be simply bundled for use in the browser.
|
|
*/
|
|
var jsYaml = require('js-yaml');
|
|
var fs = require('fs');
|
|
var async = require('async');
|
|
var chalk = require('chalk');
|
|
var path = require('path');
|
|
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
|
var utils = require(fromRoot('src/lib/utils'));
|
|
var tests = {}; // populated in readYamlTests
|
|
|
|
var esDir = fromRoot('src/_elasticsearch_' + utils.snakeCase(branch));
|
|
|
|
// generate the yaml tests
|
|
async.series([
|
|
readYamlTests,
|
|
writeYamlTests,
|
|
writeTestIndex
|
|
], done);
|
|
|
|
function readYamlTests(done) {
|
|
var testDir = path.join(esDir, 'rest-api-spec/test/');
|
|
|
|
function readDirectories(dir) {
|
|
fs.readdirSync(dir).forEach(function (filename) {
|
|
var filePath = path.join(dir, filename);
|
|
var stat = fs.statSync(filePath);
|
|
if (stat.isDirectory()) {
|
|
readDirectories(filePath);
|
|
} else if (filename.match(/\.yaml$/)) {
|
|
var file = tests[path.relative(testDir, filePath)] = [];
|
|
jsYaml.loadAll(fs.readFileSync(filePath, 'utf8'), function (doc) {
|
|
file.push(doc);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
readDirectories(testDir);
|
|
done();
|
|
}
|
|
|
|
function writeYamlTests(done) {
|
|
var testFile = fromRoot('test/integration/yaml_suite/yaml_tests_' + utils.snakeCase(branch) + '.json');
|
|
fs.writeFileSync(testFile, JSON.stringify(tests, null, ' '), 'utf8');
|
|
console.log(chalk.white.bold('wrote') + ' YAML tests as JSON to', testFile);
|
|
done();
|
|
}
|
|
|
|
function writeTestIndex(done) {
|
|
var file = fromRoot('test/integration/yaml_suite/index_' + utils.snakeCase(branch) + '.js');
|
|
fs.writeFileSync(file, 'require(\'./run\')(\'' + branch + '\');\n', 'utf8');
|
|
console.log(chalk.white.bold('wrote') + ' YAML index to', file);
|
|
done();
|
|
}
|
|
};
|