Skip to content

Commit

Permalink
fix: only send targetFile on test when needed
Browse files Browse the repository at this point in the history
Previously targetFile was ALWAYS sent to the API when
test command was run
  • Loading branch information
Joe Holdcroft committed Jul 22, 2019
1 parent 3fbf139 commit b99e974
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/snyk-test/run-test.ts
Expand Up @@ -314,7 +314,7 @@ async function assembleLocalPayloads(root, options: Options & TestOptions): Prom
}

let body: PayloadBody = {
targetFile: pkg.targetFile || options.file,
targetFile: pkg.targetFile,
projectNameOverride: options.projectName,
policy: policy && policy.toString(),
docker: pkg.docker,
Expand Down
68 changes: 59 additions & 9 deletions test/acceptance/cli.acceptance.test.ts
Expand Up @@ -129,13 +129,14 @@ test('`test sinatra --registry=rubygems` sends remote Rubygems request:', async
* Local source `test`
*/

test('`test project with custom --project-name`', async (t) => {
test('`test npm-package with custom --project-name`', async (t) => {
chdirWorkspaces();
await cli.test('project', {
await cli.test('npm-package', {
'project-name': 'custom-project-name',
});
const req = server.popRequest();
t.equal(req.body.projectNameOverride, 'custom-project-name');
t.match(req.body.projectNameOverride, 'custom-project-name', 'custom project name is passed');
t.match(req.targetFile, undefined, 'target is undefined');
});

test('`test empty --file=Gemfile`', async (t) => {
Expand Down Expand Up @@ -945,6 +946,7 @@ test('`test maven-app --file=pom.xml --dev` sends package info', async (t) => {
t.equal(req.method, 'POST', 'makes POST request');
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.equal(req.query.org, 'nobelprize.org', 'org sent as a query in request');
t.match(req.targetFile, undefined, 'target is undefined');

const depGraph = depGraphLib.createFromJSON(req.body.depGraph);
t.equal(depGraph.rootPkg.name, 'com.mycompany.app:maven-app', 'root name');
Expand All @@ -959,6 +961,7 @@ test('`test npm-package` sends pkg info', async (t) => {
await cli.test('npm-package');
const req = server.popRequest();
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.match(req.targetFile, undefined, 'target is undefined');
const depGraph = req.body.depGraph;

t.same(
Expand All @@ -972,6 +975,7 @@ test('`test npm-package --file=package-lock.json ` sends pkg info', async (t) =>
await cli.test('npm-package', {file: 'package-lock.json'});
const req = server.popRequest();
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.match(req.targetFile, undefined, 'target is undefined');
const depGraph = req.body.depGraph;
t.same(
depGraph.pkgs.map((p) => p.id).sort(),
Expand All @@ -984,6 +988,7 @@ test('`test npm-package --file=package-lock.json --dev` sends pkg info', async (
await cli.test('npm-package', {file: 'package-lock.json', dev: true});
const req = server.popRequest();
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.match(req.targetFile, undefined, 'target is undefined');
const depGraph = req.body.depGraph;
t.same(
depGraph.pkgs.map((p) => p.id).sort(),
Expand Down Expand Up @@ -1108,6 +1113,7 @@ test('`test yarn-package --file=yarn.lock ` sends pkg info', async (t) => {
await cli.test('yarn-package', {file: 'yarn.lock'});
const req = server.popRequest();
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.match(req.targetFile, undefined, 'target is undefined');
const depGraph = req.body.depGraph;
t.same(
depGraph.pkgs.map((p) => p.id).sort(),
Expand All @@ -1120,6 +1126,7 @@ test('`test yarn-package --file=yarn.lock --dev` sends pkg info', async (t) => {
await cli.test('yarn-package', {file: 'yarn.lock', dev: true});
const req = server.popRequest();
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.match(req.targetFile, undefined, 'target is undefined');
const depGraph = req.body.depGraph;
t.same(
depGraph.pkgs.map((p) => p.id).sort(),
Expand Down Expand Up @@ -1155,6 +1162,7 @@ test('`test` on a yarn package does work and displays appropriate text', async (
const req = server.popRequest();
t.equal(req.method, 'POST', 'makes POST request');
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.match(req.targetFile, undefined, 'target is undefined');
const depGraph = req.body.depGraph;
t.same(
depGraph.pkgs.map((p) => p.id).sort(),
Expand Down Expand Up @@ -1326,7 +1334,14 @@ test('`test nuget-app --file=project.json`', async (t) => {
chdirWorkspaces();
const plugin = {
async inspect() {
return {package: {}, plugin: {name: 'testplugin', runtime: 'testruntime'}};
return {
package: {},
plugin: {
name: 'testplugin',
runtime: 'testruntime',
targetFile: 'project.json',
}
};
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');
Expand Down Expand Up @@ -1403,7 +1418,14 @@ test('`test golang-gomodules --file=go.mod`', async (t) => {
chdirWorkspaces();
const plugin = {
async inspect() {
return {package: {}, plugin: {name: 'testplugin', runtime: 'testruntime'}};
return {
package: {},
plugin: {
name: 'testplugin',
runtime: 'testruntime',
targetFile: 'go.mod',
}
};
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');
Expand Down Expand Up @@ -1438,7 +1460,14 @@ test('`test golang-app` auto-detects golang-gomodules', async (t) => {
chdirWorkspaces();
const plugin = {
async inspect() {
return {package: {}, plugin: {name: 'testplugin', runtime: 'testruntime'}};
return {
package: {},
plugin: {
name: 'testplugin',
runtime: 'testruntime',
targetFile: 'go.mod',
}
};
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');
Expand Down Expand Up @@ -1471,7 +1500,14 @@ test('`test golang-app --file=Gopkg.lock`', async (t) => {
chdirWorkspaces();
const plugin = {
async inspect() {
return {package: {}, plugin: {name: 'testplugin', runtime: 'testruntime'}};
return {
package: {},
plugin: {
name: 'testplugin',
runtime: 'testruntime',
targetFile: 'Gopkg.lock',
}
};
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');
Expand Down Expand Up @@ -1506,7 +1542,14 @@ test('`test golang-app --file=vendor/vendor.json`', async (t) => {
chdirWorkspaces();
const plugin = {
async inspect() {
return {package: {}, plugin: {name: 'testplugin', runtime: 'testruntime'}};
return {
package: {},
plugin: {
name: 'testplugin',
runtime: 'testruntime',
targetFile: 'vendor/vendor.json',
}
};
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');
Expand Down Expand Up @@ -1541,7 +1584,14 @@ test('`test golang-app` auto-detects golang/dep', async (t) => {
chdirWorkspaces();
const plugin = {
async inspect() {
return {package: {}, plugin: {name: 'testplugin', runtime: 'testruntime'}};
return {
package: {},
plugin: {
name: 'testplugin',
runtime: 'testruntime',
targetFile: 'Gopkg.lock',
}
};
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');
Expand Down

0 comments on commit b99e974

Please sign in to comment.