Skip to content

Commit

Permalink
test: verify behaviour on node 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mila Votradovec committed Sep 21, 2018
1 parent 08d6248 commit da3d92c
Showing 1 changed file with 83 additions and 70 deletions.
153 changes: 83 additions & 70 deletions test/acceptance/cli.acceptance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,81 +582,94 @@ test('`test npm-package-missing-dep ` in package-lock works', function (t) {
});
});

test('`test npm-package --file=yarn.lock ` sends pkg info', function (t) {
chdirWorkspaces();
return cli.test('npm-package', {file: 'yarn.lock'})
.then(function () {
var req = server.popRequest();
var pkg = req.body;
t.equal(req.method, 'POST', 'makes POST request');
t.match(req.url, '/vuln/npm', 'posts to correct url');
t.ok(pkg.dependencies['debug'], 'dependency');
t.ok(pkg.dependencies['debug'].dependencies['ms'], 'transitive dependency');
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');
});
});
// Unfortunately, lockfile parser for yarn doesn't work on node < 6
// https://github.com/snyk/nodejs-lockfile-parser/blob/master/lib/parsers/yarn-lock-parse.ts#L32
if (parseInt(process.version.slice(1).split('.')[0], 10) < 6) {
test('Testing yarn.lock on node 4', async (t) => {
return cli.test('npm-package-missing-dep', {file: 'yarn.lock'})
.catch((e) => {
t.includes(e.message,
'less than 6. Please upgrade your Node.js',
'Information about non-supported environment is shown');
});
});
} else {
test('`test npm-package --file=yarn.lock ` sends pkg info', function (t) {
chdirWorkspaces();
return cli.test('npm-package', {file: 'yarn.lock'})
.then(function () {
var req = server.popRequest();
var pkg = req.body;
t.equal(req.method, 'POST', 'makes POST request');
t.match(req.url, '/vuln/npm', 'posts to correct url');
t.ok(pkg.dependencies['debug'], 'dependency');
t.ok(pkg.dependencies['debug'].dependencies['ms'], 'transitive dependency');
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');
});
});

test('`test npm-package --file=yarn.lock --dev` sends pkg info', function (t) {
chdirWorkspaces();
return cli.test('npm-package', {file: 'yarn.lock', dev: true})
.then(function () {
var req = server.popRequest();
var pkg = req.body;
t.equal(req.method, 'POST', 'makes POST request');
t.match(req.url, '/vuln/npm', 'posts to correct url');
t.ok(pkg.dependencies['debug'], 'dependency');
t.ok(pkg.dependencies['debug'].dependencies['ms'], 'transitive dependency');
t.ok(pkg.dependencies['object-assign'],
'dev dependency included');
t.notOk(pkg.from, 'no "from" array on root');
t.notOk(pkg.dependencies['debug'].from,
'no "from" array on dep');
});
});
test('`test npm-package --file=yarn.lock --dev` sends pkg info', function (t) {
chdirWorkspaces();
return cli.test('npm-package', {file: 'yarn.lock', dev: true})
.then(function () {
var req = server.popRequest();
var pkg = req.body;
t.equal(req.method, 'POST', 'makes POST request');
t.match(req.url, '/vuln/npm', 'posts to correct url');
t.ok(pkg.dependencies['debug'], 'dependency');
t.ok(pkg.dependencies['debug'].dependencies['ms'], 'transitive dependency');
t.ok(pkg.dependencies['object-assign'],
'dev dependency included');
t.notOk(pkg.from, 'no "from" array on root');
t.notOk(pkg.dependencies['debug'].from,
'no "from" array on dep');
});
});

test('`test npm-package-shrinkwrap --file=yarn.lock ` with npm-shrinkwrap errors', function (t) {
t.plan(1);
chdirWorkspaces();
return cli.test('npm-package-shrinkwrap', {file: 'yarn.lock'})
.catch((e) => {
t.includes(e.message, '--file=yarn.lock', 'Contains enough info about error');
});
});
test('`test npm-package-shrinkwrap --file=yarn.lock ` with npm-shrinkwrap errors', function (t) {
t.plan(1);
chdirWorkspaces();
return cli.test('npm-package-shrinkwrap', {file: 'yarn.lock'})
.catch((e) => {
t.includes(e.message, '--file=yarn.lock', 'Contains enough info about error');
});
});

test('`test npm-package-with-subfolder --file=yarn.lock ` picks top-level files', function (t) {
chdirWorkspaces();
return cli.test('npm-package-with-subfolder', {file: 'yarn.lock'})
.then(function () {
var req = server.popRequest();
var pkg = req.body;
t.equal(pkg.name, 'npm-package-top-level', 'correct package is taken');
t.ok(pkg.dependencies['to-array'], 'dependency');
});
});
test('`test npm-package-with-subfolder --file=yarn.lock ` picks top-level files', function (t) {
chdirWorkspaces();
return cli.test('npm-package-with-subfolder', {file: 'yarn.lock'})
.then(function () {
var req = server.popRequest();
var pkg = req.body;
t.equal(pkg.name, 'npm-package-top-level', 'correct package is taken');
t.ok(pkg.dependencies['to-array'], 'dependency');
});
});

test('`test npm-package-with-subfolder --file=subfolder/yarn.lock ` picks subfolder files', function (t) {
chdirWorkspaces();
return cli.test('npm-package-with-subfolder', {file: 'subfolder/yarn.lock'})
.then(function () {
var req = server.popRequest();
var pkg = req.body;
t.equal(pkg.name, 'npm-package-subfolder', 'correct package is taken');
t.ok(pkg.dependencies['to-array'], 'dependency');
});
});
test('`test npm-package-with-subfolder --file=subfolder/yarn.lock ` picks subfolder files', function (t) {
chdirWorkspaces();
return cli.test('npm-package-with-subfolder', {file: 'subfolder/yarn.lock'})
.then(function () {
var req = server.popRequest();
var pkg = req.body;
t.equal(pkg.name, 'npm-package-subfolder', 'correct package is taken');
t.ok(pkg.dependencies['to-array'], 'dependency');
});
});

test('`test npm-package-missing-dep --file=yarn.lock ` with missing dep errors', function (t) {
t.plan(1);
chdirWorkspaces();
return cli.test('npm-package-missing-dep', {file: 'yarn.lock'})
.catch((e) => {
t.includes(e.message, 'out of sync', 'Contains enough info about error');
});
});
test('`test npm-package-missing-dep --file=yarn.lock ` with missing dep errors', function (t) {
t.plan(1);
chdirWorkspaces();
return cli.test('npm-package-missing-dep', {file: 'yarn.lock'})
.catch((e) => {
t.includes(e.message, 'out of sync', 'Contains enough info about error');
});
});
}

test('`test` on a yarn package does work and displays appropriate text',
function (t) {
Expand Down

0 comments on commit da3d92c

Please sign in to comment.