@looker/sdk-rtl
Version:
Looker SDK Runtime Library
40 lines • 1.38 kB
JavaScript
import * as fs from 'fs';
import path from 'path';
import * as yaml from 'js-yaml';
import { findRootSync } from '@manypkg/find-root';
import { config } from 'dotenv';
var utf8 = 'utf-8';
var rootPath = '';
export var getRootPath = () => {
if (!rootPath) {
rootPath = findRootSync(__dirname).rootDir;
}
return rootPath;
};
export var rootFile = function rootFile() {
var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
return path.join(getRootPath(), fileName);
};
export var readFile = fileName => fs.readFileSync(fileName, utf8);
export var TestConfig = function TestConfig() {
var rootPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
config();
var testFile = 'data.yml';
rootPath = rootPath || getRootPath();
var localIni = process.env.LOOKERSDK_INI || rootFile('looker.ini');
var testPath = "".concat(rootPath, "/packages/sdk-codegen-utils/data/");
var dataFile = "".concat(testPath).concat(testFile);
var testData = fs.existsSync(dataFile) ? yaml.load(fs.readFileSync(dataFile, utf8)) : {};
var testIni = "".concat(rootPath).concat(testData.iniFile);
if (!fs.existsSync(localIni)) localIni = '';
if (!fs.existsSync(testIni)) testIni = '';
return {
dataFile,
localIni,
rootPath,
testData,
testIni,
testPath
};
};
//# sourceMappingURL=testUtils.js.map