Skip to content

Commit

Permalink
Add source-map-support. Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed May 2, 2021
1 parent 68e69b4 commit 05c7302
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 64 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
"lint": "cross-env FORCE_COLOR=1 npm-run-all --parallel --aggregate-output lint:*",
"lint:lockfile": "lockfile-lint",
"lint:markdown": "markdownlint \"**/*.md\" --ignore node_modules --config .markdownlint.js",
"lint:src": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives .",
"lint:src": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives src",
"mocha": "mocha --require source-map-support/register",
"nyc": "nyc",
"test": "mocha test test/package-managers/npm test/package-managers/yarn && mocha --exit test/timeout",
"ncu": "node ./bin/cli.js"
"test": "npm run test:src && npm run test:timeout",
"test:src": "npm run mocha -- ./build/test ./build/test/package-managers/npm ./build/test/package-managers/yarn",
"test:timeout": "npm run mocha -- --exit ./build/test/timeout",
"ncu": "node ./build/src/bin/cli.js"
},
"bin": {
"npm-check-updates": "./build/src/bin/cli.js",
Expand Down Expand Up @@ -79,6 +82,7 @@
"rimraf": "^3.0.2",
"semver": "^7.3.5",
"semver-utils": "^1.1.4",
"source-map-support": "^0.5.19",
"spawn-please": "^1.0.0",
"update-notifier": "^5.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/package-managers/gitTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getSortedVersions = async (name, declaration, options) => {
}

// eslint-disable-next-line fp/no-mutating-methods
const tags = [...tagMap.keys()]
const tags = Array.from(tagMap.keys())
.map(tag => versionUtil.isSimpleVersion(tag) ? tag + '.0.0' : tag)
// do not pass semver.valid reference directly since the mapping index will be interpreted as the loose option
// https://github.com/npm/node-semver#functions
Expand Down
70 changes: 35 additions & 35 deletions test/bin.test.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions test/deep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ chai.use(chaiAsPromised)

process.env.NCU_TESTS = true

const bin = path.join(__dirname, '../src/bin/cli.js')

