forked from sindresorhus/np
/
npmignore.js
78 lines (64 loc) · 2.49 KB
/
npmignore.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import path from 'path';
import test from 'ava';
import mockery from 'mockery';
import sinon from 'sinon';
let testedModule;
const gitUtilApi = {
newFilesSinceLastRelease: async () => {}
};
const pkgDirApi = {
sync: () => {}
};
test.before(() => {
const stubGitUtil = sinon.stub(gitUtilApi, 'newFilesSinceLastRelease');
mockery.registerAllowable('../source/util');
mockery.registerAllowable('../source/npm/util');
mockery.registerMock('./git-util', gitUtilApi);
mockery.registerMock('pkg-dir', pkgDirApi);
stubGitUtil.returns(['source/ignore.txt', 'source/pay_attention.txt', '.hg', 'test/file.txt']);
mockery.enable({
useCleanCache: true,
warnOnReplace: false,
warnOnUnregistered: false
});
// Mockery has to setup before module is loaded
testedModule = require('../source/util');
});
test.after(() => {
mockery.deregisterAll();
mockery.disable();
});
test.serial('ignored files using file-attribute in package.json with one file', async t => {
const stubPkgDir = sinon.stub();
stubPkgDir.returns(path.resolve('test', 'fixtures', 'package'));
pkgDirApi.sync = stubPkgDir;
t.deepEqual(await testedModule.getNewAndUnpublishedFiles({files: ['pay_attention.txt']}),
['source/ignore.txt', 'test/file.txt']);
});
test.serial('ignored files using file-attribute in package.json with multiple file', async t => {
const stubPkgDir = sinon.stub();
stubPkgDir.returns(path.resolve('test', 'fixtures', 'package'));
pkgDirApi.sync = stubPkgDir;
t.deepEqual(await testedModule.getNewAndUnpublishedFiles(
{files: ['pay_attention.txt', 'ignore.txt']}), ['test/file.txt']);
});
test.serial('ignored file using file-attribute in package.json with directory', async t => {
const stubPkgDir = sinon.stub();
stubPkgDir.returns(path.resolve('test', 'fixtures', 'package'));
pkgDirApi.sync = stubPkgDir;
t.deepEqual(await testedModule.getNewAndUnpublishedFiles(
{files: ['source']}), ['test/file.txt']);
});
test.serial('ignored files using .npmignore', async t => {
const stubPkgDir = sinon.stub();
stubPkgDir.returns(path.resolve('test', 'fixtures', 'npmignore'));
pkgDirApi.sync = stubPkgDir;
t.deepEqual(await testedModule.getNewAndUnpublishedFiles({name: 'without file-attribute'}),
['source/ignore.txt', 'test/file.txt']);
});
test.serial('ignore strategy is not used', async t => {
const stubPkgDir = sinon.stub();
stubPkgDir.returns(path.resolve('test', 'fixtures'));
pkgDirApi.sync = stubPkgDir;
t.true(await testedModule.getNewAndUnpublishedFiles({name: 'without file-attribute'}) === undefined);
});