"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/lib/diff.js" between
npm-cli-7.16.0.tar.gz and npm-cli-7.17.0.tar.gz

About: npm is a JavaScript package manager (requires node v6 or higher).

diff.js  (npm-cli-7.16.0):diff.js  (npm-cli-7.17.0)
const { resolve } = require('path') const { resolve, join } = require('path')
const t = require('tap') const t = require('tap')
const mockNpm = require('../fixtures/mock-npm') const mockNpm = require('../fixtures/mock-npm')
const noop = () => null const noop = () => null
let libnpmdiff = noop let libnpmdiff = noop
let rpn = () => 'foo'
const config = { const config = {
global: false, global: false,
tag: 'latest', tag: 'latest',
diff: [], diff: [],
} }
const flatOptions = { const flatOptions = {
global: false, global: false,
diffUnified: null, diffUnified: null,
diffIgnoreAllSpace: false, diffIgnoreAllSpace: false,
diffNoPrefix: false, diffNoPrefix: false,
diffSrcPrefix: '', diffSrcPrefix: '',
diffDstPrefix: '', diffDstPrefix: '',
diffText: false, diffText: false,
savePrefix: '^', savePrefix: '^',
} }
const fooPath = t.testdir({
'package.json': JSON.stringify({ name: 'foo', version: '1.0.0' }),
})
const npm = mockNpm({ const npm = mockNpm({
globalDir: __dirname, prefix: fooPath,
prefix: '.',
config, config,
flatOptions, flatOptions,
output: noop, output: noop,
}) })
const mocks = { const mocks = {
npmlog: { info: noop, verbose: noop }, npmlog: { info: noop, verbose: noop },
libnpmdiff: (...args) => libnpmdiff(...args), libnpmdiff: (...args) => libnpmdiff(...args),
'npm-registry-fetch': async () => ({}), 'npm-registry-fetch': async () => ({}),
'../../lib/utils/read-package-name.js': async (prefix) => rpn(prefix),
'../../lib/utils/usage.js': () => 'usage instructions', '../../lib/utils/usage.js': () => 'usage instructions',
} }
t.afterEach(() => { t.afterEach(() => {
config.global = false config.global = false
config.tag = 'latest' config.tag = 'latest'
config.diff = [] config.diff = []
flatOptions.global = false flatOptions.global = false
flatOptions.diffUnified = null flatOptions.diffUnified = null
flatOptions.diffIgnoreAllSpace = false flatOptions.diffIgnoreAllSpace = false
flatOptions.diffNoPrefix = false flatOptions.diffNoPrefix = false
flatOptions.diffSrcPrefix = '' flatOptions.diffSrcPrefix = ''
flatOptions.diffDstPrefix = '' flatOptions.diffDstPrefix = ''
flatOptions.diffText = false flatOptions.diffText = false
flatOptions.savePrefix = '^' flatOptions.savePrefix = '^'
npm.globalDir = __dirname npm.globalDir = fooPath
npm.prefix = '..' npm.prefix = fooPath
libnpmdiff = noop libnpmdiff = noop
rpn = () => 'foo' diff.prefix = undefined
diff.top = undefined
}) })
const Diff = t.mock('../../lib/diff.js', mocks) const Diff = t.mock('../../lib/diff.js', mocks)
const diff = new Diff(npm) const diff = new Diff(npm)
t.test('no args', t => { t.test('no args', t => {
t.test('in a project dir', t => { t.test('in a project dir', t => {
t.plan(3) t.plan(3)
const path = t.testdir({})
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'foo@latest', 'should have default spec comparison') t.equal(a, 'foo@latest', 'should have default spec comparison')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${fooPath}`, 'should compare to cwd')
t.match(opts, npm.flatOptions, 'should forward flat options') t.match(opts, npm.flatOptions, 'should forward flat options')
} }
npm.prefix = path npm.prefix = fooPath
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
t.end()
}) })
}) })
t.test('no args, missing package.json name in cwd', t => { t.test('no args, missing package.json name in cwd', t => {
rpn = () => undefined const path = t.testdir({})
npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
t.match( t.match(
err, err,
/Needs multiple arguments to compare or run from a project dir./, /Needs multiple arguments to compare or run from a project dir./,
'should throw EDIFF error msg' 'should throw EDIFF error msg'
) )
t.end() t.end()
}) })
}) })
t.test('no args, missing package.json in cwd', t => { t.test('no args, bad package.json in cwd', t => {
rpn = () => { const path = t.testdir({
throw new Error('ERR') 'package.json': '{invalid"json',
} })
npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
t.match( t.match(
err, err,
/Needs multiple arguments to compare or run from a project dir./, /Needs multiple arguments to compare or run from a project dir./,
'should throw EDIFF error msg' 'should throw EDIFF error msg'
) )
t.end() t.end()
}) })
}) })
t.end() t.end()
}) })
t.test('single arg', t => { t.test('single arg', t => {
t.test('spec using cwd package name', t => { t.test('spec using cwd package name', t => {
t.plan(4) t.plan(3)
rpn = (prefix) => {
t.equal(prefix, path, 'read-package-name gets proper prefix')
return 'foo'
}
const path = t.testdir({})
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'foo@1.0.0', 'should forward single spec') t.equal(a, 'foo@1.0.0', 'should forward single spec')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${fooPath}`, 'should compare to cwd')
t.match(opts, npm.flatOptions, 'should forward flat options') t.match(opts, npm.flatOptions, 'should forward flat options')
} }
config.diff = ['foo@1.0.0'] config.diff = ['foo@1.0.0']
npm.prefix = path npm.prefix = fooPath
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
t.end() t.end()
}) })
}) })
t.test('unknown spec, no package.json', t => { t.test('unknown spec, no package.json', t => {
const path = t.testdir({}) const path = t.testdir({})
rpn = () => {
throw new Error('ERR')
}
config.diff = ['foo@1.0.0'] config.diff = ['foo@1.0.0']
npm.prefix = path npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
t.match( t.match(
err, err,
/Needs multiple arguments to compare or run from a project dir./, /Needs multiple arguments to compare or run from a project dir./,
'should throw usage error' 'should throw usage error'
) )
t.end() t.end()
}) })
}) })
t.test('spec using semver range', t => { t.test('spec using semver range', t => {
t.plan(3) t.plan(3)
const path = t.testdir({})
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'foo@~1.0.0', 'should forward single spec') t.equal(a, 'foo@~1.0.0', 'should forward single spec')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${fooPath}`, 'should compare to cwd')
t.match(opts, npm.flatOptions, 'should forward flat options') t.match(opts, npm.flatOptions, 'should forward flat options')
} }
config.diff = ['foo@~1.0.0'] config.diff = ['foo@~1.0.0']
npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('version', t => { t.test('version', t => {
t.plan(3) t.plan(3)
const path = t.testdir({})
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'foo@2.1.4', 'should convert to expected first spec') t.equal(a, 'foo@2.1.4', 'should convert to expected first spec')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${fooPath}`, 'should compare to cwd')
t.match(opts, npm.flatOptions, 'should forward flat options') t.match(opts, npm.flatOptions, 'should forward flat options')
} }
config.diff = ['2.1.4'] config.diff = ['2.1.4']
npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('version, no package.json', t => { t.test('version, no package.json', t => {
rpn = () => { const path = t.testdir({})
throw new Error('ERR') npm.prefix = path
}
config.diff = ['2.1.4'] config.diff = ['2.1.4']
diff.exec([], err => { diff.exec([], err => {
t.match( t.match(
err, err,
/Needs multiple arguments to compare or run from a project dir./, /Needs multiple arguments to compare or run from a project dir./,
'should throw an error message explaining usage' 'should throw an error message explaining usage'
) )
t.end() t.end()
}) })
}) })
t.test('version, filtering by files', t => { t.test('version, filtering by files', t => {
t.plan(3) t.plan(3)
const path = t.testdir({})
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'foo@2.1.4', 'should use expected spec') t.equal(a, 'foo@2.1.4', 'should use expected spec')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${fooPath}`, 'should compare to cwd')
t.match(opts, { t.match(opts, {
...npm.flatOptions, ...npm.flatOptions,
diffFiles: [ diffFiles: [
'./foo.js', './foo.js',
'./bar.js', './bar.js',
], ],
}, 'should forward flatOptions and diffFiles') }, 'should forward flatOptions and diffFiles')
} }
config.diff = ['2.1.4'] config.diff = ['2.1.4']
npm.prefix = path
diff.exec(['./foo.js', './bar.js'], err => { diff.exec(['./foo.js', './bar.js'], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('spec is not a dep', t => { t.test('spec is not a dep', t => {
t.plan(2) t.plan(2)
const path = t.testdir({ const path = t.testdir({
skipping to change at line 280 skipping to change at line 266
config.diff = ['simple-output'] config.diff = ['simple-output']
npm.prefix = path npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('unknown package name, no package.json', t => { t.test('unknown package name, no package.json', t => {
const path = t.testdir({}) const path = t.testdir({})
rpn = () => {
throw new Error('ERR')
}
config.diff = ['bar'] config.diff = ['bar']
npm.prefix = path npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
t.match( t.match(
err, err,
/Needs multiple arguments to compare or run from a project dir./, /Needs multiple arguments to compare or run from a project dir./,
'should throw usage error' 'should throw usage error'
) )
t.end() t.end()
skipping to change at line 534 skipping to change at line 517
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('unknown package name', t => { t.test('unknown package name', t => {
t.plan(2) t.plan(2)
const path = t.testdir({}) const path = t.testdir({
rpn = async () => undefined 'package.json': JSON.stringify({ version: '1.0.0' }),
})
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@latest', 'should target latest tag of name') t.equal(a, 'bar@latest', 'should target latest tag of name')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${path}`, 'should compare to cwd')
} }
config.diff = ['bar'] config.diff = ['bar']
npm.prefix = path npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('use project name in project dir', t => { t.test('use project name in project dir', t => {
t.plan(2) t.plan(2)
const path = t.testdir({})
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'my-project@latest', 'should target latest tag of name') t.equal(a, 'foo@latest', 'should target latest tag of name')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${fooPath}`, 'should compare to cwd')
} }
config.diff = ['my-project'] config.diff = ['foo']
npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('dir spec type', t => { t.test('dir spec type', t => {
t.plan(2) t.plan(2)
const path = t.testdir({})
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'file:/path/to/other-dir', 'should target dir') t.equal(a, 'file:/path/to/other-dir', 'should target dir')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${fooPath}`, 'should compare to cwd')
} }
config.diff = ['/path/to/other-dir'] config.diff = ['/path/to/other-dir']
npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('unsupported spec type', t => { t.test('unsupported spec type', t => {
rpn = async () => 'my-project'
config.diff = ['git+https://github.com/user/foo'] config.diff = ['git+https://github.com/user/foo']
diff.exec([], err => { diff.exec([], err => {
t.match( t.match(
err, err,
/Spec type not supported./, /Spec type git not supported./,
'should throw spec type not supported error.' 'should throw spec type not supported error.'
) )
t.end() t.end()
}) })
}) })
t.end() t.end()
}) })
t.test('first arg is a qualified spec', t => { t.test('first arg is a qualified spec', t => {
skipping to change at line 641 skipping to change at line 616
}, },
}, },
'package.json': JSON.stringify({ 'package.json': JSON.stringify({
name: 'my-project', name: 'my-project',
dependencies: { dependencies: {
bar: '^1.0.0', bar: '^1.0.0',
}, },
}), }),
}) })
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@2.0.0', 'should set expected first spec') t.equal(a, 'bar@2.0.0', 'should set expected first spec')
t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg') t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
} }
npm.prefix = path npm.prefix = path
config.diff = ['bar@2.0.0', 'bar'] config.diff = ['bar@2.0.0', 'bar']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
skipping to change at line 710 skipping to change at line 684
}, },
}, },
'package.json': JSON.stringify({ 'package.json': JSON.stringify({
name: 'my-project', name: 'my-project',
dependencies: { dependencies: {
bar: '^1.0.0', bar: '^1.0.0',
}, },
}), }),
}) })
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg') t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, 'bar@2.0.0', 'should set expected second spec') t.equal(b, 'bar@2.0.0', 'should set expected second spec')
} }
npm.prefix = path npm.prefix = path
config.diff = ['bar', 'bar@2.0.0'] config.diff = ['bar', 'bar@2.0.0']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
skipping to change at line 750 skipping to change at line 723
}, },
}, },
'package.json': JSON.stringify({ 'package.json': JSON.stringify({
name: 'my-project', name: 'my-project',
dependencies: { dependencies: {
bar: '^1.0.0', bar: '^1.0.0',
}, },
}), }),
}) })
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg') t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, `bar-fork@file:${resolve(path, 'node_modules/bar-fork')}`, 'sho uld target fork local node_modules pkg') t.equal(b, `bar-fork@file:${resolve(path, 'node_modules/bar-fork')}`, 'sho uld target fork local node_modules pkg')
} }
npm.prefix = path npm.prefix = path
config.diff = ['bar', 'bar-fork'] config.diff = ['bar', 'bar-fork']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
skipping to change at line 784 skipping to change at line 756
}, },
}, },
'package.json': JSON.stringify({ 'package.json': JSON.stringify({
name: 'my-project', name: 'my-project',
dependencies: { dependencies: {
bar: '^1.0.0', bar: '^1.0.0',
}, },
}), }),
}) })
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg') t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, 'bar@2.0.0', 'should use package name from first arg') t.equal(b, 'bar@2.0.0', 'should use package name from first arg')
} }
npm.prefix = path npm.prefix = path
config.diff = ['bar', '2.0.0'] config.diff = ['bar', '2.0.0']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
skipping to change at line 818 skipping to change at line 789
}, },
}, },
'package.json': JSON.stringify({ 'package.json': JSON.stringify({
name: 'my-project', name: 'my-project',
dependencies: { dependencies: {
bar: '^1.0.0', bar: '^1.0.0',
}, },
}), }),
}) })
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg') t.equal(a, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
t.equal(b, 'bar-fork@latest', 'should set expected second spec') t.equal(b, 'bar-fork@latest', 'should set expected second spec')
} }
npm.prefix = path npm.prefix = path
config.diff = ['bar', 'bar-fork'] config.diff = ['bar', 'bar-fork']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
skipping to change at line 872 skipping to change at line 842
}, },
}, },
'package.json': JSON.stringify({ 'package.json': JSON.stringify({
name: 'my-project', name: 'my-project',
dependencies: { dependencies: {
bar: '^1.0.0', bar: '^1.0.0',
}, },
}), }),
}) })
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should use name from second arg') t.equal(a, 'bar@1.0.0', 'should use name from second arg')
t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should set ex pected second spec from nm') t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should set ex pected second spec from nm')
} }
npm.prefix = path npm.prefix = path
config.diff = ['1.0.0', 'bar'] config.diff = ['1.0.0', 'bar']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('second arg is ALSO a semver version', t => { t.test('second arg is ALSO a semver version', t => {
t.plan(2) t.plan(2)
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'my-project@1.0.0', 'should use name from project dir') t.equal(a, 'foo@1.0.0', 'should use name from project dir')
t.equal(b, 'my-project@2.0.0', 'should use name from project dir') t.equal(b, 'foo@2.0.0', 'should use name from project dir')
} }
config.diff = ['1.0.0', '2.0.0'] config.diff = ['1.0.0', '2.0.0']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('second arg is ALSO a semver version BUT cwd not a project dir', t => { t.test('second arg is ALSO a semver version BUT cwd not a project dir', t => {
const path = t.testdir({}) const path = t.testdir({})
rpn = () => {
throw new Error('ERR')
}
config.diff = ['1.0.0', '2.0.0'] config.diff = ['1.0.0', '2.0.0']
npm.prefix = path npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
t.match( t.match(
err, err,
/Needs to be run from a project dir in order to diff two versions./, /Needs to be run from a project dir in order to diff two versions./,
'should throw two versions need project dir error usage msg' 'should throw two versions need project dir error usage msg'
) )
t.end() t.end()
}) })
}) })
t.test('second arg is an unknown dependency name', t => { t.test('second arg is an unknown dependency name', t => {
t.plan(2) t.plan(2)
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@1.0.0', 'should use name from second arg') t.equal(a, 'bar@1.0.0', 'should use name from second arg')
t.equal(b, 'bar@latest', 'should compare against latest tag') t.equal(b, 'bar@latest', 'should compare against latest tag')
} }
config.diff = ['1.0.0', 'bar'] config.diff = ['1.0.0', 'bar']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
skipping to change at line 947 skipping to change at line 910
t.plan(2) t.plan(2)
const path = t.testdir({ const path = t.testdir({
'package.json': JSON.stringify({ 'package.json': JSON.stringify({
name: 'my-project', name: 'my-project',
}), }),
}) })
const Diff = t.mock('../../lib/diff.js', { const Diff = t.mock('../../lib/diff.js', {
...mocks, ...mocks,
'../../lib/utils/read-package-name.js': async () => 'my-project',
'@npmcli/arborist': class { '@npmcli/arborist': class {
constructor () { constructor () {
throw new Error('ERR') throw new Error('ERR')
} }
}, },
libnpmdiff: async ([a, b], opts) => { libnpmdiff: async ([a, b], opts) => {
t.equal(a, 'lorem@1.0.0', 'should target latest version of pkg name') t.equal(a, 'lorem@1.0.0', 'should target latest version of pkg name')
t.equal(b, 'lorem@2.0.0', 'should target expected spec') t.equal(b, 'lorem@2.0.0', 'should target expected spec')
}, },
}) })
skipping to change at line 980 skipping to change at line 942
}) })
t.test('first arg is an unknown dependency name', t => { t.test('first arg is an unknown dependency name', t => {
t.test('second arg is a qualified spec', t => { t.test('second arg is a qualified spec', t => {
t.plan(4) t.plan(4)
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@latest', 'should set expected first spec') t.equal(a, 'bar@latest', 'should set expected first spec')
t.equal(b, 'bar@2.0.0', 'should set expected second spec') t.equal(b, 'bar@2.0.0', 'should set expected second spec')
t.match(opts, npm.flatOptions, 'should forward flat options') t.match(opts, npm.flatOptions, 'should forward flat options')
t.match(opts, { where: '.' }, 'should forward pacote options') t.match(opts, { where: fooPath }, 'should forward pacote options')
} }
config.diff = ['bar', 'bar@2.0.0'] config.diff = ['bar', 'bar@2.0.0']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('second arg is a known dependency', t => { t.test('second arg is a known dependency', t => {
skipping to change at line 1010 skipping to change at line 972
}, },
}, },
'package.json': JSON.stringify({ 'package.json': JSON.stringify({
name: 'my-project', name: 'my-project',
dependencies: { dependencies: {
bar: '^1.0.0', bar: '^1.0.0',
}, },
}), }),
}) })
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar-fork@latest', 'should use latest tag') t.equal(a, 'bar-fork@latest', 'should use latest tag')
t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg') t.equal(b, `bar@file:${resolve(path, 'node_modules/bar')}`, 'should target local node_modules pkg')
} }
npm.prefix = path npm.prefix = path
config.diff = ['bar-fork', 'bar'] config.diff = ['bar-fork', 'bar']
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
skipping to change at line 1058 skipping to change at line 1019
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('cwd not a project dir', t => { t.test('cwd not a project dir', t => {
t.plan(2) t.plan(2)
const path = t.testdir({}) const path = t.testdir({})
rpn = () => {
throw new Error('ERR')
}
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'bar@latest', 'should use latest tag') t.equal(a, 'bar@latest', 'should use latest tag')
t.equal(b, 'bar-fork@latest', 'should use latest tag') t.equal(b, 'bar-fork@latest', 'should use latest tag')
} }
config.diff = ['bar', 'bar-fork'] config.diff = ['bar', 'bar-fork']
npm.prefix = path npm.prefix = path
diff.exec([], err => { diff.exec([], err => {
if (err) if (err)
skipping to change at line 1123 skipping to change at line 1081
diff.exec(['./foo.js', './bar.js'], err => { diff.exec(['./foo.js', './bar.js'], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('set files no diff args', t => { t.test('set files no diff args', t => {
t.plan(3) t.plan(3)
const path = t.testdir({})
rpn = async () => 'my-project'
libnpmdiff = async ([a, b], opts) => { libnpmdiff = async ([a, b], opts) => {
t.equal(a, 'my-project@latest', 'should have default spec') t.equal(a, 'foo@latest', 'should have default spec')
t.equal(b, `file:${path}`, 'should compare to cwd') t.equal(b, `file:${fooPath}`, 'should compare to cwd')
t.match(opts, { t.match(opts, {
...npm.flatOptions, ...npm.flatOptions,
diffFiles: [ diffFiles: [
'./foo.js', './foo.js',
'./bar.js', './bar.js',
], ],
}, 'should forward all remaining items as filenames') }, 'should forward all remaining items as filenames')
} }
npm.prefix = path
diff.exec(['./foo.js', './bar.js'], err => { diff.exec(['./foo.js', './bar.js'], err => {
if (err) if (err)
throw err throw err
}) })
}) })
t.test('using diff option', t => { t.test('using diff option', t => {
t.plan(1) t.plan(1)
flatOptions.diffContext = 5 flatOptions.diffContext = 5
skipping to change at line 1186 skipping to change at line 1141
config.diff = ['a', 'b', 'c'] config.diff = ['a', 'b', 'c']
diff.exec([], err => { diff.exec([], err => {
t.match( t.match(
err, err,
/Can't use more than two --diff arguments./, /Can't use more than two --diff arguments./,
'should throw usage error' 'should throw usage error'
) )
t.end() t.end()
}) })
}) })
t.test('workspaces', t => {
const path = t.testdir({
'package.json': JSON.stringify({
name: 'workspaces-test',
version: '1.2.3-test',
workspaces: ['workspace-a', 'workspace-b', 'workspace-c'],
}),
'workspace-a': {
'package.json': JSON.stringify({
name: 'workspace-a',
version: '1.2.3-a',
}),
},
'workspace-b': {
'package.json': JSON.stringify({
name: 'workspace-b',
version: '1.2.3-b',
}),
},
'workspace-c': JSON.stringify({
'package.json': {
name: 'workspace-n',
version: '1.2.3-n',
},
}),
})
t.test('all workspaces', t => {
const diffCalls = []
libnpmdiff = async ([a, b]) => {
diffCalls.push([a, b])
}
npm.prefix = path
npm.localPrefix = path
diff.execWorkspaces([], [], (err) => {
if (err)
throw err
t.same(diffCalls, [
['workspace-a@latest', join(`file:${path}`, 'workspace-a')],
['workspace-b@latest', join(`file:${path}`, 'workspace-b')],
], 'should call libnpmdiff with workspaces params')
t.end()
})
})
t.test('one workspace', t => {
const diffCalls = []
libnpmdiff = async ([a, b]) => {
diffCalls.push([a, b])
}
npm.prefix = path
npm.localPrefix = path
diff.execWorkspaces([], ['workspace-a'], (err) => {
if (err)
throw err
t.same(diffCalls, [
['workspace-a@latest', join(`file:${path}`, 'workspace-a')],
], 'should call libnpmdiff with workspaces params')
t.end()
})
})
t.test('invalid workspace', t => {
libnpmdiff = () => {
t.fail('should not call libnpmdiff')
}
npm.prefix = path
npm.localPrefix = path
diff.execWorkspaces([], ['workspace-x'], (err) => {
t.match(err, /No workspaces found/)
t.match(err, /workspace-x/)
t.end()
})
})
t.end()
})
 End of changes. 57 change blocks. 
85 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)