Welcome to mirror list, hosted at ThFree Co, Russian Federation.

url-dependencies.js « tap « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c2078aff73765605f942a3244d1dfd3d51283af (plain)
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
var test = require("tap").test
var rimraf = require("rimraf")

var mr = require("npm-registry-mock")

var spawn = require("child_process").spawn
var npm = require.resolve("../../bin/npm-cli.js")
var node = process.execPath
var pkg = "./url-dependencies"

var mockRoutes = {
  "get": {
    "/underscore/-/underscore-1.3.1.tgz": [200]
  }
}

test("url-dependencies: download first time", function(t) {
  rimraf.sync(__dirname + "/url-dependencies/node_modules")

  performInstall(function(output){
    if(!tarballWasFetched(output)){
      t.fail("Tarball was not fetched")
    }else{
      t.pass("Tarball was fetched")
    }
    t.end()
  })
})

test("url-dependencies: do not download subsequent times", function(t) {
  rimraf.sync(__dirname + "/url-dependencies/node_modules")

  performInstall(function(){
    performInstall(function(output){
      if(tarballWasFetched(output)){
        t.fail("Tarball was fetched second time around")
      }else{
        t.pass("Tarball was not fetched")
      }
      t.end()
    })
  })
})

function tarballWasFetched(output){
  return output.indexOf("http GET http://localhost:1337/underscore/-/underscore-1.3.1.tgz") > -1
}

function performInstall (cb) {
  mr({port: 1337, mocks: mockRoutes}, function(s){
    var output = ""
      , child = spawn(node, [npm, "install"], {
          cwd: pkg,
          env: {
            npm_config_registry: "http://localhost:1337",
            npm_config_cache_lock_stale: 1000,
            npm_config_cache_lock_wait: 1000,
            HOME: process.env.HOME,
            Path: process.env.PATH,
            PATH: process.env.PATH
          }
        })

    child.stderr.on("data", function(data){
      output += data.toString()
    })
    child.on("close", function () {
      s.close()
      cb(output)
    })
  })
}