Files
pnpm/packages/plugin-commands-store/test/storeAdd.ts
Zoltan Kochan da091c7114 feat!: remove store state
PR #2542
ref #594
2020-05-10 12:02:46 +03:00

83 lines
2.2 KiB
TypeScript

import assertStore from '@pnpm/assert-store'
import { store } from '@pnpm/plugin-commands-store'
import { tempDir } from '@pnpm/prepare'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import fs = require('fs')
import loadJsonFile = require('load-json-file')
import path = require('path')
import exists = require('path-exists')
import test = require('tape')
const STORE_VERSION = 'v3'
test('pnpm store add express@4.16.3', async function (t) {
tempDir(t)
const storeDir = path.resolve('store')
await store.handler({
dir: process.cwd(),
rawConfig: {
registry: `http://localhost:${REGISTRY_MOCK_PORT}/`,
},
registries: { default: `http://localhost:${REGISTRY_MOCK_PORT}/` },
storeDir,
}, ['add', 'express@4.16.3'])
const { cafsHas } = assertStore(t, path.join(storeDir, STORE_VERSION))
await cafsHas('sha1-avilAjUNsyRuzEvs9rWjTSL37VM=')
t.end()
})
test('pnpm store add scoped package that uses not the standard registry', async function (t) {
tempDir(t)
const storeDir = path.resolve('store')
await store.handler({
dir: process.cwd(),
rawConfig: {
registry: 'https://registry.npmjs.org/',
},
registries: {
'@foo': `http://localhost:${REGISTRY_MOCK_PORT}/`,
'default': 'https://registry.npmjs.org/',
},
storeDir,
}, ['add', '@foo/no-deps@1.0.0'])
const { cafsHas } = assertStore(t, path.join(storeDir, STORE_VERSION))
await cafsHas('@foo/no-deps', '1.0.0')
t.end()
})
test('should fail if some packages can not be added', async (t) => {
tempDir(t)
fs.mkdirSync('_')
process.chdir('_')
const storeDir = path.resolve('pnpm-store')
let thrown = false
try {
await store.handler({
dir: process.cwd(),
rawConfig: {
registry: 'https://registry.npmjs.org/',
},
registries: {
'@foo': `http://localhost:${REGISTRY_MOCK_PORT}/`,
'default': 'https://registry.npmjs.org/',
},
storeDir,
}, ['add', '@pnpm/this-does-not-exist'])
} catch (e) {
thrown = true
t.equal(e.code, 'ERR_PNPM_STORE_ADD_FAILURE', 'has thrown the correct error code')
t.equal(e.message, 'Some packages have not been added correctly', 'has thrown the correct error')
}
t.ok(thrown, 'has thrown')
t.end()
})