Skip to content

Commit

Permalink
fix: drop tape as a dependency
Browse files Browse the repository at this point in the history
We use tap currently across the CLI, tape is legacy.
  • Loading branch information
lili2311 committed Feb 24, 2020
1 parent 64b5fd4 commit 075fb0a
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 278 deletions.
5 changes: 1 addition & 4 deletions test/acceptance/cli-test/cli-test.python.spec.ts
@@ -1,10 +1,7 @@
import * as fs from 'fs';
import * as sinon from 'sinon';
import { AcceptanceTests } from './cli-test.acceptance.test';

function loadJson(filename: string) {
return JSON.parse(fs.readFileSync(filename, 'utf-8'));
}
import { loadJson } from '../../utils';

export const PythonTests: AcceptanceTests = {
language: 'Python',
Expand Down
6 changes: 2 additions & 4 deletions test/api-key.test.ts
@@ -1,7 +1,7 @@
import { test } from 'tap';
import * as snyk from '../src/lib';

test('api token', (t) => {
test('api token', async (t) => {
const fromConfig = snyk.config.get('api');
t.equal(fromConfig, snyk.api, 'current api value matches config store');
const value = '_____test_____';
Expand All @@ -12,10 +12,9 @@ test('api token', (t) => {
} else {
snyk.config.delete('api');
}
t.end();
});

test('api token via env value', (t) => {
test('api token via env value', async (t) => {
const fromConfig = snyk.config.get('api');
t.equal(fromConfig, snyk.api, 'current api value matches config store');
const value = '_____test_____';
Expand All @@ -26,5 +25,4 @@ test('api token via env value', (t) => {
} else {
snyk.config.delete('api');
}
t.end();
});
4 changes: 1 addition & 3 deletions test/deep-deps.test.ts
Expand Up @@ -15,8 +15,6 @@ test('finds all sub-dependencies', async (t) => {
'marked has no dependencies',
);
} catch (e) {
t.fail(e.message);
console.log(e.stack);
t.bailout();
t.fail('Should have passed: ' + e);
}
});
8 changes: 0 additions & 8 deletions test/litmus.test.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/litmus.test.ts
@@ -0,0 +1,6 @@
import { test } from 'tap';
import * as snyk from '../src/lib';

test('does it load', async (t) => {
t.assert(snyk, 'snyk loaded');
});
74 changes: 0 additions & 74 deletions test/module-report.test.js

This file was deleted.

66 changes: 66 additions & 0 deletions test/module-report.test.ts
@@ -0,0 +1,66 @@
import { test } from 'tap';
import * as path from 'path';
import * as snyk from '../src/lib';

const cwd = process.cwd();
const osDir = path.resolve(__dirname, 'fixtures', 'demo-private');

async function runTests(t, error, modules) {
const expectedModules = {
express: '3.21.1',
autocache: '0.6.1',
less: '2.5.1',
marked: '0.2.10',
'demo-private': null,
};

if (error) {
t.fail(error.message);
}
t.ok(!error, 'module reading did not error');
t.ok(typeof modules === 'object', 'modules is an object');

const keys = Object.keys(modules.dependencies);
const count = keys.length;
t.equal(count, 4, 'dep count');

keys.forEach((key) => {
t.ok(expectedModules[key] !== undefined, key + ' was expected');

// special case for demo-private - as it doesn't have a version
if (key === 'demo-private') {
t.equal(modules[key].version, null, 'no version on demo-private');
t.equal(modules[key].valid, undefined, 'no dep test on demo-private');
} else {
t.equal(
expectedModules[key],
modules.dependencies[key].version,
key + ' version is correct',
);
t.equal(
modules.dependencies[key].valid,
true,
key + ' version was satisfied WRT dep',
);
}
});
}

test('module reporting: private project', async (t) => {
t.test('specified directory', async (t) => {
const modules = await snyk.modules(osDir);
await runTests(t, null, modules);
});

t.test('inferred directory', async (t) => {
process.chdir(osDir);

const modules = await snyk.modules('.');
await runTests(t, null, modules);
});
});

test('teardown', async (t) => {
process.chdir(cwd);
t.pass('reset cwd');
});
21 changes: 0 additions & 21 deletions test/no-deps.test.js

This file was deleted.

15 changes: 15 additions & 0 deletions test/no-deps.test.ts
@@ -0,0 +1,15 @@
import { test } from 'tap';
import * as path from 'path';
import * as snyk from '../src/lib';

const osDir = path.resolve(__dirname, 'fixtures', 'no-deps');

test('works when there are no dependencies', async (t) => {
try {
const modules = await snyk.modules(osDir);
t.ok(true, 'modules did not bail');
t.deepEqual(modules.dependencies, {});
} catch (e) {
t.fail('Should have passed:' + e);
}
});
20 changes: 0 additions & 20 deletions test/old-snyk-format.test.js

This file was deleted.

16 changes: 16 additions & 0 deletions test/old-snyk-format.test.ts
@@ -0,0 +1,16 @@
import * as policy from 'snyk-policy';
import { test } from 'tap';
import { loadJson } from './utils';

test('test sensibly bails if gets an old .snyk format', async (t) => {
try {
const vulns2 = loadJson(
__dirname + '/fixtures/test-jsbin-vulns-updated.json',
);
const config = await policy.load(__dirname + '/fixtures/old-snyk-config');
const res = await config.filter(vulns2);
t.fail('was expecting an error, got ' + JSON.stringify(res));
} catch (e) {
t.equal(e.code, 'OLD_DOTFILE_FORMAT');
}
});
2 changes: 1 addition & 1 deletion test/package-no-name.test.ts
@@ -1,4 +1,4 @@
import * as test from 'tape';
import { test } from 'tap';
import * as snyk from '../src/lib';

test('packages with no name read dir', async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion test/policy.test.ts
@@ -1,5 +1,5 @@
import * as policy from 'snyk-policy';
import * as test from 'tape';
import { test } from 'tap';
import { extendExpiries } from './utils';
import * as path from 'path';

Expand Down
2 changes: 1 addition & 1 deletion test/prompt-next-step.test.js
@@ -1,4 +1,4 @@
var test = require('tape');
var test = require('tap').test;
var prompts = require('../src/cli/commands/protect/prompts').nextSteps;

test('wizard next steps include protect correctly', function(t) {
Expand Down
2 changes: 1 addition & 1 deletion test/prompts-no-remediation.test.js
@@ -1,4 +1,4 @@
var test = require('tape');
var test = require('tap').test;
var getPrompts = require('../src/cli/commands/protect/prompts').getPrompts;
var vulns = require('./fixtures/test-jsbin-vulns-updated.json').vulnerabilities;

Expand Down
2 changes: 1 addition & 1 deletion test/protect-config.test.js
@@ -1,5 +1,5 @@
var protect = require('../src/lib/protect');
var test = require('tape');
var test = require('tap').test;
var plan = require('./fixtures/protect-interactive.json');
var expected = require('./fixtures/protect-interactive-config.json');

Expand Down
2 changes: 1 addition & 1 deletion test/protect-fail.test.js
Expand Up @@ -2,7 +2,7 @@ var applyPatch = require('../src/lib/protect/apply-patch');
var path = require('path');
var fs = require('fs');
var thenfs = require('then-fs');
var test = require('tape');
var test = require('tap').test;
var snyk = require('../src/lib');

test('bad patch file does not apply', function(t) {
Expand Down
62 changes: 0 additions & 62 deletions test/protect-patch-skip.test.js

This file was deleted.

0 comments on commit 075fb0a

Please sign in to comment.