Skip to content

Commit

Permalink
server.listen and server.close are async
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Aug 30, 2018
1 parent 327a4b4 commit 802c30b
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 50 deletions.
13 changes: 9 additions & 4 deletions spec/docs-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ describe 'apm docs', ->
response.sendFile path.join(__dirname, 'fixtures', 'wrap-guide.json')
app.get '/install', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'install.json')
server = http.createServer(app)
server.listen(3000)
server = http.createServer(app)

process.env.ATOM_PACKAGES_URL = "http://localhost:3000"
live = false
server.listen 3000, '127.0.0.1', ->
process.env.ATOM_PACKAGES_URL = "http://localhost:3000"
live = true
waitsFor -> live

afterEach ->
server.close()
done = false
server.close -> done = true
waitsFor -> done

it 'logs an error if the package has no URL', ->
callback = jasmine.createSpy('callback')
Expand Down
14 changes: 9 additions & 5 deletions spec/featured-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ describe 'apm featured', ->
response.sendFile path.join(__dirname, 'fixtures', 'packages.json')
app.get '/themes/featured', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'themes.json')
server = http.createServer(app)

server = http.createServer(app)
server.listen(3000)

process.env.ATOM_API_URL = "http://localhost:3000"
live = false
server.listen 3000, '127.0.0.1', ->
process.env.ATOM_API_URL = "http://localhost:3000"
live = true
waitsFor -> live

afterEach ->
server.close()
done = false
server.close -> done = true
waitsFor -> done

it 'lists the featured packages and themes', ->
callback = jasmine.createSpy('callback')
Expand Down
17 changes: 11 additions & 6 deletions spec/publish-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ describe 'apm publish', ->

app = express()
server = http.createServer(app)
server.listen(3000)

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 = 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 ->
server.close()
done = false
server.close -> done = true
waitsFor -> done

it "validates the package's package.json file", ->
packageToPublish = temp.mkdirSync('apm-test-package-')
Expand Down
28 changes: 17 additions & 11 deletions spec/rebuild-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,29 @@ describe 'apm rebuild', ->
app.get '/node/v0.10.3/SHASUMS256.txt', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'SHASUMS256.txt')

server = http.createServer(app)
server.listen(3000)
server = http.createServer(app)

atomHome = temp.mkdirSync('apm-home-dir-')
process.env.ATOM_HOME = atomHome
process.env.ATOM_ELECTRON_URL = "http://localhost:3000/node"
process.env.ATOM_PACKAGES_URL = "http://localhost:3000/packages"
process.env.ATOM_ELECTRON_VERSION = 'v0.10.3'
process.env.ATOM_RESOURCE_PATH = temp.mkdirSync('atom-resource-path-')
live = false
server.listen 3000, '127.0.0.1', ->
atomHome = temp.mkdirSync('apm-home-dir-')
process.env.ATOM_HOME = atomHome
process.env.ATOM_ELECTRON_URL = "http://localhost:3000/node"
process.env.ATOM_PACKAGES_URL = "http://localhost:3000/packages"
process.env.ATOM_ELECTRON_VERSION = 'v0.10.3'
process.env.ATOM_RESOURCE_PATH = temp.mkdirSync('atom-resource-path-')

originalPathEnv = process.env.PATH
process.env.PATH = ""
originalPathEnv = process.env.PATH
process.env.PATH = ""
live = true
waitsFor -> live

afterEach ->
server.close()
process.env.PATH = originalPathEnv

done = false
server.close -> done = true
waitsFor -> done

it "rebuilds all modules when no module names are specified", ->
packageToRebuild = path.join(__dirname, 'fixtures/package-with-native-deps')

Expand Down
13 changes: 9 additions & 4 deletions spec/search-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ describe 'apm search', ->
app = express()
app.get '/search', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'search.json')
server = http.createServer(app)
server.listen(3000)
server = http.createServer(app)

