• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env node
2'use strict'
3const loadFromDir = require('tacks/load-from-dir.js')
4
5process.exit(main(process.argv.slice(2)))
6
7function main (argv) {
8  if (argv.length !== 1) {
9    console.error('Usage: maketest <fixturedir>')
10    return 1
11  }
12  const fixturedir = process.argv[2]
13
14  console.log(generateFromDir(fixturedir))
15  return 0
16}
17
18function indent (ind, str) {
19  return str.replace(/\n/g, '\n' + ind)
20}
21
22function generateFromDir (dir) {
23  const tacks = loadFromDir(dir)
24  return `'use strict'
25const path = require('path')
26const test = require('tap').test
27const Tacks = require('tacks')
28const File = Tacks.File
29const Symlink = Tacks.Symlink
30const Dir = Tacks.Dir
31const common = require('../common-tap.js')
32
33const basedir = path.join(__dirname, path.basename(__filename, '.js'))
34const testdir = path.join(basedir, 'testdir')
35const cachedir = path.join(basedir, 'cache')
36const globaldir = path.join(basedir, 'global')
37const tmpdir = path.join(basedir, 'tmp')
38
39const conf = {
40  cwd: testdir,
41  env: common.newEnv().extend({
42    npm_config_cache: cachedir,
43    npm_config_tmp: tmpdir,
44    npm_config_prefix: globaldir,
45    npm_config_registry: common.registry,
46    npm_config_loglevel: 'warn'
47  })
48}
49
50const fixture = new Tacks(Dir({
51  cache: Dir(),
52  global: Dir(),
53  tmp: Dir(),
54  testdir: ${indent('  ', tacks.fixture.toSource())}
55}))
56
57function setup () {
58  cleanup()
59  fixture.create(basedir)
60}
61
62function cleanup () {
63  fixture.remove(basedir)
64}
65
66test('setup', t => {
67  setup()
68  return common.fakeRegistry.listen()
69})
70
71test('example', t => {
72  return common.npm(['install'], conf).then(([code, stdout, stderr]) => {
73    t.is(code, 0, 'command ran ok')
74    t.comment(stdout.trim())
75    t.comment(stderr.trim())
76    // your assertions here
77  })
78})
79
80test('cleanup', t => {
81  common.fakeRegistry.close()
82  cleanup()
83  t.done()
84})\n`
85}
86