]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/legacy-array-bin.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / legacy-array-bin.js
1 'use strict'
2 var test = require('tap').test
3 var common = require('../common-tap.js')
4 var path = require('path')
5 var rimraf = require('rimraf')
6 var mkdirp = require('mkdirp')
7 var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
8 var fixturepath = path.resolve(basepath, 'npm-test-array-bin')
9 var modulepath = path.resolve(basepath, 'node_modules')
10 var installedpath = path.resolve(modulepath, 'npm-test-array-bin')
11 var Tacks = require('tacks')
12 var File = Tacks.File
13 var Dir = Tacks.Dir
14 var fixture = new Tacks(
15   Dir({
16     bin: Dir({
17       'array-bin': File(
18         '#!/usr/bin/env node\n' +
19         "console.log('test ran ok')\n"
20       )
21     }),
22     'package.json': File({
23       name: 'npm-test-array-bin',
24       version: '1.2.5',
25       bin: [
26         'bin/array-bin'
27       ],
28       scripts: {
29         test: 'node test.js'
30       }
31     }),
32     'test.js': File(
33       "require('child_process').exec('array-bin', { env: process.env },\n" +
34       '  function (err, stdout, stderr) {\n' +
35       "    if (err && err.code) throw new Error('exited badly with code = ' + err.code)\n" +
36       '    console.log(stdout)\n' +
37       '    console.error(stderr)\n' +
38       '  }\n' +
39       ')\n'
40     )
41   })
42 )
43 test('setup', function (t) {
44   setup()
45   t.done()
46 })
47 test('array-bin', function (t) {
48   common.npm(['install', fixturepath], {cwd: basepath}, installCheckAndTest)
49   function installCheckAndTest (err, code, stdout, stderr) {
50     if (err) throw err
51     t.is(code, 0, 'install went ok')
52     t.equal(stderr, '', 'no error output')
53     common.npm(['test'], {cwd: installedpath}, testCheckAndRemove)
54   }
55   function testCheckAndRemove (err, code, stdout, stderr) {
56     t.ifError(err, 'npm test on array bin')
57     t.equal(code, 0, 'exited OK')
58     t.equal(stderr.trim(), '', 'no error output')
59     t.match(stdout, /test ran ok/, 'child script ran properly')
60     common.npm(['rm', fixturepath], {cwd: basepath}, removeCheckAndDone)
61   }
62   function removeCheckAndDone (err, code, stdout, stderr) {
63     if (err) throw err
64     t.is(code, 0, 'remove went ok')
65     t.done()
66   }
67 })
68 test('cleanup', function (t) {
69   cleanup()
70   t.done()
71 })
72 function setup () {
73   cleanup()
74   fixture.create(fixturepath)
75   mkdirp.sync(modulepath)
76 }
77 function cleanup () {
78   fixture.remove(fixturepath)
79   rimraf.sync(basepath)
80 }