Skip to content

Instantly share code, notes, and snippets.

@iarna
Last active November 10, 2017 13:03
Show Gist options
  • Save iarna/d7cde31fb2fb35142036acb921adc5a8 to your computer and use it in GitHub Desktop.
Save iarna/d7cde31fb2fb35142036acb921adc5a8 to your computer and use it in GitHub Desktop.
package-lock-only tests

made a folder called install-package-lock-only containing only a package.json with these contents:

{
  "name": "install-package-lock-only",
  "version": "1.0.0",
  "dependencies": {
    "mkdirp": "^0.3.4"
  }
}

Then I ran:

scripts/maketest install-package-lock-only  > test/tap/install-package-lock-only.js

And that produced the first revision of the attached file. Then I edited it to do pass in the command line option and have comments about the assertions we'll want.

'use strict'
var path = require('path')
var test = require('tap').test
var mr = require('npm-registry-mock')
var Tacks = require('tacks')
var File = Tacks.File
var Dir = Tacks.Dir
var extend = Object.assign || require('util')._extend
var common = require('../common-tap.js')
var basedir = path.join(__dirname, path.basename(__filename, '.js'))
var testdir = path.join(basedir, 'testdir')
var cachedir = path.join(basedir, 'cache')
var globaldir = path.join(basedir, 'global')
var tmpdir = path.join(basedir, 'tmp')
var conf = {
cwd: testdir,
env: extend(extend({}, process.env), {
npm_config_cache: cachedir,
npm_config_tmp: tmpdir,
npm_config_prefix: globaldir,
npm_config_registry: common.registry,
npm_config_loglevel: 'warn'
})
}
var server
var fixture = new Tacks(Dir({
cache: Dir(),
global: Dir(),
tmp: Dir(),
testdir: Dir({
'package.json': File({
name: 'install-package-lock-only',
version: '1.0.0',
dependencies: {
mkdirp: '^0.3.4'
}
})
})
}))
function setup () {
cleanup()
fixture.create(basedir)
}
function cleanup () {
fixture.remove(basedir)
}
test('setup', function (t) {
setup()
mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
if (err) throw err
server = s
t.done()
})
})
test('package-lock-only', function (t) {
return common.npm(['install', '--package-lock-only'], conf).spread((code, stdout, stderr) => {
t.is(code, 0, 'command ran ok')
t.comment(stdout.trim())
t.comment(stderr.trim())
// TODO: Verify that node_modules does not exist
// TODO: Verify that package-lock.json exists and has `[email protected]` in it.
t.done()
})
})
test('cleanup', function (t) {
server.close()
cleanup()
t.done()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment