mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-25 02:21:52 -04:00
86 lines
2.4 KiB
TypeScript
86 lines
2.4 KiB
TypeScript
import tape = require('tape')
|
|
import promisifyTape from 'tape-promise'
|
|
import fs = require('mz/fs')
|
|
import mkdirp = require('mkdirp-promise')
|
|
import path = require('path')
|
|
import {prepare, testDefaults} from './utils'
|
|
import {installPkgs} from '../src'
|
|
|
|
const test = promisifyTape(tape)
|
|
|
|
test('fail on non-compatible node_modules', async t => {
|
|
const project = prepare(t)
|
|
const opts = testDefaults()
|
|
|
|
await saveModulesYaml('0.50.0', path.join(opts.storePath, '1'))
|
|
|
|
try {
|
|
await installPkgs(['is-negative'], opts)
|
|
t.fail('should have failed')
|
|
} catch (err) {
|
|
t.equal(err.code, 'MODULES_BREAKING_CHANGE', 'modules breaking change error is thrown')
|
|
}
|
|
})
|
|
|
|
test("don't fail on non-compatible node_modules when forced", async t => {
|
|
const project = prepare(t)
|
|
const opts = testDefaults({force: true})
|
|
|
|
await saveModulesYaml('0.50.0', path.join(opts.storePath, '1'))
|
|
|
|
await installPkgs(['is-negative'], opts)
|
|
|
|
t.pass('install did not fail')
|
|
})
|
|
|
|
test('fail on non-compatible store', async t => {
|
|
const project = prepare(t)
|
|
const opts = testDefaults()
|
|
|
|
await saveModulesYaml('0.32.0', path.join(opts.storePath, '1'))
|
|
|
|
try {
|
|
await installPkgs(['is-negative'], opts)
|
|
t.fail('should have failed')
|
|
} catch (err) {
|
|
t.equal(err.code, 'STORE_BREAKING_CHANGE', 'store breaking change error is thrown')
|
|
}
|
|
})
|
|
|
|
test("don't fail on non-compatible store when forced", async t => {
|
|
const project = prepare(t)
|
|
const opts = testDefaults({force: true})
|
|
|
|
await saveModulesYaml('0.32.0', path.join(opts.storePath, '1'))
|
|
|
|
await installPkgs(['is-negative'], opts)
|
|
|
|
t.pass('install did not fail')
|
|
})
|
|
|
|
async function saveModulesYaml (pnpmVersion: string, storePath: string) {
|
|
await mkdirp('node_modules')
|
|
await fs.writeFile('node_modules/.modules.yaml', `packageManager: pnpm@${pnpmVersion}\nstorePath: ${storePath}`)
|
|
}
|
|
|
|
test('fail on non-compatible shrinkwrap.yaml', async t => {
|
|
const project = prepare(t)
|
|
await fs.writeFile('shrinkwrap.yaml', '')
|
|
|
|
try {
|
|
await installPkgs(['is-negative'], testDefaults())
|
|
t.fail('should have failed')
|
|
} catch (err) {
|
|
t.equal(err.code, 'SHRINKWRAP_BREAKING_CHANGE', 'shrinkwrap breaking change error is thrown')
|
|
}
|
|
})
|
|
|
|
test("don't fail on non-compatible shrinkwrap.yaml when forced", async t => {
|
|
const project = prepare(t)
|
|
await fs.writeFile('shrinkwrap.yaml', '')
|
|
|
|
await installPkgs(['is-negative'], testDefaults({force: true}))
|
|
|
|
t.pass('install did not fail')
|
|
})
|