Skip to content
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

Make license-ls compatible with npm 7.x #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ lib(options)
}
spinner.succeed()
console.log(output)
})
})
.catch(reason => {
spinner.fail('Unexpected error')
console.error(reason);
})
2 changes: 1 addition & 1 deletion helpers/npm-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const optionsToArgv = require('./options-to-args')
* @returns {Promise<Array<Object>>}
*/
module.exports = function (opts = {}) {
const blackListOpts = ['format']
const blackListOpts = ['format', 'csv']
const options = optionsToArgv(opts, blackListOpts)

return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const glob = promisify(require('glob'))
*/
module.exports = async function (options = {}) {
const pathList = await npmLs(options)
return await Promise.all(pathList.map(async (path, index) => {
return Promise.all(pathList.map(async (path, index) => {
const pkg = await getPackageDetails(path)
const licShortName = extractLicenseText(pkg.license || pkg.licenses || pkg.licence || pkg.licences)
const licLongName = getExpandedLicName(licShortName) || 'unknown'
Expand Down
23 changes: 18 additions & 5 deletions tests/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
const cli = require('../cli')
const test = require('ava')
const spawn = require("cross-spawn");

test('Does the thing', async (t) => {
// TODO: how do I test this since it's not a function?
t.true(true)
})
test('runs successfully', async (t) => {
t.timeout(10000)
const args = [
'cli.js',
'--format=json',
'--depth=0',
'--prod',
]

const sync = spawn.sync('node', args, {encoding: 'utf-8'})

t.regex(sync.stderr, /^- Analyzing\n(√|✔) Analyzing\n- Building output format\n(√|✔) Building output format\n$/)
t.is(sync.status, 0)

const output = JSON.parse(sync.stdout)
t.is(output.length, 12, 'number of packages in the output should match the direct dependencies of license-ls')
})
19 changes: 19 additions & 0 deletions tests/npm-ls.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const npmList = require('../helpers/npm-list')
const test = require('ava')
const fs = require('fs')

test('Returns a non-empty array of package paths', async (t) => {
const actual = await npmList()
Expand Down Expand Up @@ -32,3 +33,21 @@ test('Produces different results when given different options', async (t) => {
t.notDeepEqual(prodOnly, devOnly)
})

test('Handles more complex options correctly', async (t) => {
const opts = {
csv: { delimiter: ',' },
depth: 0,
format: 'json',
prod: true,
production: true,
include: [ 'id', 'name', 'version', 'license', 'repository', 'author', 'homepage', 'dependencyLevel' ],
table: {},
xml: { asAttrs: false, 'as-attrs': false }
}

const actual = await npmList(opts);

t.true(actual.length > 0)
actual.forEach(path => t.true(fs.existsSync('' + path), `invalid path: ${path}`))
})