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
/
publish-spec.coffee
123 lines (103 loc) · 4.05 KB
/
publish-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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
path = require 'path'
fs = require 'fs-extra'
temp = require 'temp'
express = require 'express'
http = require 'http'
apm = require '../lib/apm-cli'
describe 'apm publish', ->
[server] = []
beforeEach ->
spyOnToken()
silenceOutput()
app = express()
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/api"
process.env.ATOM_RESOURCE_PATH = temp.mkdirSync('atom-resource-path-')
live = true
waitsFor -> live
afterEach ->
done = false
server.close -> done = true
waitsFor -> done
it "validates the package's package.json file", ->
packageToPublish = temp.mkdirSync('apm-test-package-')
fs.writeFileSync(path.join(packageToPublish, 'package.json'), '}{')
process.chdir(packageToPublish)
callback = jasmine.createSpy('callback')
apm.run(['publish'], callback)
waitsFor 'waiting for publish to complete', 600000, ->
callback.callCount is 1
runs ->
expect(callback.mostRecentCall.args[0].message).toBe 'Error parsing package.json file: Unexpected token } in JSON at position 0'
it "validates the package is in a Git repository", ->
packageToPublish = temp.mkdirSync('apm-test-package-')
metadata =
name: 'test'
version: '1.0.0'
fs.writeFileSync(path.join(packageToPublish, 'package.json'), JSON.stringify(metadata))
process.chdir(packageToPublish)
callback = jasmine.createSpy('callback')
apm.run(['publish'], callback)
waitsFor 'waiting for publish to complete', 600000, ->
callback.callCount is 1
runs ->
expect(callback.mostRecentCall.args[0].message).toBe 'Package must be in a Git repository before publishing: https://help.github.com/articles/create-a-repo'
it "validates the engines.atom range in the package.json file", ->
packageToPublish = temp.mkdirSync('apm-test-package-')
metadata =
name: 'test'
version: '1.0.0'
engines:
atom: '><>'
fs.writeFileSync(path.join(packageToPublish, 'package.json'), JSON.stringify(metadata))
process.chdir(packageToPublish)
callback = jasmine.createSpy('callback')
apm.run(['publish'], callback)
waitsFor 'waiting for publish to complete', 600000, ->
callback.callCount is 1
runs ->
expect(callback.mostRecentCall.args[0].message).toBe 'The Atom engine range in the package.json file is invalid: ><>'
it "validates the dependency semver ranges in the package.json file", ->
packageToPublish = temp.mkdirSync('apm-test-package-')
metadata =
name: 'test'
version: '1.0.0'
engines:
atom: '1'
dependencies:
abc: 'git://github.com/user/project.git'
abcd: 'latest'
foo: '^^'
fs.writeFileSync(path.join(packageToPublish, 'package.json'), JSON.stringify(metadata))
process.chdir(packageToPublish)
callback = jasmine.createSpy('callback')
apm.run(['publish'], callback)
waitsFor 'waiting for publish to complete', 600000, ->
callback.callCount is 1
runs ->
expect(callback.mostRecentCall.args[0].message).toBe 'The foo dependency range in the package.json file is invalid: ^^'
it "validates the dev dependency semver ranges in the package.json file", ->
packageToPublish = temp.mkdirSync('apm-test-package-')
metadata =
name: 'test'
version: '1.0.0'
engines:
atom: '1'
dependencies:
foo: '^5'
devDependencies:
abc: 'git://github.com/user/project.git'
abcd: 'latest'
bar: '1,3'
fs.writeFileSync(path.join(packageToPublish, 'package.json'), JSON.stringify(metadata))
process.chdir(packageToPublish)
callback = jasmine.createSpy('callback')
apm.run(['publish'], callback)
waitsFor 'waiting for publish to complete', 600000, ->
callback.callCount is 1
runs ->
expect(callback.mostRecentCall.args[0].message).toBe 'The bar dev dependency range in the package.json file is invalid: 1,3'