process.env.ATOM_PACKAGES_URL = "http://localhost:3000"
live = false
server.listen 3000, '127.0.0.1', ->
process.env.ATOM_PACKAGES_URL = "http://localhost:3000"
live = true
waitsFor -> live

afterEach ->
server.close()
done = false
server.close -> done = true
waitsFor -> done

it 'lists the matching packages and excludes deprecated packages', ->
callback = jasmine.createSpy('callback')
Expand Down
15 changes: 10 additions & 5 deletions spec/unpublish-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ describe 'apm unpublish', ->
unpublishVersionCallback()
response.status(204).send(204)

server = http.createServer(app)
server.listen(3000)
server = http.createServer(app)

process.env.ATOM_HOME = temp.mkdirSync('apm-home-dir-')
process.env.ATOM_API_URL = "http://localhost:3000"
live = false
server.listen 3000, '127.0.0.1', ->
process.env.ATOM_HOME = temp.mkdirSync('apm-home-dir-')
process.env.ATOM_API_URL = "http://localhost:3000"
live = true
waitsFor -> live

afterEach ->
server.close()
done = false
server.close -> done = true
waitsFor -> done

describe "when no version is specified", ->
it 'unpublishes the package', ->
Expand Down
29 changes: 17 additions & 12 deletions spec/upgrade-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,26 @@ describe "apm upgrade", ->
app.get '/packages/different-repo', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'upgrade-different-repo.json')
server = http.createServer(app)
server.listen(3000)

atomHome = temp.mkdirSync('apm-home-dir-')
atomApp = temp.mkdirSync('apm-app-dir-')
packagesDir = path.join(atomHome, 'packages')
process.env.ATOM_HOME = atomHome
process.env.ATOM_ELECTRON_URL = "http://localhost:3000/node"
process.env.ATOM_PACKAGES_URL = "http://localhost:3000/packages"
process.env.ATOM_ELECTRON_VERSION = 'v0.10.3'
process.env.ATOM_RESOURCE_PATH = atomApp

fs.writeFileSync(path.join(atomApp, 'package.json'), JSON.stringify(version: '0.10.0'))
live = false
server.listen 3000, '127.0.0.1', ->
atomHome = temp.mkdirSync('apm-home-dir-')
atomApp = temp.mkdirSync('apm-app-dir-')
packagesDir = path.join(atomHome, 'packages')
process.env.ATOM_HOME = atomHome
process.env.ATOM_ELECTRON_URL = "http://localhost:3000/node"
process.env.ATOM_PACKAGES_URL = "http://localhost:3000/packages"
process.env.ATOM_ELECTRON_VERSION = 'v0.10.3'
process.env.ATOM_RESOURCE_PATH = atomApp

fs.writeFileSync(path.join(atomApp, 'package.json'), JSON.stringify(version: '0.10.0'))
live = true
waitsFor -> live

afterEach ->
server.close()
done = false
server.close -> done = true
waitsFor -> done

it "does not display updates for unpublished packages", ->
fs.writeFileSync(path.join(packagesDir, 'not-published', 'package.json'), JSON.stringify({name: 'not-published', version: '1.0', repository: 'https://github.com/a/b'}))
Expand Down
11 changes: 8 additions & 3 deletions spec/view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ describe 'apm view', ->
app.get '/wrap-guide', (request, response) ->
response.sendFile path.join(__dirname, 'fixtures', 'wrap-guide.json')
server = http.createServer(app)
server.listen(3000)

process.env.ATOM_PACKAGES_URL = "http://localhost:3000"
live = false
server.listen 3000, '127.0.0.1', ->
process.env.ATOM_PACKAGES_URL = "http://localhost:3000"
live = true
waitsFor -> live

afterEach ->
server.close()
done = false
server.close -> done = true
waitsFor -> done

it 'displays information about the package', ->
callback = jasmine.createSpy('callback')
Expand Down

0 comments on commit 802c30b

Please sign in to comment.