Skip to content

Commit

Permalink
change: remove testConstants
Browse files Browse the repository at this point in the history
  • Loading branch information
Torathion committed Mar 7, 2024
1 parent f208591 commit b2ca2cd
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 115 deletions.
13 changes: 6 additions & 7 deletions test/bin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Index } from '../src/types/IndexType'
import { Version } from '../src/types/Version'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'
import { rmOptions } from './helpers/testConstants'

chaiSetup()

Expand Down Expand Up @@ -117,7 +116,7 @@ describe('bin', async function () {
const pkgData = JSON.parse(text)
pkgData.should.have.property('express')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand All @@ -134,7 +133,7 @@ describe('bin', async function () {
upgradedPkg.dependencies.should.have.property('express')
upgradedPkg.dependencies.express.should.not.equal('1')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand All @@ -154,7 +153,7 @@ describe('bin', async function () {
upgradedPkg.dependencies.should.have.property('express')
upgradedPkg.dependencies.express.should.not.equal('1')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand All @@ -171,7 +170,7 @@ describe('bin', async function () {
ugradedPkg.dependencies.should.have.property('express')
ugradedPkg.dependencies.express.should.not.equal('1')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand All @@ -188,7 +187,7 @@ describe('bin', async function () {
upgradedPkg.dependencies.should.have.property('express')
upgradedPkg.dependencies.express.should.not.equal('1')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand All @@ -215,7 +214,7 @@ describe('bin', async function () {
const output = await spawn('node', [bin, '--packageFile', pkgFile, '--filter', 'ncu-test-v2 ncu-test-tag'])
output.should.include('"ncu-test-v2 ncu-test-tag"')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down
5 changes: 2 additions & 3 deletions test/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { CACHE_DELIMITER, resolvedDefaultCacheFile } from '../src/lib/cache'
import { CacheData } from '../src/types/Cacher'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'
import { rmOptions } from './helpers/testConstants'

chaiSetup()

Expand Down Expand Up @@ -36,7 +35,7 @@ describe('cache', () => {
[`ncu-test-alpha${CACHE_DELIMITER}latest`]: '1.0.0',
})
} finally {
await fs.rm(resolvedDefaultCacheFile, rmOptions)
await fs.rm(resolvedDefaultCacheFile, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -96,7 +95,7 @@ describe('cache', () => {
[`ncu-test-alpha${CACHE_DELIMITER}greatest`]: '2.0.0-alpha.2',
})
} finally {
await fs.rm(resolvedDefaultCacheFile, rmOptions)
await fs.rm(resolvedDefaultCacheFile, { recursive: true, force: true })
stub.restore()
}
})
Expand Down
7 changes: 3 additions & 4 deletions test/deep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ncu from '../src/'
import mergeOptions from '../src/lib/mergeOptions'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'
import { rmOptions } from './helpers/testConstants'

chaiSetup()

Expand Down Expand Up @@ -66,7 +65,7 @@ describe('--deep', function () {
deepJsonOut['packages/sub1/package.json'].dependencies.should.have.property('express')
deepJsonOut['packages/sub2/package.json'].dependencies.should.have.property('express')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
}
})

Expand All @@ -86,7 +85,7 @@ describe('--deep', function () {
upgradedPkg.dependencies.should.have.property('express')
upgradedPkg.dependencies.express.should.not.equal('1')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
}
})

Expand Down Expand Up @@ -116,7 +115,7 @@ describe('--deep', function () {
json.should.have.property(path.join(tempDir, 'packages/sub2/package.json').replace(/\\/g, '/'))
json.should.have.property(path.join(tempDir, 'package.json').replace(/\\/g, '/'))
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
}
})
})
Expand Down
13 changes: 6 additions & 7 deletions test/dep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import path from 'path'
import ncu from '../src/'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'
import { rmOptions } from './helpers/testConstants'

chaiSetup()

Expand Down Expand Up @@ -99,7 +98,7 @@ describe('--dep', () => {
},
})
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -146,7 +145,7 @@ describe('--dep', () => {
},
})
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -193,7 +192,7 @@ describe('--dep', () => {
},
})
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -237,7 +236,7 @@ describe('--dep', () => {
},
})
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -277,7 +276,7 @@ describe('--dep', () => {
},
})
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -319,7 +318,7 @@ describe('--dep', () => {
},
})
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down
35 changes: 17 additions & 18 deletions test/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { chalkInit } from '../src/lib/chalk'
import { PackageManagerName } from '../src/types/PackageManagerName'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'
import { rmOptions } from './helpers/testConstants'

chaiSetup()

Expand Down Expand Up @@ -69,13 +68,13 @@ const testPass = ({ packageManager }: { packageManager: PackageManagerName }) =>

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
await fs.rm(nodeModulesPath, rmOptions)
await fs.rm(lockfilePath, rmOptions)
await fs.rm(nodeModulesPath, { recursive: true, force: true })
await fs.rm(lockfilePath, { recursive: true, force: true })

// delete yarn cache
if (packageManager === 'yarn') {
await fs.rm(path.join(cwd, '.yarn'), rmOptions)
await fs.rm(path.join(cwd, '.pnp.js'), rmOptions)
await fs.rm(path.join(cwd, '.yarn'), { recursive: true, force: true })
await fs.rm(path.join(cwd, '.pnp.js'), { recursive: true, force: true })
}

