This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 292
/
stars-spec.coffee
108 lines (88 loc) · 4.19 KB
/
stars-spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
path = require 'path'
express = require 'express'
fs = require 'fs-extra'
http = require 'http'
temp = require 'temp'
apm = require '../lib/apm-cli'
describe 'apm stars', ->
[atomHome, server] = []
beforeEach ->
silenceOutput()
spyOnToken()
app = express()
app.get '/stars', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'available.json')
app.get '/users/hubot/stars', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'stars.json')
app.get '/node/v10.20.1/node-v10.20.1.tar.gz', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'node-v10.20.1.tar.gz')
app.get '/node/v10.20.1/node-v10.20.1-headers.tar.gz', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'node-v10.20.1-headers.tar.gz')
app.get '/node/v10.20.1/node.lib', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'node.lib')
app.get '/node/v10.20.1/x64/node.lib', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'node_x64.lib')
app.get '/node/v10.20.1/SHASUMS256.txt', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'SHASUMS256.txt')
app.get '/tarball/test-module-1.2.0.tgz', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'test-module-1.2.0.tgz')
app.get '/tarball/test-module2-2.0.0.tgz', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'test-module2-2.0.0.tgz')
app.get '/packages/test-module', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'install-test-module.json')
server = http.createServer(app)
live = false
server.listen 3000, '127.0.0.1', ->
atomHome = temp.mkdirSync('apm-home-dir-')
process.env.ATOM_HOME = atomHome
process.env.ATOM_API_URL = "http://localhost:3000"
process.env.ATOM_ELECTRON_URL = "http://localhost:3000/node"
process.env.ATOM_PACKAGES_URL = "http://localhost:3000/packages"
process.env.ATOM_ELECTRON_VERSION = 'v10.20.1'
process.env.npm_config_registry = 'http://localhost:3000/'
live = true
waitsFor -> live
afterEach ->
closed = false
server.close -> closed = true
waitsFor -> closed
describe "when no user flag is specified", ->
it 'lists your starred packages', ->
callback = jasmine.createSpy('callback')
apm.run(['stars'], callback)
waitsFor 'waiting for command to complete', ->
callback.callCount > 0
runs ->
expect(console.log).toHaveBeenCalled()
expect(console.log.argsForCall[1][0]).toContain 'beverly-hills'
describe "when a user flag is specified", ->
it 'lists their starred packages', ->
callback = jasmine.createSpy('callback')
apm.run(['stars', '--user', 'hubot'], callback)
waitsFor 'waiting for command to complete', ->
callback.callCount > 0
runs ->
expect(console.log).toHaveBeenCalled()
expect(console.log.argsForCall[1][0]).toContain 'test-module'
describe "when the install flag is specified", ->
it "installs all of the stars", ->
testModuleDirectory = path.join(atomHome, 'packages', 'test-module')
expect(fs.existsSync(testModuleDirectory)).toBeFalsy()
callback = jasmine.createSpy('callback')
apm.run(['stars', '--user', 'hubot', '--install'], callback)
waitsFor 'waiting for command to complete', ->
callback.callCount > 0
runs ->
expect(callback.mostRecentCall.args[0]).toBeNull()
expect(fs.existsSync(path.join(testModuleDirectory, 'index.js'))).toBeTruthy()
expect(fs.existsSync(path.join(testModuleDirectory, 'package.json'))).toBeTruthy()
describe 'when the theme flag is specified', ->
it "only lists themes", ->
callback = jasmine.createSpy('callback')
apm.run(['stars', '--themes'], callback)
waitsFor 'waiting for command to complete', ->
callback.callCount > 0
runs ->
expect(console.log).toHaveBeenCalled()
expect(console.log.argsForCall[1][0]).toContain 'duckblur'
expect(console.log.argsForCall[1][0]).not.toContain 'beverly-hills'