From 5a1b10c2dca02f657ef8a8bca6b8d2574020ff8f Mon Sep 17 00:00:00 2001 From: zkochan Date: Sun, 29 Jan 2017 18:52:55 +0200 Subject: [PATCH] test: breaking changes --- src/api/checkCompatibility.ts | 8 ++--- test/breakingChanges.ts | 65 +++++++++++++++++++++++++++++++++++ test/index.ts | 1 + 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 test/breakingChanges.ts diff --git a/src/api/checkCompatibility.ts b/src/api/checkCompatibility.ts index 3fbc8ac6e2..f7de5def93 100644 --- a/src/api/checkCompatibility.ts +++ b/src/api/checkCompatibility.ts @@ -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 }) } diff --git a/test/breakingChanges.ts b/test/breakingChanges.ts new file mode 100644 index 0000000000..c77f626469 --- /dev/null +++ b/test/breakingChanges.ts @@ -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}`) +} diff --git a/test/index.ts b/test/index.ts index 1f2de28308..f372d2010c 100644 --- a/test/index.ts +++ b/test/index.ts @@ -5,3 +5,4 @@ import './uninstall' import './link' import './prune' import './cache' +import './breakingChanges'