• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('fs')
2var path = require('path')
3
4var mkdirp = require('mkdirp')
5var test = require('tap').test
6
7var common = require('../common-tap.js')
8
9var pkg = common.pkg
10var subdir = path.resolve(pkg, 'subdir')
11
12var json = {
13  name: 'init-cwd',
14  version: '1.0.0',
15  scripts: {
16    initcwd: process.platform === 'win32' ? 'echo %INIT_CWD%' : 'echo "$INIT_CWD"'
17  }
18}
19
20test('setup', function (t) {
21  mkdirp.sync(subdir)
22  fs.writeFileSync(
23    path.join(pkg, 'package.json'),
24    JSON.stringify(json, null, 2)
25  )
26  t.end()
27})
28
29test('make sure the env.INIT_CWD is correct', t =>
30  common.npm(['run-script', 'initcwd'], { cwd: subdir })
31    .then(([code, stdout, stderr]) => {
32      t.equal(code, 0, 'exit code')
33      stdout = stdout.trim().split(/\r|\n/).pop()
34      var actual = stdout
35      t.equal(actual, subdir)
36    }))
37