Skip to content

Commit

Permalink
feat: enable paket to be autodetected with --all-projects
Browse files Browse the repository at this point in the history
  • Loading branch information
orsagie committed Jan 28, 2020
1 parent 7e30ef6 commit db34336
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const AUTO_DETECTABLE_FILES: string[] = [
'Gemfile.lock',
'pom.xml',
'packages.config',
'paket.dependencies',
'project.json',
'project.assets.json',
'Podfile',
Expand Down
74 changes: 68 additions & 6 deletions test/acceptance/cli-monitor/cli-monitor.all-projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const AllProjectsTests: AcceptanceTests = {
t.ok(spyPlugin.withArgs('rubygems').calledOnce, 'calls rubygems plugin');
t.ok(spyPlugin.withArgs('npm').calledOnce, 'calls npm plugin');
t.ok(spyPlugin.withArgs('maven').calledOnce, 'calls maven plugin');
t.ok(spyPlugin.withArgs('nuget').calledOnce, 'calls nuget plugin');
t.ok(spyPlugin.withArgs('paket').calledOnce, 'calls nuget plugin');

// npm
t.match(
result,
Expand All @@ -38,18 +41,39 @@ export const AllProjectsTests: AcceptanceTests = {
'rubygems/some/project-id',
'rubygems project was monitored',
);

// nuget
t.match(result, 'nuget/some/project-id', 'nuget project was monitored');
// paket
t.match(result, 'paket/some/project-id', 'paket project was monitored');
// maven
t.match(result, 'maven/some/project-id', 'maven project was monitored ');
// Pop all calls to server and filter out calls to `featureFlag` endpoint
const requests = params.server
.popRequests(4)
.popRequests(6)
.filter((req) => req.url.includes('/monitor/'));
t.equal(requests.length, 3, 'Correct amount of monitor requests');
t.equal(requests.length, 5, 'Correct amount of monitor requests');

const pluginsWithoutTragetFilesInBody = [
'snyk-nodejs-lockfile-parser',
'bundled:maven',
'bundled:rubygems',
];

requests.forEach((req) => {
t.match(req.url, '/monitor/', 'puts at correct url');
t.notOk(req.body.targetFile, "doesn't send the targetFile");
if (
pluginsWithoutTragetFilesInBody.includes(req.body.meta.pluginName)
) {
t.notOk(
req.body.targetFile,
`doesn\'t send the targetFile for ${req.body.meta.pluginName}`,
);
} else {
t.ok(
req.body.targetFile,
`does send the targetFile ${req.body.meta.pluginName}`,
);
}
t.equal(req.method, 'PUT', 'makes PUT request');
t.equal(
req.headers['x-snyk-cli-version'],
Expand Down Expand Up @@ -147,8 +171,22 @@ export const AllProjectsTests: AcceptanceTests = {
detectionDepth: 1,
});
// Pop all calls to server and filter out calls to `featureFlag` endpoint
const [rubyAll, npmAll, mavenAll] = params.server
.popRequests(4)
const [
rubyAll,
npmAll,
nugetAll,
paketAll,
mavenAll,
] = params.server
.popRequests(6)
.filter((req) => req.url.includes('/monitor/'));

// nuget
await params.cli.monitor('mono-repo-project', {
file: 'packages.config',
});
const [requestsNuget] = params.server
.popRequests(2)
.filter((req) => req.url.includes('/monitor/'));

// Ruby
Expand All @@ -175,6 +213,14 @@ export const AllProjectsTests: AcceptanceTests = {
.popRequests(2)
.filter((req) => req.url.includes('/monitor/'));

// paket
await params.cli.monitor('mono-repo-project', {
file: 'paket.dependencies',
});
const [requestsPaket] = params.server
.popRequests(2)
.filter((req) => req.url.includes('/monitor/'));

// Ruby project

t.deepEqual(
Expand All @@ -191,13 +237,29 @@ export const AllProjectsTests: AcceptanceTests = {
'Same body for --all-projects and --file=package-lock.json',
);

// NUGET project

t.deepEqual(
nugetAll.body,
requestsNuget.body,
'Same body for --all-projects and --file=packages.config',
);

// Maven project

t.deepEqual(
mavenAll.body,
requestsMaven.body,
'Same body for --all-projects and --file=pom.xml',
);

// Paket project

t.deepEqual(
paketAll.body,
requestsPaket.body,
'Same body for --all-projects and --file=paket.dependencies',
);
},
'`monitor mono-repo-project with lockfiles --all-projects --json`': (
params,
Expand Down
31 changes: 28 additions & 3 deletions test/acceptance/cli-test/cli-test.all-projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export const AllProjectsTests: AcceptanceTests = {
t.ok(spyPlugin.withArgs('rubygems').calledOnce, 'calls rubygems plugin');
t.ok(spyPlugin.withArgs('npm').calledOnce, 'calls npm plugin');
t.ok(spyPlugin.withArgs('maven').calledOnce, 'calls maven plugin');
t.ok(spyPlugin.withArgs('nuget').calledOnce, 'calls nuget plugin');
t.ok(spyPlugin.withArgs('paket').calledOnce, 'calls nuget plugin');

params.server.popRequests(3).forEach((req) => {
params.server.popRequests(5).forEach((req) => {
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
Expand All @@ -33,7 +35,7 @@ export const AllProjectsTests: AcceptanceTests = {
t.ok(req.body.depGraph, 'body contains depGraph');
t.match(
req.body.depGraph.pkgManager.name,
/(npm|rubygems|maven)/,
/(npm|rubygems|maven|nuget|paket)/,
'depGraph has package manager',
);
});
Expand Down Expand Up @@ -86,14 +88,26 @@ export const AllProjectsTests: AcceptanceTests = {
const [
rubyAllProjectsBody,
npmAllProjectsBody,
nugetAllProjectsBody,
paketAllProjectsBody,
mavenAllProjectsBody,
] = params.server.popRequests(3).map((req) => req.body);
] = params.server.popRequests(5).map((req) => req.body);

await params.cli.test('mono-repo-project', {
file: 'Gemfile.lock',
});
const { body: rubyFileBody } = params.server.popRequest();

await params.cli.test('mono-repo-project', {
file: 'paket.dependencies',
});
const { body: paketFileBody } = params.server.popRequest();

await params.cli.test('mono-repo-project', {
file: 'packages.config',
});
const { body: nugetFileBody } = params.server.popRequest();

await params.cli.test('mono-repo-project', {
file: 'package-lock.json',
});
Expand All @@ -116,6 +130,17 @@ export const AllProjectsTests: AcceptanceTests = {
'Same body for --all-projects and --file=package-lock.json',
);

t.same(
paketAllProjectsBody,
paketFileBody,
'Same body for --all-projects and --file=package-lock.json',
);

t.same(
nugetAllProjectsBody,
nugetFileBody,
'Same body for --all-projects and --file=package-lock.json',
);
t.same(
mavenAllProjectsBody,
mavenFileBody,
Expand Down
4 changes: 4 additions & 0 deletions test/acceptance/workspaces/mono-repo-project/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
redirects: on
source https://nuget.org/api/v2

nuget FSharp.Formatting
nuget FAKE
10 changes: 10 additions & 0 deletions test/acceptance/workspaces/mono-repo-project/paket.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
REDIRECTS: ON
NUGET
remote: https://www.nuget.org/api/v2
FAKE (5.8.4)
FSharp.Compiler.Service (2.0.0.6)
FSharp.Formatting (2.14.4)
FSharp.Compiler.Service (2.0.0.6)
FSharpVSPowerTools.Core (>= 2.3 < 2.4)
FSharpVSPowerTools.Core (2.3)
FSharp.Compiler.Service (>= 2.0.0.3)

0 comments on commit db34336

Please sign in to comment.