diff --git a/.gitignore b/.gitignore index fde1afd01c6..8fc3e51c44a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ local.log tmp .DS_Store package-lock.json +!**/package-lock.json diff --git a/src/lib/snyk-test/npm/index.js b/src/lib/snyk-test/npm/index.js index 0534b1d09b8..8e71b1dcdb3 100644 --- a/src/lib/snyk-test/npm/index.js +++ b/src/lib/snyk-test/npm/index.js @@ -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); diff --git a/test/acceptance/cli.acceptance.test.js b/test/acceptance/cli.acceptance.test.js index 69f7d11d6ae..d668ebc8e98 100644 --- a/test/acceptance/cli.acceptance.test.js +++ b/test/acceptance/cli.acceptance.test.js @@ -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') diff --git a/test/fixtures/package-sans-name-lockfile/package-lock.json b/test/fixtures/package-sans-name-lockfile/package-lock.json new file mode 100644 index 00000000000..e4cea78a399 --- /dev/null +++ b/test/fixtures/package-sans-name-lockfile/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "semver": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-2.3.2.tgz", + "integrity": "sha1-uYSPJdbPNjMwc+ye+IVtQvEjPlI=" + } + } +} diff --git a/test/fixtures/package-sans-name-lockfile/package.json b/test/fixtures/package-sans-name-lockfile/package.json new file mode 100644 index 00000000000..4ac13f6fa20 --- /dev/null +++ b/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" + } +} diff --git a/test/package-no-name.test.js b/test/package-no-name.test.js index 6edc23d0075..fcad880f786 100644 --- a/test/package-no-name.test.js +++ b/test/package-no-name.test.js @@ -8,4 +8,13 @@ test('packages with no name read dir', function (t) { }).catch(function (e) { t.fail('Failed with: ' + e.message); }); -}); \ No newline at end of file +}); + +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); + }); +});