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

prepublish.js « tap « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 36391beeb340facceaec4b63506eb7bc8d9cf94d (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
73
74
75
76
77
78
79
80
81
82
// verify that prepublish runs on pack and publish
var common = require("../common-tap")
var test = require("tap").test
var fs = require("graceful-fs")
var join = require("path").join
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")

var pkg = join(__dirname, "prepublish_package")
var tmp = join(pkg, "tmp")
var cache = join(pkg, "cache")

test("setup", function (t) {
  var n = 0
  cleanup()
  mkdirp(pkg, then())
  mkdirp(cache, then())
  mkdirp(tmp, then())
  function then () {
    n++
    return function (er) {
      if (er) throw er
      if (--n === 0) next()
    }
  }

  function next () {
    fs.writeFile(join(pkg, "package.json"), JSON.stringify({
      name: "npm-test-prepublish",
      version: "1.2.5",
      scripts: { prepublish: "echo ok" }
    }), "ascii", function (er) {
      if (er) throw er

      t.pass("setup done")
      t.end()
    })
  }
})

test("test", function (t) {
  var env = {
    "npm_config_cache"  : cache,
    "npm_config_tmp"    : tmp,
    "npm_config_prefix" : pkg,
    "npm_config_global" : "false"
  }
  for (var i in process.env) {
    if (!/^npm_config_/.test(i))
      env[i] = process.env[i]
  }

  common.npm([
      "pack",
      "--loglevel", "warn"
    ], { cwd: pkg, env: env }, function(err, code, stdout, stderr) {
    t.equal(code, 0, "pack finished successfully")
    t.ifErr(err, "pack finished successfully")

    t.notOk(stderr, "got stderr data:" + JSON.stringify("" + stderr))
    var c = stdout.trim()
    var regex = new RegExp("" +
      "> npm-test-prepublish@1.2.5 prepublish [^\\r\\n]+\\r?\\n" +
      "> echo ok\\r?\\n" +
      "\\r?\\n" +
      "ok\\r?\\n" +
      "npm-test-prepublish-1.2.5.tgz", "ig")

    t.ok(c.match(regex))
    t.end()
  })
})

test("cleanup", function (t) {
  cleanup()
  t.pass("cleaned up")
  t.end()
})

function cleanup() {
  rimraf.sync(pkg)
}