Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/tap/shrinkwrap-extra-metadata.js')
-rw-r--r--test/tap/shrinkwrap-extra-metadata.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/tap/shrinkwrap-extra-metadata.js b/test/tap/shrinkwrap-extra-metadata.js
new file mode 100644
index 000000000..1947ee575
--- /dev/null
+++ b/test/tap/shrinkwrap-extra-metadata.js
@@ -0,0 +1,83 @@
+'use strict'
+
+const common = require('../common-tap.js')
+const fs = require('fs')
+const mkdirp = require('mkdirp')
+const mr = require('npm-registry-mock')
+const npm = require('../../lib/npm.js')
+const osenv = require('osenv')
+const path = require('path')
+const rimraf = require('rimraf')
+const shrinkwrap = require('../../lib/shrinkwrap.js')
+const ssri = require('ssri')
+const test = require('tap').test
+
+const pkg = path.join(__dirname, path.basename(__filename, '.js'))
+
+const EXEC_OPTS = { cwd: pkg }
+
+const json = {
+ author: 'Rockbert',
+ name: 'shrinkwrap-extra-metadata',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+
+ process.chdir(pkg)
+ t.end()
+})
+
+test('adds additional metadata fields from the pkglock spec', function (t) {
+ mr({ port: common.port }, function (er, s) {
+ common.npm(
+ [
+ '--registry', common.registry,
+ '--loglevel', 'silent',
+ 'shrinkwrap'
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout, stderr) {
+ t.ifError(err, 'shrinkwrap ran without issue')
+ t.notOk(code, 'shrinkwrap ran without raising error code')
+
+ fs.readFile(path.resolve(pkg, 'npm-shrinkwrap.json'), function (err, desired) {
+ t.ifError(err, 'read npm-shrinkwrap.json without issue')
+ t.same(
+ {
+ 'name': 'shrinkwrap-extra-metadata',
+ 'version': '0.0.0',
+ 'createdWith': `npm@${npm.version}`,
+ 'lockfileVersion': shrinkwrap.PKGLOCK_VERSION,
+ 'packageIntegrity': ssri.fromData(JSON.stringify(json, null, 2), {
+ algorithms: ['sha512']
+ }).toString()
+ },
+ JSON.parse(desired),
+ 'shrinkwrap wrote the expected metadata fields'
+ )
+
+ s.close()
+ t.end()
+ })
+ }
+ )
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+
+ t.end()
+})
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}