'use babel'

/* @flow */

import Path from 'path'
import FS from 'fs'
import Installer from '../'
import { exec } from 'sb-exec'
import { readFile, writeFile, readJSON, exists } from 'motion-fs'

// const { it } = require(process.env.SPEC_HELPER_SCRIPT)
const { it } = require('/Users/steel/w/motion/scripts/../spec/helpers.js')

describe('Installer', function() {
  const testRoot = '/tmp/motion-spec'
  const testPackageName = 'sb-promisify' // <-- choosing because it's lightweight
  const testPackagePath = Path.join(testRoot, 'node_modules', 'sb-promisify')

  beforeEach(function() {
    waitsForPromise(async function() {
      await exec(process.env.SHELL, ['-c', `mkdir -p ${testRoot}`])
      await writeFile(Path.join(testRoot, 'package.json'), '{"dependencies": {}}')
    })
  })

  afterEach(function() {
    waitsForPromise(async function() {
      await exec(process.env.SHELL, ['-c', `rm -rf ${testRoot} || true`])
    })
  })

  it('installs and saves properly', async function() {
    console = require('console')
    const installer = new Installer({rootDirectory: testRoot})
    await installer.install('sb-promisify', true)
    expect(await exists(testPackagePath)).toBe(true)
    const manifest = await readJSON(Path.join(testRoot, 'package.json'))
    expect(typeof manifest.dependencies['sb-promisify']).toBe('string')
  })

  it('installs without saving', async function() {
    console = require('console')
    const installer = new Installer({rootDirectory: testRoot})
    await installer.install('sb-promisify')
    expect(await exists(testPackagePath)).toBe(true)
    const manifest = await readJSON(Path.join(testRoot, 'package.json'))
    expect(typeof manifest.dependencies['sb-promisify']).toBe('undefined')
  })

})

@@ -1397,41 +1397,8 @@
 ) %7B%0A
-    console = require('console')%0A
     
@@ -1448,32 +1448,32 @@
 ory: testRoot%7D)%0A
+
     await instal
@@ -1618,32 +1618,32 @@
 package.json'))%0A
-
     expect(typeo
@@ -1707,11 +1707,750 @@
 )%0A  %7D)%0A%0A
+  it('uninstalls and saves properly', async function() %7B%0A    const installer = new Installer(%7BrootDirectory: testRoot%7D)%0A    await installer.install('sb-promisify', true)%0A    await installer.uninstall('sb-promisify', true)%0A    const manifest = await readJSON(Path.join(testRoot, 'package.json'))%0A    expect(typeof manifest.dependencies%5B'sb-promisify'%5D).toBe('undefined')%0A  %7D)%0A%0A  it('uninstalls without saving', async function() %7B%0A    const installer = new Installer(%7BrootDirectory: testRoot%7D)%0A    await installer.install('sb-promisify', true)%0A    await installer.uninstall('sb-promisify')%0A    const manifest = await readJSON(Path.join(testRoot, 'package.json'))%0A    expect(typeof manifest.dependencies%5B'sb-promisify'%5D).toBe('string')%0A  %7D)%0A%0A
 %7D)%0A

Add specs about npm uninstaller