Skip to content

Commit

Permalink
fix: convert test to typescript
Browse files Browse the repository at this point in the history
Converting snyk test to typescript.
Co-authored-by: Lili Kastilio <lili@lilianakastilio.co.uk>
  • Loading branch information
gitphill committed Dec 9, 2019
1 parent b0bd447 commit 4377ae5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 57 deletions.
57 changes: 0 additions & 57 deletions src/lib/snyk-test/index.js

This file was deleted.

38 changes: 38 additions & 0 deletions src/lib/snyk-test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import chalk from 'chalk';
import * as detect from '../detect';
import runTest = require('./run-test');
import * as pm from '../package-managers';
import { UnsupportedPackageManagerError } from '../errors';
import { Options, TestOptions } from '../types';
import { LegacyVulnApiResult } from './legacy';

export = test;

async function test(root: string, options: any) {
try {
const packageManager = detect.detectPackageManager(root, options);
options.packageManager = packageManager;
const results = await run(root, options);
for (const res of results) {
if (!res.packageManager && packageManager) {
res.packageManager = packageManager;
}
}
if (results.length === 1) {
// Return only one result if only one found as this is the default usecase
return results[0];
}
// For gradle and yarnWorkspaces we may be returning more than one result
return results;
} catch (error) {
return Promise.reject(chalk.red.bold(error));
}
}

async function run(root: string, options: Options & TestOptions) {
const packageManager = options.packageManager;
if (!(options.docker || pm.SUPPORTED_PACKAGE_MANAGER_NAME[packageManager])) {
throw new UnsupportedPackageManagerError(packageManager);
}
return runTest(packageManager, root, options);
}

0 comments on commit 4377ae5

Please sign in to comment.