Skip to content

more random tests #1902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const npm = require('./npm.js')
const output = require('./utils/output.js')
const usageUtil = require('./utils/usage.js')
const completion = require('./utils/completion/none.js')
const PATH = require('./utils/path.js')
const cmd = (args, cb) => bin(args).then(() => cb()).catch(cb)
const usage = usageUtil('bin', 'npm bin [-g]')
const bin = async (args, cb) => {
const b = npm.bin
const PATH = require('./utils/path.js')
output(b)
if (npm.flatOptions.global && !PATH.includes(b)) {
console.error('(not in PATH env variable)')
Expand Down
71 changes: 71 additions & 0 deletions test/lib/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const { test } = require('tap')
const requireInject = require('require-inject')

test('bin', (t) => {
t.plan(3)
const dir = '/bin/dir'

const bin = requireInject('../../lib/bin.js', {
'../../lib/npm.js': { bin: dir, flatOptions: { global: false } },
'../../lib/utils/output.js': (output) => {
t.equal(output, dir, 'prints the correct directory')
}
})

bin([], (err) => {
t.ifError(err, 'npm bin')
t.ok('should have printed directory')
})
})

test('bin -g', (t) => {
t.plan(3)
const consoleError = console.error
t.tearDown(() => {
console.error = consoleError
})

console.error = (output) => {
t.fail('should not have printed to console.error')
}
const dir = '/bin/dir'

const bin = requireInject('../../lib/bin.js', {
'../../lib/npm.js': { bin: dir, flatOptions: { global: true } },
'../../lib/utils/path.js': [dir],
'../../lib/utils/output.js': (output) => {
t.equal(output, dir, 'prints the correct directory')
}
})

bin([], (err) => {
t.ifError(err, 'npm bin')
t.ok('should have printed directory')
})
})

test('bin -g (not in path)', (t) => {
t.plan(4)
const consoleError = console.error
t.tearDown(() => {
console.error = consoleError
})

console.error = (output) => {
t.equal(output, '(not in PATH env variable)', 'prints env warning')
}
const dir = '/bin/dir'

const bin = requireInject('../../lib/bin.js', {
'../../lib/npm.js': { bin: dir, flatOptions: { global: true } },
'../../lib/utils/path.js': ['/not/my/dir'],
'../../lib/utils/output.js': (output) => {
t.equal(output, dir, 'prints the correct directory')
}
})

bin([], (err) => {
t.ifError(err, 'npm bin')
t.ok('should have printed directory')
})
})
84 changes: 84 additions & 0 deletions test/lib/birthday.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const { test } = require('tap')
const requireInject = require('require-inject')

test('birthday (nope)', (t) => {
t.plan(1)
const B = global[Buffer.from([66, 117, 102, 102, 101, 114])]
const f = B.from([102, 114, 111, 109])
const D = global[B[f]([68, 97, 116, 101])]
const _6 = B[f]([98, 97, 115, 101, 54, 52]) + ''
const l = B[f]('dG9TdHJpbmc=', _6)
class FD extends D {
[B[f]('Z2V0VVRDTW9udGg=', _6)[l]()] () {
return 7
}
}
global[B[f]([68, 97, 116, 101])] = FD
const consoleLog = console.log
console.log = () => undefined
t.tearDown(() => {
global[B[f]([68, 97, 116, 101])] = D
console.log = consoleLog
})
const birthday = requireInject('../../lib/birthday', {})
birthday([], (err) => {
t.match(err, 'try again', 'not telling you the secret that easily are we?')
})
})

test('birthday (nope again)', (t) => {
t.plan(1)
const B = global[Buffer.from([66, 117, 102, 102, 101, 114])]
const f = B.from([102, 114, 111, 109])
const D = global[B[f]([68, 97, 116, 101])]
const _6 = B[f]([98, 97, 115, 101, 54, 52]) + ''
const l = B[f]('dG9TdHJpbmc=', _6)
class FD extends D {
[B[f]('Z2V0RnVsbFllYXI=', _6)[l]()] () {
const d = new D()
return d[B[f]('Z2V0RnVsbFllYXI=', _6)[l]()]() + 1
}
[B[f]('Z2V0VVRDTW9udGg=', _6)[l]()] () {
return 9
}
}
global[B[f]([68, 97, 116, 101])] = FD
const consoleLog = console.log
console.log = () => undefined
t.tearDown(() => {
global[B[f]([68, 97, 116, 101])] = D
console.log = consoleLog
})
const birthday = requireInject('../../lib/birthday', {})
birthday([], (err) => {
t.match(err, 'try again', 'not telling you the secret that easily are we?')
})
})

test('birthday (yup)', (t) => {
t.plan(1)
const B = global[Buffer.from([66, 117, 102, 102, 101, 114])]
const f = B.from([102, 114, 111, 109])
const D = global[B[f]([68, 97, 116, 101])]
const _6 = B[f]([98, 97, 115, 101, 54, 52]) + ''
const l = B[f]('dG9TdHJpbmc=', _6)
class FD extends D {
[B[f]('Z2V0VVRDTW9udGg=', _6)[l]()] () {
return 8
}
[B[f]('Z2V0VVRDRGF0ZQ==', _6)[l]()] () {
return 29
}
}
global[B[f]([68, 97, 116, 101])] = FD
const consoleLog = console.log
console.log = () => undefined
t.tearDown(() => {
global[B[f]([68, 97, 116, 101])] = D
console.log = consoleLog
})
const birthday = requireInject('../../lib/birthday', {})
birthday([], (err) => {
t.ifError(err, 'npm birthday')
})
})
19 changes: 19 additions & 0 deletions test/lib/prefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { test } = require('tap')
const requireInject = require('require-inject')

test('prefix', (t) => {
t.plan(3)
const dir = '/prefix/dir'

const prefix = requireInject('../../lib/prefix.js', {
'../../lib/npm.js': { prefix: dir },
'../../lib/utils/output.js': (output) => {
t.equal(output, dir, 'prints the correct directory')
}
})

prefix([], (err) => {
t.ifError(err, 'npm prefix')
t.ok('should have printed directory')
})
})
19 changes: 19 additions & 0 deletions test/lib/root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { test } = require('tap')
const requireInject = require('require-inject')

test('root', (t) => {
t.plan(3)
const dir = '/root/dir'

const root = requireInject('../../lib/root.js', {
'../../lib/npm.js': { dir },
'../../lib/utils/output.js': (output) => {
t.equal(output, dir, 'prints the correct directory')
}
})

root([], (err) => {
t.ifError(err, 'npm root')
t.ok('should have printed directory')
})
})