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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
// verify that prepublishOnly runs _only_ on publish
var join = require('path').join
var mr = require('npm-registry-mock')
var test = require('tap').test
var Tacks = require('tacks')
var File = Tacks.File
var Dir = Tacks.Dir
var path = require('path')
var common = require('../common-tap')
var pkg = join(__dirname, 'prepublish_package')
var cachedir = join(pkg, 'cache')
var tmpdir = join(pkg, 'tmp')
var env = {
'npm_config_cache': cachedir,
'npm_config_tmp': tmpdir,
'npm_config_prefix': pkg,
'npm_config_global': 'false'
}
for (var i in process.env) {
if (!/^npm_config_/.test(i)) {
env[i] = process.env[i]
}
}
var server
var fixture = new Tacks(Dir({
cache: Dir(),
tmp: Dir(),
'.npmrc': File([
'progress=false',
'registry=' + common.registry,
'//localhost:1337/:username=username',
'//localhost:1337/:_authToken=deadbeeffeed'
].join('\n') + '\n'),
helper: Dir({
'script.js': File([
'#!/usr/bin/env node\n',
'console.log("ok")\n'
].join('\n') + '\n'
),
'package.json': File({
name: 'helper',
version: '6.6.6',
bin: './script.js'
})
}),
'package.json': File({
name: 'npm-test-prepublish-only',
version: '1.2.5',
dependencies: {
'helper': 'file:./helper'
},
scripts: {
build: 'helper',
prepublishOnly: 'node ' + path.resolve(__dirname, '../../') + ' run build'
}
})
}))
test('setup', function (t) {
cleanup()
fixture.create(pkg)
mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
t.ifError(err, 'registry mocked successfully')
server = s
common.npm(
[
'install',
'--loglevel', 'error',
'--cache', cachedir,
'--tmp', tmpdir
],
{
cwd: pkg,
env: env
},
function (err, code, stdout, stderr) {
t.equal(code, 0, 'install exited OK')
t.ifErr(err, 'installed successfully')
t.notOk(stderr, 'got stderr data:' + JSON.stringify('' + stderr))
t.end()
}
)
})
})
test('test', function (t) {
server.filteringRequestBody(function () { return true })
.put('/npm-test-prepublish-only', true)
.reply(201, {ok: true})
common.npm(
[
'publish',
'--loglevel', 'warn'
],
{
cwd: pkg,
env: env
},
function (err, code, stdout, stderr) {
t.equal(code, 0, 'publish ran without error')
t.ifErr(err, 'published successfully')
t.notOk(stderr, 'got stderr data:' + JSON.stringify('' + stderr))
var c = stdout.trim()
var regex = new RegExp(
'> npm-test-prepublish-only@1.2.5 prepublishOnly [^\\r\\n]+\\r?\\n' +
'> .* run build\\r?\\n' +
'\\r?\\n' +
'\\r?\\n' +
'> npm-test-prepublish-only@1.2.5 build [^\\r\\n]+\\r?\\n' +
'> helper\\r?\\n' +
'\\r?\\n' +
'ok\\r?\\n' +
'\\+ npm-test-prepublish-only@1.2.5', 'ig'
)
t.match(c, regex)
t.end()
}
)
})
test('cleanup', function (t) {
cleanup()
server.close()
t.pass('cleaned up')
t.end()
})
function cleanup () {
fixture.remove(pkg)
}
|