]> 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/scoped.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 / scoped.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-scoped')
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-scoped',
20   'version': '3.1.4',
21   'main': 'elf.js',
22   'bundledDependencies': [
23     '@npmwombat/scoped'
24   ]
25 }
26
27 test('setup', function (t) {
28   setup()
29   t.end()
30 })
31
32 var included = [
33   'package.json',
34   'elf.js',
35   join('node_modules', '@npmwombat', 'scoped', 'index.js')
36 ]
37
38 test('includes bundledDependencies', function (t) {
39   var subject = new Packer({ path: pkg, type: 'Directory', isDirectory: true })
40   var filenames = []
41   subject.on('entry', function (entry) {
42     t.equal(entry.type, 'File', 'only files in this package')
43
44     // include relative path in filename
45     var filename = entry._path.slice(entry.root._path.length + 1)
46
47     filenames.push(filename)
48   })
49   // need to do this so fstream doesn't explode when files are removed from
50   // under it
51   subject.on('end', function () {
52     // ensure we get *exactly* the results we expect by comparing in both
53     // directions
54     filenames.forEach(function (filename) {
55       t.ok(
56         included.indexOf(filename) > -1,
57         filename + ' is included'
58       )
59     })
60     included.forEach(function (filename) {
61       t.ok(
62         filenames.indexOf(filename) > -1,
63         filename + ' is not included'
64       )
65     })
66     t.end()
67   })
68 })
69
70 test('cleanup', function (t) {
71   // rimraf.sync chokes here for some reason
72   rimraf(pkg, function () { t.end() })
73 })
74
75 function setup () {
76   rimraf.sync(pkg)
77   mkdirp.sync(pkg)
78   fs.writeFileSync(
79     join(pkg, 'package.json'),
80     JSON.stringify(json, null, 2)
81   )
82
83   fs.writeFileSync(
84     join(pkg, 'elf.js'),
85     elfJS
86   )
87
88   var scopedDir = join(pkg, 'node_modules', '@npmwombat', 'scoped')
89   mkdirp.sync(scopedDir)
90   fs.writeFileSync(
91     join(scopedDir, 'index.js'),
92     "console.log('hello wombat')"
93   )
94 }