Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL] static translator and normalizer: added tests #75

Merged
merged 7 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/normalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const projectPreprocessor = require("./projectPreprocessor");
* @param {string} options.translator Translator to use
* @returns {Promise} Promise resolving to tree object
*/
async function generateProjectTree(options) {
async function generateProjectTree(options = {}) {
const tree = await generateDependencyTree(options);

if (options.configPath) {
Expand All @@ -34,7 +34,7 @@ async function generateProjectTree(options) {
* @param {string} options.translator Translator to use
* @returns {Promise} Promise resolving to tree object
*/
async function generateDependencyTree(options) {
async function generateDependencyTree(options = { }) {
log.verbose("Building dependency tree...");
const cwd = options && options.cwd || ".";

Expand All @@ -55,7 +55,7 @@ async function generateDependencyTree(options) {
translator = require("./translators/npm");
break;
default:
throw new Error(`Unkown translator ${translatorName}`);
return Promise.reject(new Error(`Unknown translator ${translatorName}`));
}

return translator.generateDependencyTree(cwd, translatorParams);
Expand Down
6 changes: 4 additions & 2 deletions lib/translators/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ const parseYaml = require("js-yaml").safeLoad;
* @param {Array} [translatorOptions] Configuration options
* @returns {Promise} Promise resolving with a dependency tree
*/
function generateDependencyTree(dirPath, translatorOptions) {
function generateDependencyTree(dirPath, translatorOptions = []) {
const depFilePath = translatorOptions[0] || path.join(dirPath, "projectDependencies.yaml");

return new Promise(function(resolve, reject) {
fs.readFile(depFilePath, function(err, buffer) {
if (err) {
reject(err);
reject(new Error(
`[static translator] Failed to locate projectDependencies.json for "${dirPath}"`)
RandomByte marked this conversation as resolved.
Show resolved Hide resolved
);
} else {
resolve(parseYaml(buffer.toString(), {
filename: depFilePath
Expand Down
Loading