Skip to content

Commit

Permalink
fix: propagate correct relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
orsagie committed Oct 31, 2019
1 parent 14cdb94 commit 7c489d5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/lib/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export async function monitor(

const target = await getTarget(pkg, meta);
const targetFileRelativePath = targetFile
? path.relative(root, targetFile)
? path.join(path.resolve(root), targetFile)
: '';

if (target && target.branch) {
Expand Down Expand Up @@ -285,7 +285,7 @@ export async function monitorGraph(

const target = await getTarget(pkg, meta);
const targetFileRelativePath = targetFile
? path.relative(root, targetFile)
? path.join(path.resolve(root), targetFile)
: '';

if (target && target.branch) {
Expand Down
34 changes: 34 additions & 0 deletions test/acceptance/cli.acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3212,6 +3212,11 @@ test('`monitor sbt package --experimental-dep-graph --sbt-graph`', async (t) =>
t.equal(req.method, 'PUT', 'makes PUT request');
t.match(req.url, '/monitor/sbt/graph', 'puts at correct url');
t.ok(req.body.depGraphJSON, 'sends depGraphJSON');
t.match(
req.body.targetFileRelativePath,
'/test/acceptance/workspaces/sbt-simple-struts/build.sbt',
'matching file path',
);
});

test('`monitor yarn-package`', async (t) => {
Expand All @@ -3231,6 +3236,35 @@ test('`monitor yarn-package`', async (t) => {
t.notOk(pkg.dependencies['object-assign'], 'no dev dependency');
t.notOk(pkg.from, 'no "from" array on root');
t.notOk(pkg.dependencies.debug.from, 'no "from" array on dep');
t.match(
req.body.targetFileRelativePath,
'/test/acceptance/workspaces/yarn-package/yarn.lock',
'matching file path',
);
});

test('`monitor yarn-package from within folder`', async (t) => {
chdirWorkspaces('yarn-package');
await cli.monitor();
const req = server.popRequest();
const pkg = req.body.package;
t.equal(req.method, 'PUT', 'makes PUT request');
t.equal(
req.headers['x-snyk-cli-version'],
versionNumber,
'sends version number',
);
t.match(req.url, '/monitor/yarn', 'puts at correct url');
t.ok(pkg.dependencies.debug, 'dependency');
t.notOk(req.body.targetFile, 'doesnt send the targetFile');
t.notOk(pkg.dependencies['object-assign'], 'no dev dependency');
t.notOk(pkg.from, 'no "from" array on root');
t.notOk(pkg.dependencies.debug.from, 'no "from" array on dep');
t.match(
req.body.targetFileRelativePath,
'/test/acceptance/workspaces/yarn-package/yarn.lock',
'matching file path',
);
});

test('`monitor npm-package with custom --project-name`', async (t) => {
Expand Down
13 changes: 7 additions & 6 deletions test/monitor-target.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test, afterEach, afterAll } from 'tap';
import * as requestLib from 'needle';
import * as path from 'path';

import * as _ from 'lodash';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -61,9 +62,9 @@ test('Make sure that target is sent correctly', async (t) => {
'http://github.com/snyk/project.git',
'correct name passed to request',
);
t.equals(
t.match(
data.targetFileRelativePath,
'package.json',
'snyk' + path.sep + 'package.json',
'correct relative target file path passed to request',
);

Expand All @@ -78,9 +79,9 @@ test("Make sure it's not failing monitor for non git projects", async (t) => {

t.true(requestSpy.calledOnce, 'needle.request was called once');
t.true(_.isEmpty(data.target), 'empty target passed to request');
t.equals(
t.match(
data.targetFileRelativePath,
'package.json',
'snyk' + path.sep + 'package.json',
'targetFileRelativePath passed to request',
);

Expand All @@ -95,9 +96,9 @@ test("Make sure it's not failing if there is no remote configured", async (t) =>

t.true(requestSpy.calledOnce, 'needle.request was called once');
t.true(_.isEmpty(data.target), 'empty target passed to request');
t.equals(
t.match(
data.targetFileRelativePath,
'package.json',
'snyk' + path.sep + 'package.json',
'targetFileRelativePath passed to request',
);
subProcessStub.restore();
Expand Down

0 comments on commit 7c489d5

Please sign in to comment.