diff --git a/test/doctor.test.ts b/test/doctor.test.ts index 7831d4d7..8a3b412d 100644 --- a/test/doctor.test.ts +++ b/test/doctor.test.ts @@ -8,6 +8,7 @@ import { rimraf } from 'rimraf' import spawn from 'spawn-please' import { cliOptionsMap } from '../src/cli-options' import { chalkInit } from '../src/lib/chalk' +import { PackageManagerName } from '../src/types/PackageManagerName' chai.should() chai.use(chaiAsPromised) @@ -22,7 +23,7 @@ const doctorTests = path.join(__dirname, 'test-data/doctor') const ncu = (args: string[], options?: Record) => spawn('node', [bin, ...args], options) /** Assertions for npm or yarn when tests pass. */ -const testPass = ({ packageManager }: { packageManager: string }) => { +const testPass = ({ packageManager }: { packageManager: PackageManagerName }) => { it('upgrade dependencies when tests pass', async function () { // use dynamic import for ESM module const { default: stripAnsi } = await import('strip-ansi') @@ -31,7 +32,13 @@ const testPass = ({ packageManager }: { packageManager: string }) => { const nodeModulesPath = path.join(cwd, 'node_modules') const lockfilePath = path.join( cwd, - packageManager === 'yarn' ? 'yarn.lock' : packageManager === 'pnpm' ? 'pnpm-lock.yaml' : 'package-lock.json', + packageManager === 'yarn' + ? 'yarn.lock' + : packageManager === 'pnpm' + ? 'pnpm-lock.yaml' + : packageManager === 'bun' + ? 'bun.lockb' + : 'package-lock.json', ) const pkgOriginal = await fs.readFile(path.join(cwd, 'package.json'), 'utf-8') let stdout = '' @@ -83,12 +90,21 @@ const testPass = ({ packageManager }: { packageManager: string }) => { } /** Assertions for npm or yarn when tests fail. */ -const testFail = ({ packageManager }: { packageManager: string }) => { +const testFail = ({ packageManager }: { packageManager: PackageManagerName }) => { it('identify broken upgrade', async function () { const cwd = path.join(doctorTests, 'fail') const pkgPath = path.join(cwd, 'package.json') const nodeModulesPath = path.join(cwd, 'node_modules') - const lockfilePath = path.join(cwd, packageManager === 'npm' ? 'package-lock.json' : 'yarn.lock') + const lockfilePath = path.join( + cwd, + packageManager === 'yarn' + ? 'yarn.lock' + : packageManager === 'pnpm' + ? 'pnpm-lock.yaml' + : packageManager === 'bun' + ? 'bun.lockb' + : 'package-lock.json', + ) const pkgOriginal = await fs.readFile(path.join(cwd, 'package.json'), 'utf-8') let stdout = '' let stderr = '' @@ -446,4 +462,10 @@ console.log(createFactories())`, testPass({ packageManager: 'yarn' }) testFail({ packageManager: 'yarn' }) }) + + describe('bun', () => { + // TODO: fix doctor bun tests + // testPass({ packageManager: 'bun' }) + // testFail({ packageManager: 'bun' }) + }) }) diff --git a/test/package-managers/bun/index.test.ts b/test/package-managers/bun/index.test.ts index 5e0ec01a..81f0b890 100644 --- a/test/package-managers/bun/index.test.ts +++ b/test/package-managers/bun/index.test.ts @@ -1,9 +1,13 @@ import chai from 'chai' import chaiAsPromised from 'chai-as-promised' +import chaiString from 'chai-string' import * as bun from '../../../src/package-managers/bun' chai.should() chai.use(chaiAsPromised) +chai.use(chaiString) + +process.env.NCU_TESTS = 'true' describe('bun', function () { it('list', async () => {