mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-24 10:01:48 -04:00
test: breaking changes
This commit is contained in:
@@ -26,8 +26,7 @@ export default function checkCompatibility (
|
||||
})
|
||||
}
|
||||
const pnpmVersion = getPackageManagerVersion(modules.packageManager)
|
||||
checkStore(pnpmVersion, opts.storePath)
|
||||
checkModules(pnpmVersion, opts.modulesPath)
|
||||
check(pnpmVersion, opts.storePath, opts.modulesPath)
|
||||
}
|
||||
|
||||
function getPackageManagerVersion(packageManager: string) {
|
||||
@@ -39,7 +38,7 @@ function getPackageManagerVersion(packageManager: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkStore (pnpmVersion: string, storePath: string) {
|
||||
function check (pnpmVersion: string, storePath: string, modulesPath: string) {
|
||||
if (!pnpmVersion || semver.lt(pnpmVersion, '0.28.0')) {
|
||||
throw new StoreBreakingChangeError({
|
||||
storePath,
|
||||
@@ -66,9 +65,6 @@ function checkStore (pnpmVersion: string, storePath: string) {
|
||||
additionalInformation: 'The structure of store.json/dependencies was changed to not include the redundunt package.json at the end',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function checkModules (pnpmVersion: string, modulesPath: string) {
|
||||
if (!pnpmVersion || semver.lt(pnpmVersion, '0.48.0')) {
|
||||
throw new ModulesBreakingChangeError({ modulesPath, relatedPR: 534 })
|
||||
}
|
||||
|
||||
65
test/breakingChanges.ts
Normal file
65
test/breakingChanges.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import tape = require('tape')
|
||||
import promisifyTape from 'tape-promise'
|
||||
import fs = require('mz/fs')
|
||||
import mkdirp = require('mkdirp')
|
||||
import path = require('path')
|
||||
import prepare from './support/prepare'
|
||||
import testDefaults from './support/testDefaults'
|
||||
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) {
|
||||
mkdirp.sync('node_modules')
|
||||
await fs.writeFile('node_modules/.modules.yaml', `packageManager: pnpm@${pnpmVersion}\nstorePath: ${storePath}`)
|
||||
}
|
||||
@@ -5,3 +5,4 @@ import './uninstall'
|
||||
import './link'
|
||||
import './prune'
|
||||
import './cache'
|
||||
import './breakingChanges'
|
||||
|
||||
Reference in New Issue
Block a user