mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-11 09:28:24 -04:00
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
/// <reference path="../../../typings/index.d.ts"/>
|
|
import path from 'path'
|
|
import readPackageJson, { fromDir as readPackageJsonFromDir } from '@pnpm/read-package-json'
|
|
|
|
const fixtures = path.join(__dirname, 'fixtures')
|
|
|
|
test('readPackageJson()', async () => {
|
|
expect((await readPackageJson(path.join(__dirname, '..', 'package.json'))).name).toBe('@pnpm/read-package-json')
|
|
})
|
|
|
|
test('fromDir()', async () => {
|
|
expect((await readPackageJsonFromDir(path.join(__dirname, '..'))).name).toBe('@pnpm/read-package-json')
|
|
})
|
|
|
|
test('readPackageJson() throw error when name is invalid', async () => {
|
|
let err
|
|
try {
|
|
await readPackageJson(path.join(fixtures, 'invalid-name', 'package.json'))
|
|
} catch (_: any) { // eslint-disable-line
|
|
err = _
|
|
}
|
|
expect(err.code).toBe('ERR_PNPM_BAD_PACKAGE_JSON')
|
|
})
|
|
|
|
test('readPackageJson() throw initial error when package.json not found', async () => {
|
|
let err
|
|
try {
|
|
await readPackageJson(path.join(fixtures, 'package.json'))
|
|
} catch (_: any) { // eslint-disable-line
|
|
err = _
|
|
}
|
|
expect(err.code).toBe('ENOENT')
|
|
})
|