Skip to content

Commit

Permalink
test: add bun doctor test
Browse files Browse the repository at this point in the history
  • Loading branch information
ImBIOS committed Aug 16, 2023
1 parent c4274c5 commit 8271d8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 26 additions & 4 deletions test/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -22,7 +23,7 @@ const doctorTests = path.join(__dirname, 'test-data/doctor')
const ncu = (args: string[], options?: Record<string, unknown>) => 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')
Expand All @@ -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 = ''
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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' })
})
})
4 changes: 4 additions & 0 deletions test/package-managers/bun/index.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down

0 comments on commit 8271d8f

Please sign in to comment.