// bun prints the run header to stderr instead of stdout
Expand Down Expand Up @@ -134,13 +133,13 @@ const testFail = ({ packageManager }: { packageManager: PackageManagerName }) =>
} finally {
pkgUpgraded = await fs.readFile(pkgPath, 'utf-8')
await fs.writeFile(pkgPath, pkgOriginal)
await fs.rm(nodeModulesPath, rmOptions)
await fs.rm(lockfilePath, rmOptions)
await fs.rm(nodeModulesPath, { recursive: true, force: true })
await fs.rm(lockfilePath, { recursive: true, force: true })

// delete yarn cache
if (packageManager === 'yarn') {
await fs.rm(path.join(cwd, '.yarn'), rmOptions)
await fs.rm(path.join(cwd, '.pnp.js'), rmOptions)
await fs.rm(path.join(cwd, '.yarn'), { recursive: true, force: true })
await fs.rm(path.join(cwd, '.pnp.js'), { recursive: true, force: true })
}
}

Expand Down Expand Up @@ -235,8 +234,8 @@ describe('doctor', function () {

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
await fs.rm(lockfilePath, rmOptions)
await fs.rm(nodeModulesPath, rmOptions)
await fs.rm(lockfilePath, { recursive: true, force: true })
await fs.rm(nodeModulesPath, { recursive: true, force: true })

// stderr should be empty
stderr.should.equal('')
Expand Down Expand Up @@ -277,8 +276,8 @@ describe('doctor', function () {

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
await fs.rm(lockfilePath, rmOptions)
await fs.rm(nodeModulesPath, rmOptions)
await fs.rm(lockfilePath, { recursive: true, force: true })
await fs.rm(nodeModulesPath, { recursive: true, force: true })

// stderr should be empty
stderr.should.equal('')
Expand Down Expand Up @@ -318,8 +317,8 @@ describe('doctor', function () {

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
await fs.rm(lockfilePath, rmOptions)
await fs.rm(nodeModulesPath, rmOptions)
await fs.rm(lockfilePath, { recursive: true, force: true })
await fs.rm(nodeModulesPath, { recursive: true, force: true })

// stderr should be empty
stderr.should.equal('')
Expand Down Expand Up @@ -359,8 +358,8 @@ describe('doctor', function () {

// cleanup before assertions in case they fail
await fs.writeFile(pkgPath, pkgOriginal)
await fs.rm(lockfilePath, rmOptions)
await fs.rm(nodeModulesPath, rmOptions)
await fs.rm(lockfilePath, { recursive: true, force: true })
await fs.rm(nodeModulesPath, { recursive: true, force: true })

// stderr should be empty
stderr.should.equal('')
Expand Down Expand Up @@ -431,7 +430,7 @@ else {

pkgUpgraded = JSON.parse(await fs.readFile(pkgPath, 'utf-8'))
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
}

// stdout should include successful upgrades
Expand Down
3 changes: 1 addition & 2 deletions test/filterResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import path from 'path'
import ncu from '../src/'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'
import { rmOptions } from './helpers/testConstants'

chaiSetup()

Expand Down Expand Up @@ -50,7 +49,7 @@ describe('filterResults', () => {
expect(upgraded).to.have.property('ncu-test-v2', '3.0.0')
expect(upgraded).to.not.have.property('ncu-test-return-version')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down
11 changes: 5 additions & 6 deletions test/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import path from 'path'
import spawn from 'spawn-please'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'
import { rmOptions } from './helpers/testConstants'

chaiSetup()

Expand Down Expand Up @@ -50,7 +49,7 @@ describe('format', () => {
const output = await spawn('node', [bin, '--format', 'repo'], { cwd: tempDir })
output.should.include('https://github.com/Mitsunee/modern-diacritics')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
}
})

Expand Down Expand Up @@ -78,7 +77,7 @@ describe('format', () => {
const output = await spawn('node', [bin, '--format', 'lines'], { cwd: tempDir })
output.should.equals('ncu-test-v2@^2.0.0\nncu-test-tag@^1.1.0\n')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -108,7 +107,7 @@ describe('format', () => {
cwd: tempDir,
}).should.eventually.be.rejectedWith('Cannot specify both --format lines and --jsonUpgraded.')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -138,7 +137,7 @@ describe('format', () => {
cwd: tempDir,
}).should.eventually.be.rejectedWith('Cannot specify both --format lines and --jsonAll.')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down Expand Up @@ -168,7 +167,7 @@ describe('format', () => {
cwd: tempDir,
}).should.eventually.be.rejectedWith('Cannot use --format lines with other formatting options.')
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
Expand Down
3 changes: 1 addition & 2 deletions test/group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import spawn from 'spawn-please'
import { GroupFunction } from '../src/types/GroupFunction'
import chaiSetup from './helpers/chaiSetup'
import stubNpmView from './helpers/stubNpmView'
import { rmOptions } from './helpers/testConstants'

chaiSetup()

Expand Down Expand Up @@ -47,7 +46,7 @@ async function groupTestScaffold(
})
stripAnsi(stdout).should.containIgnoreCase(expectedOutput)
} finally {
await fs.rm(tempDir, rmOptions)
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
}
Expand Down
3 changes: 0 additions & 3 deletions test/helpers/testConstants.ts

This file was deleted.

Loading

0 comments on commit b2ca2cd

Please sign in to comment.