1 | 'use strict';
|
2 |
|
3 | var test = require('tap').test
|
4 |
|
5 | var findShip = require('../')
|
6 | , path = require('path');
|
7 |
|
8 | test('\nfinding ship starting at lowest dir, looking for dependency unodep', function (t) {
|
9 |
|
10 | findShip(
|
11 | path.join(__dirname, 'uno', 'dos', 'tres')
|
12 | , function ismothership (pack) {
|
13 | return !!(pack.dependencies && pack.dependencies.unodep);
|
14 | }
|
15 | , function (err, res) {
|
16 | if (err) { t.fail(err); return t.end(); }
|
17 | t.equal(res.path, path.join(__dirname, 'uno', 'package.json'), 'resolves correct package.json path')
|
18 | t.equal(res.pack.name, 'uno', 'resolves correct package.json')
|
19 | t.end();
|
20 | }
|
21 | )
|
22 | })
|
23 |
|
24 | test('\nfinding ship starting at lowest dir, looking for dependency tresdep', function (t) {
|
25 |
|
26 | findShip(
|
27 | path.join(__dirname, 'uno', 'dos', 'tres')
|
28 | , function ismothership (pack) {
|
29 | return !!(pack.dependencies && pack.dependencies.tresdep);
|
30 | }
|
31 | , function (err, res) {
|
32 | if (err) { t.fail(err); return t.end(); }
|
33 | t.equal(res.path, path.join(__dirname, 'uno', 'dos', 'tres', 'package.json'), 'resolves correct package.json path')
|
34 | t.equal(res.pack.name, 'tres', 'resolves correct package.json')
|
35 | t.end();
|
36 | }
|
37 | )
|
38 | })
|
39 |
|
40 | test('\nfinding ship starting at lowest dir, looking for name dos', function (t) {
|
41 | findShip(
|
42 | path.join(__dirname, 'uno', 'dos', 'tres')
|
43 | , function ismothership (pack) {
|
44 | return pack.name === 'dos';
|
45 | }
|
46 | , function (err, res) {
|
47 | if (err) { t.fail(err); return t.end(); }
|
48 | t.equal(res.path, path.join(__dirname, 'uno', 'dos', 'package.json'), 'resolves correct package.json path')
|
49 | t.equal(res.pack.name, 'dos', 'resolves correct package.json')
|
50 | t.end();
|
51 | }
|
52 | )
|
53 | })
|
54 |
|
55 | test('\nfinding ship starting at lowest dir, looking for name cuatro - which does not exist', function (t) {
|
56 | findShip(
|
57 | path.join(__dirname, 'uno', 'dos', 'tres')
|
58 | , function ismothership (pack) {
|
59 | return pack.name === 'cuatro';
|
60 | }
|
61 | , function (err, res) {
|
62 | if (err) { t.fail(err); return t.end(); }
|
63 | t.notOk(res, 'finds no mother ship')
|
64 | t.end();
|
65 | }
|
66 | )
|
67 | })
|