-
Notifications
You must be signed in to change notification settings - Fork 2k
Upgrade apps for env:flex. #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
/** | ||
* Copyright 2016, Google, Inc. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var express = require('express'); | ||
var path = require('path'); | ||
var proxyquire = require('proxyquire').noPreserveCache(); | ||
var request = require('supertest'); | ||
const express = require(`express`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this overkill/idiomatic for strings where templating isn't used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In our tests, I've been switching to using string templates as much as possible. They're just better strings. In the sample files themselves I've only been using template strings where we need to do interpolation or concatenation. |
||
const path = require(`path`); | ||
const proxyquire = require(`proxyquire`).noPreserveCache(); | ||
const request = require(`supertest`); | ||
|
||
var SAMPLE_PATH = path.join(__dirname, '../app.js'); | ||
const SAMPLE_PATH = path.join(__dirname, `../app.js`); | ||
|
||
function getSample () { | ||
var testApp = express(); | ||
sinon.stub(testApp, 'listen').callsArg(1); | ||
var expressMock = sinon.stub().returns(testApp); | ||
var resultsMock = { | ||
const testApp = express(); | ||
sinon.stub(testApp, `listen`).callsArg(1); | ||
const expressMock = sinon.stub().returns(testApp); | ||
const resultsMock = { | ||
statusCode: 200, | ||
foo: 'bar' | ||
foo: `bar` | ||
}; | ||
|
||
var requestMock = { | ||
post: sinon.stub().callsArgWith(2, null, resultsMock) | ||
const requestMock = { | ||
post: sinon.stub().yields(null, resultsMock) | ||
}; | ||
|
||
var app = proxyquire(SAMPLE_PATH, { | ||
const app = proxyquire(SAMPLE_PATH, { | ||
request: requestMock, | ||
express: expressMock | ||
}); | ||
|
||
return { | ||
app: app, | ||
mocks: { | ||
|
@@ -47,52 +50,52 @@ function getSample () { | |
}; | ||
} | ||
|
||
describe('appengine/analytics/app.js', function () { | ||
var sample; | ||
describe(`appengine/analytics/app.js`, () => { | ||
let sample; | ||
|
||
beforeEach(function () { | ||
beforeEach(() => { | ||
sample = getSample(); | ||
|
||
assert(sample.mocks.express.calledOnce); | ||
assert(sample.app.listen.calledOnce); | ||
assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080); | ||
}); | ||
|
||
it('should record a visit', function (done) { | ||
var expectedResult = 'Event tracked.'; | ||
it(`should record a visit`, (done) => { | ||
const expectedResult = `Event tracked.`; | ||
|
||
request(sample.app) | ||
.get('/') | ||
.get(`/`) | ||
.expect(200) | ||
.expect(function (response) { | ||
.expect((response) => { | ||
assert.equal(response.text, expectedResult); | ||
}) | ||
.end(done); | ||
}); | ||
|
||
it('should handle request error', function (done) { | ||
var expectedResult = 'request_error'; | ||
it(`should handle request error`, (done) => { | ||
const expectedResult = `request_error`; | ||
|
||
sample.mocks.request.post.onFirstCall().callsArgWith(2, expectedResult); | ||
|
||
request(sample.app) | ||
.get('/') | ||
.get(`/`) | ||
.expect(500) | ||
.expect(function (response) { | ||
assert.equal(response.text, expectedResult + '\n'); | ||
.expect((response) => { | ||
assert.equal(response.text, expectedResult + `\n`); | ||
}) | ||
.end(done); | ||
}); | ||
|
||
it('should handle track error', function (done) { | ||
it(`should handle track error`, (done) => { | ||
sample.mocks.request.post.onFirstCall().callsArgWith(2, null, { | ||
statusCode: 400 | ||
}); | ||
|
||
request(sample.app) | ||
.get('/') | ||
.expect(500) | ||
.expect(function (response) { | ||
.expect((response) => { | ||
assert.notEqual(response.text.indexOf('Error: Tracking failed'), -1); | ||
}) | ||
.end(done); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,18 @@ | |
"license": "Apache Version 2.0", | ||
"author": "Google Inc.", | ||
"engines": { | ||
"node": "~4.2" | ||
"node": ">=4.3.2" | ||
}, | ||
"scripts": { | ||
"postinstall": "bower install --config.interactive=false", | ||
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js" | ||
}, | ||
"dependencies": { | ||
"bower": "^1.7.7", | ||
"express": "^4.13.4", | ||
"jade": "^1.11.0" | ||
"bower": "^1.7.9", | ||
"express": "^4.14.0", | ||
"pug": "^2.0.0-beta6" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, I was holding off on switching to Pug until it was out of beta for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jade should no longer be used (legal issues). Pug is just the Jade project renamed to Pug, so the code is quite battle-tested. Go ahead and switch to Pug. |
||
}, | ||
"devDependencies": { | ||
"mocha": "^2.5.3" | ||
"mocha": "^3.1.0" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is the new pattern to follow now? (checking for my own information)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, technically, with the errback pattern, the return value of a function should be
undefined
, so I'm moving thereturn;
to its own line to avoid the possibility of accidentally returning a value.