]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/fstream-npm/test/ignores.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / fstream-npm / test / ignores.js
1 var fs = require('graceful-fs')
2 var join = require('path').join
3
4 var mkdirp = require('mkdirp')
5 var rimraf = require('rimraf')
6 var test = require('tap').test
7
8 var Packer = require('..')
9
10 var pkg = join(__dirname, 'test-package')
11
12 var elfJS = function () {/*
13 module.exports = function () {
14   console.log("i'm a elf")
15 }
16 */}.toString().split('\n').slice(1, -1).join()
17
18 var json = {
19   'name': 'test-package',
20   'version': '3.1.4',
21   'main': 'elf.js'
22 }
23
24 test('setup', function (t) {
25   setup()
26   t.end()
27 })
28
29 var included = [
30   'package.json',
31   'elf.js',
32   join('deps', 'foo', 'config', 'config.gypi')
33 ]
34
35 test('follows npm package ignoring rules', function (t) {
36   var subject = new Packer({ path: pkg, type: 'Directory', isDirectory: true })
37   var filenames = []
38   subject.on('entry', function (entry) {
39     t.equal(entry.type, 'File', 'only files in this package')
40
41     // include relative path in filename
42     var filename = entry._path.slice(entry.root._path.length + 1)
43
44     filenames.push(filename)
45   })
46   // need to do this so fstream doesn't explode when files are removed from
47   // under it
48   subject.on('end', function () {
49     // ensure we get *exactly* the results we expect by comparing in both
50     // directions
51     filenames.forEach(function (filename) {
52       t.ok(
53         included.indexOf(filename) > -1,
54         filename + ' is included'
55       )
56     })
57     included.forEach(function (filename) {
58       t.ok(
59         filenames.indexOf(filename) > -1,
60         filename + ' is not included'
61       )
62     })
63     t.end()
64   })
65 })
66
67 test('cleanup', function (t) {
68   // rimraf.sync chokes here for some reason
69   rimraf(pkg, function () { t.end() })
70 })
71
72 function setup () {
73   rimraf.sync(pkg)
74   mkdirp.sync(pkg)
75   fs.writeFileSync(
76     join(pkg, 'package.json'),
77     JSON.stringify(json, null, 2)
78   )
79
80   fs.writeFileSync(
81     join(pkg, 'elf.js'),
82     elfJS
83   )
84
85   fs.writeFileSync(
86     join(pkg, '.npmrc'),
87     'packaged=false'
88   )
89
90   fs.writeFileSync(
91     join(pkg, '.npmignore'),
92     '.npmignore\ndummy\npackage.json'
93   )
94
95   fs.writeFileSync(
96     join(pkg, 'dummy'),
97     'foo'
98   )
99
100   var buildDir = join(pkg, 'build')
101   mkdirp.sync(buildDir)
102   fs.writeFileSync(
103     join(buildDir, 'config.gypi'),
104     "i_wont_be_included_by_fstream='with any luck'"
105   )
106
107   var depscfg = join(pkg, 'deps', 'foo', 'config')
108   mkdirp.sync(depscfg)
109   fs.writeFileSync(
110     join(depscfg, 'config.gypi'),
111     "i_will_be_included_by_fstream='with any luck'"
112   )
113
114   fs.writeFileSync(
115     join(buildDir, 'npm-debug.log'),
116     '0 lol\n'
117   )
118
119   var gitDir = join(pkg, '.git')
120   mkdirp.sync(gitDir)
121   fs.writeFileSync(
122     join(gitDir, 'gitstub'),
123     "won't fool git, also won't be included by fstream"
124   )
125
126   var historyDir = join(pkg, 'node_modules/history')
127   mkdirp.sync(historyDir)
128   fs.writeFileSync(
129     join(historyDir, 'README.md'),
130     "please don't include me"
131   )
132 }