File: test.js

package info (click to toggle)
node-find-cache-dir 0.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 100 kB
  • ctags: 5
  • sloc: makefile: 2; sh: 2
file content (43 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import _test from 'ava';
import fn from './';
import path from 'path';
import rimraf from 'rimraf';
import fs from 'fs';

const test = _test.serial;

test('finds from a list of files', t => {
	process.chdir(path.join(__dirname, '..'));
	const files = ['foo/bar', 'baz/quz'].map(file => path.join(__dirname, file));
	t.is(fn({files, name: 'blah'}), path.join(__dirname, 'node_modules', '.cache', 'blah'));
});

test('finds from process.cwd', t => {
	process.chdir(path.join(__dirname));
	t.is(fn({name: 'foo'}), path.join(__dirname, 'node_modules', '.cache', 'foo'));
});

test('finds from options.cwd', t => {
	process.chdir(path.join(__dirname, '..'));
	t.is(fn({cwd: __dirname, name: 'bar'}), path.join(__dirname, 'node_modules', '.cache', 'bar'));
});

test('creates dir', t => {
	const dir = path.join(__dirname, 'node_modules', '.cache', 'created');
	rimraf.sync(dir);
	fn({create: true, name: 'created', cwd: __dirname});
	t.true(fs.existsSync(dir));
});

test('thunk', t => {
	const dir = path.join(__dirname, 'node_modules', '.cache', 'thunked');
	rimraf.sync(dir);
	const thunk = fn({thunk: true, name: 'thunked', cwd: __dirname});
	t.is(thunk('foo'), path.join(dir, 'foo'));
	t.is(thunk('bar'), path.join(dir, 'bar'));
});

test('returns null if it can\'t find package.json', t => {
	process.chdir(path.join(__dirname, '..'));
	t.is(fn({name: 'foo'}), null);
});