Files
pnpm/packages/supi/test/storeAdd.ts
Tejasvi (Teju) Nareddy 2bf7c0d333 test(supi): abstract store assertions via assert-store
* chore(assert-store): introduce return types and getStorePath

Add return types to pre-existing methods
Introduce function to get store path, simplifying logic in assert-project later

* chore(assert-project): abstract store assertions via assert-store

Cache entire store object instead of just the store path
Store-related calls in assert-project are run against assert-store

* test(supi): call assert-store for store assertions

Test cases where `pnpm install` is not called do not have a valid project
Use assert-store directly for store assertions

* test(supi): abstract store assertions with assert-store

Replace direct store checking (via path-exists) with assert-store

* fix: storeHasNot() when store does not exist

* refactor: remove getStorePath from assert-store

PR #1560
2018-12-15 18:20:26 +02:00

54 lines
1.5 KiB
TypeScript

import assertStore from '@pnpm/assert-store'
import { tempDir } from '@pnpm/prepare'
import fs = require('fs')
import loadJsonFile from 'load-json-file'
import path = require('path')
import { storeAdd } from 'supi'
import tape = require('tape')
import promisifyTape from 'tape-promise'
import { testDefaults } from './utils'
const test = promisifyTape(tape)
const testOnly = promisifyTape(tape.only)
test('add packages to the store', async (t: tape.Test) => {
tempDir(t)
fs.mkdirSync('_')
process.chdir('_')
const opts = await testDefaults()
const store = assertStore(t, opts.store)
opts['registry'] = opts.registries!.default // tslint:disable-line
await storeAdd(['express@4.16.3'], opts)
// Assert package in file structure
await store.storeHas('express', '4.16.3')
// Assert package in store index
const storeIndex = await loadJsonFile(path.join(opts.store, 'store.json'))
t.deepEqual(
storeIndex,
{
'localhost+4873/express/4.16.3': [],
},
'package has been added to the store index',
)
})
test('should fail if some packages can not be added', async (t: tape.Test) => {
tempDir(t)
fs.mkdirSync('_')
process.chdir('_')
let thrown = false
try {
await storeAdd(['@pnpm/this-does-not-exist'], await testDefaults())
} 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')
})