Skip to content

Commit

Permalink
fix: add tests for missing package name
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliabaron committed Dec 7, 2018
1 parent 61889f8 commit 640eb2c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ local.log
tmp
.DS_Store
package-lock.json
!**/package-lock.json
5 changes: 0 additions & 5 deletions src/lib/snyk-test/npm/index.js
Expand Up @@ -75,11 +75,6 @@ function test(root, options) {
return pkg;
});
}).then((pkg) => {
// if there's no package name, let's get it from the root dir
if (!pkg.name) {
pkg.name = path.basename(path.resolve(root));
}

policyLocations = policyLocations.concat(pluckPolicies(pkg));
debug('policies found', policyLocations);
analytics.add('policies', policyLocations.length);
Expand Down
24 changes: 24 additions & 0 deletions test/acceptance/cli.acceptance.test.js
Expand Up @@ -1815,6 +1815,30 @@ test('`monitor non-existing`', function (t) {
});
});

test('monitor for package with no name', function (t) {
t.plan(1);
return cli.monitor({
file: __dirname + '/../fixtures/package-sans-name/package.json',
})
.then(function () {
t.pass('succeed');
}).catch(function (e) {
t.fail('Failed with: ' + e.message);
});
});

test('monitor for package with no name in lockfile', function (t) {
t.plan(1);
return cli.monitor({
file: __dirname + '/../fixtures/package-sans-name-lockfile/package-lock.json',
})
.then(function () {
t.pass('succeed');
}).catch(function (e) {
t.fail('Failed with: ' + e.message);
});
});

test('`monitor npm-package`', function (t) {
chdirWorkspaces();
return cli.monitor('npm-package')
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/package-sans-name-lockfile/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/fixtures/package-sans-name-lockfile/package.json
@@ -0,0 +1,12 @@
{
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"semver": "^2.3.2"
}
}
11 changes: 10 additions & 1 deletion test/package-no-name.test.js
Expand Up @@ -8,4 +8,13 @@ test('packages with no name read dir', function (t) {
}).catch(function (e) {
t.fail('Failed with: ' + e.message);
});
});
});

test('packages with no name read dir with a lockfile', function (t) {
t.plan(1);
snyk.test(__dirname + '/fixtures/package-sans-name-lockfile').then(function () {
t.pass('succeed');
}).catch(function (e) {
t.fail('Failed with: ' + e.message);
});
});

0 comments on commit 640eb2c

Please sign in to comment.