describe('--deep', function () {

const bin = path.join(__dirname, '../bin/cli.js')
const cwd = path.join(__dirname, 'deep')
const cwd = path.join(__dirname, '../../test/deep')

this.timeout(60000)

Expand Down Expand Up @@ -119,8 +120,7 @@ describe('--deep', function () {

describe('--deep with nested ncurc files', function () {

const bin = path.join(__dirname, '../bin/cli.js')
const cwd = path.join(__dirname, 'deep-ncurc')
const cwd = path.join(__dirname, '../../test/deep-ncurc')

this.timeout(60000)

Expand Down
17 changes: 10 additions & 7 deletions test/doctor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,38 @@ const { doctorHelpText } = require('../src/constants.js')
chai.should()
chai.use(chaiAsPromised)

const bin = path.join(__dirname, '../src/bin/cli.js')
const doctorTests = path.join(__dirname, '../../test/doctor')

/** Run the ncu CLI. */
const ncu = (args, options) => spawn('node', [path.join(__dirname, '../bin/cli.js'), ...args], options)
const ncu = (args, options) => spawn('node', [bin, ...args], options)

describe('doctor', function() {

// 3 min timeout
this.timeout(3 * 60 * 1000)

it('print instructions when -u is not specified', async () => {
const cwd = path.join(__dirname, 'doctor/nopackagefile')
const cwd = path.join(doctorTests, 'nopackagefile')
return ncu(['--doctor'], { cwd })
.should.eventually.equal(doctorHelpText + '\n')
})

it('throw an error if there is no package file', async () => {
const cwd = path.join(__dirname, 'doctor/nopackagefile')
const cwd = path.join(doctorTests, 'nopackagefile')
return ncu(['--doctor', '-u'], { cwd })
.should.eventually.be.rejectedWith('Missing or invalid package.json')
})

it('throw an error if there is no test script', async () => {
const cwd = path.join(__dirname, 'doctor/notestscript')
const cwd = path.join(doctorTests, 'notestscript')
return ncu(['--doctor', '-u'], { cwd })
.should.eventually.be.rejectedWith('No npm "test" script')
})

it('upgrade dependencies when tests pass', async function () {

const cwd = path.join(__dirname, 'doctor/pass')
const cwd = path.join(doctorTests, 'pass')
const pkgPath = path.join(cwd, 'package.json')
const lockfilePath = path.join(cwd, 'package-lock.json')
const nodeModulesPath = path.join(cwd, 'node_modules')
Expand Down Expand Up @@ -81,7 +84,7 @@ describe('doctor', function() {

it('pass through options', async function () {

const cwd = path.join(__dirname, 'doctor/options')
const cwd = path.join(doctorTests, 'options')
const pkgPath = path.join(cwd, 'package.json')
const lockfilePath = path.join(cwd, 'package-lock.json')
const nodeModulesPath = path.join(cwd, 'node_modules')
Expand Down Expand Up @@ -134,7 +137,7 @@ describe('doctor', function() {

it('identify broken upgrade', async function() {

const cwd = path.join(__dirname, 'doctor/fail')
const cwd = path.join(doctorTests, 'fail')
const pkgPath = path.join(cwd, 'package.json')
const lockfilePath = path.join(cwd, 'package-lock.json')
const nodeModulesPath = path.join(cwd, 'node_modules')
Expand Down
4 changes: 2 additions & 2 deletions test/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('filter', () => {

it('filter by package name with one arg', async () => {
const upgraded = await ncu.run({
packageData: fs.readFileSync(path.join(__dirname, '/ncu/package2.json'), 'utf-8'),
packageData: fs.readFileSync(path.join(__dirname, '../../test/ncu/package2.json'), 'utf-8'),
args: ['lodash.map']
})
upgraded.should.have.property('lodash.map')
Expand All @@ -21,7 +21,7 @@ describe('filter', () => {

it('filter by package name with multiple args', async () => {
const upgraded = await ncu.run({
packageData: fs.readFileSync(path.join(__dirname, '/ncu/package2.json'), 'utf-8'),
packageData: fs.readFileSync(path.join(__dirname, '../../test/ncu/package2.json'), 'utf-8'),
args: ['lodash.map', 'lodash.filter']
})
upgraded.should.have.property('lodash.map')
Expand Down
12 changes: 7 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ chai.use(chaiString)

process.env.NCU_TESTS = true

const testDir = path.join(__dirname, '../../test/')

describe('run', function () {

let last = 0
Expand All @@ -24,7 +26,7 @@ describe('run', function () {

it('return promised jsonUpgraded', () => {
return ncu.run({
packageData: fs.readFileSync(path.join(__dirname, '/ncu/package.json'), 'utf-8')
packageData: fs.readFileSync(path.join(testDir, 'ncu/package.json'), 'utf-8')
}).should.eventually.have.property('express')
})

Expand Down Expand Up @@ -56,7 +58,7 @@ describe('run', function () {

it('only upgrade devDependencies and peerDependencies with --dep dev', () => {
const upgraded = ncu.run({
packageData: fs.readFileSync(path.join(__dirname, '/ncu/package-dep.json'), 'utf-8'),
packageData: fs.readFileSync(path.join(testDir, 'ncu/package-dep.json'), 'utf-8'),
dep: 'dev'
})

Expand All @@ -69,7 +71,7 @@ describe('run', function () {

it('only upgrade devDependencies and peerDependencies with --dep dev,peer', () => {
const upgraded = ncu.run({
packageData: fs.readFileSync(path.join(__dirname, '/ncu/package-dep.json'), 'utf-8'),
packageData: fs.readFileSync(path.join(testDir, 'ncu/package-dep.json'), 'utf-8'),
dep: 'dev,peer'
})

Expand Down Expand Up @@ -711,7 +713,7 @@ describe('run', function () {
})

describe('peer dependencies', () => {
const peerPath = path.join(__dirname, '/peer/')
const peerPath = path.join(__dirname, '../../test/peer/')

it('peer dependencies of installed packages are ignored by default', async () => {
try {
Expand Down Expand Up @@ -741,7 +743,7 @@ describe('run', function () {
}
})

const peerUpdatePath = path.join(__dirname, '/peer-update/')
const peerUpdatePath = path.join(__dirname, '../../test/peer-update/')
it('peer dependencies of installed packages are checked iteratively when using option peer', async () => {
try {
await spawnNpm('install', {}, { cwd: peerUpdatePath })
Expand Down
9 changes: 6 additions & 3 deletions test/package-managers/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
'use strict'

const path = require('path')
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const packageManagers = require('../../../src/package-managers')

chai.should()
chai.use(chaiAsPromised)

const npmTestDir = path.join(__dirname, '../../../../test/package-managers/npm')

describe('npm', function () {

this.timeout(30000)

it('list', async () => {
const versionObject = await packageManagers.npm.list({ cwd: __dirname })
const versionObject = await packageManagers.npm.list({ cwd: npmTestDir })
versionObject.should.have.property('express')
})

it('latest', async () => {
const version = await packageManagers.npm.latest('express', null, { cwd: __dirname })
const version = await packageManagers.npm.latest('express', null, { cwd: npmTestDir })
parseInt(version, 10).should.be.above(1)
})

it('greatest', async () => {
const version = await packageManagers.npm.greatest('ncu-test-greatest-not-newest', null, { pre: true, cwd: __dirname })
const version = await packageManagers.npm.greatest('ncu-test-greatest-not-newest', null, { pre: true, cwd: npmTestDir })
version.should.equal('2.0.0-beta')
})

Expand Down
8 changes: 5 additions & 3 deletions test/package-managers/yarn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,26 @@ const packageManagers = require('../../../src/package-managers')
chai.should()
chai.use(chaiAsPromised)

const yarnTestDir = path.join(__dirname, '../../../../test/package-managers/yarn')

describe('yarn', function () {

this.timeout(30000)

it('list', async () => {
const testDir = path.resolve(path.join(__dirname, './default'))
const testDir = path.join(yarnTestDir, 'default')
const version = await packageManagers.yarn.latest('chalk', null, { cwd: testDir })
parseInt(version, 10).should.be.above(3)
})

it('latest', async () => {
const testDir = path.resolve(path.join(__dirname, './default'))
const testDir = path.join(yarnTestDir, 'default')
const version = await packageManagers.yarn.latest('chalk', null, { cwd: testDir })
parseInt(version, 10).should.be.above(3)
})

it('"No lockfile" error should be thrown on list command when there is no lockfile', async () => {
const testDir = path.resolve(path.join(__dirname, './nolockfile'))
const testDir = path.join(yarnTestDir, 'nolockfile')
const lockFileErrorMessage = 'No lockfile in this directory. Run `yarn install` to generate one.'
await packageManagers.yarn.list({ cwd: testDir })
.should.eventually.be.rejectedWith(lockFileErrorMessage)
Expand Down
3 changes: 2 additions & 1 deletion test/timeout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ describe('timeout (with --exit)', function () {
// this must be executed as a separate process with --exit to prevent delayed test completion
// https://github.com/raineorshine/npm-check-updates/issues/721
it('throw an exception instead of printing to the console when timeout is exceeded', () => {
const pkgPath = path.join(__dirname, '../../../test/ncu/package-large.json')
return ncu.run({
packageData: fs.readFileSync(path.join(__dirname, '../ncu/package-large.json'), 'utf-8'),
packageData: fs.readFileSync(pkgPath, 'utf-8'),
timeout: 1
})
.should.eventually.be.rejectedWith('Exceeded global timeout of 1ms')
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"include": [
"./src/**/*",
"./test/**/*",
],
"compilerOptions": {
"allowJs": true,
Expand All @@ -18,6 +19,7 @@
"resolveJsonModule": true,
"outDir": "./build",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es5"
}
Expand Down

0 comments on commit 05c7302

Please # to comment.