1- /**
2- * Copyright 2016, Google, Inc.
3- * Licensed under the Apache License, Version 2.0 (the "License");
4- * you may not use this file except in compliance with the License.
5- * You may obtain a copy of the License at
6- *
7- * http://www.apache.org/licenses/LICENSE-2.0
8- *
9- * Unless required by applicable law or agreed to in writing, software
10- * distributed under the License is distributed on an "AS IS" BASIS,
11- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12- * See the License for the specific language governing permissions and
13- * limitations under the License.
14- */
1+ // Copyright 2016, Google, Inc.
2+ // Licensed under the Apache License, Version 2.0 (the "License");
3+ // you may not use this file except in compliance with the License.
4+ // You may obtain a copy of the License at
5+ //
6+ // http://www.apache.org/licenses/LICENSE-2.0
7+ //
8+ // Unless required by applicable law or agreed to in writing, software
9+ // distributed under the License is distributed on an "AS IS" BASIS,
10+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+ // See the License for the specific language governing permissions and
12+ // limitations under the License.
1513
1614'use strict' ;
1715
18- const express = require ( ` express` ) ;
19- const path = require ( ` path` ) ;
20- const proxyquire = require ( ` proxyquire` ) . noPreserveCache ( ) ;
21- const request = require ( ` supertest` ) ;
16+ var express = require ( ' express' ) ;
17+ var path = require ( ' path' ) ;
18+ var proxyquire = require ( ' proxyquire' ) . noPreserveCache ( ) ;
19+ var request = require ( ' supertest' ) ;
2220
23- const SAMPLE_PATH = path . join ( __dirname , ` ../app.js` ) ;
21+ var SAMPLE_PATH = path . join ( __dirname , ' ../app.js' ) ;
2422
2523function getSample ( ) {
26- const testApp = express ( ) ;
27- sinon . stub ( testApp , ` listen` ) . callsArg ( 1 ) ;
28- const expressMock = sinon . stub ( ) . returns ( testApp ) ;
29- const resultsMock = {
24+ var testApp = express ( ) ;
25+ sinon . stub ( testApp , ' listen' ) . callsArg ( 1 ) ;
26+ var expressMock = sinon . stub ( ) . returns ( testApp ) ;
27+ var resultsMock = {
3028 statusCode : 200 ,
31- foo : ` bar`
29+ foo : ' bar'
3230 } ;
3331
34- const requestMock = {
35- post : sinon . stub ( ) . yields ( null , resultsMock )
32+ var requestMock = {
33+ post : sinon . stub ( ) . callsArgWith ( 2 , null , resultsMock )
3634 } ;
3735
38- const app = proxyquire ( SAMPLE_PATH , {
36+ var app = proxyquire ( SAMPLE_PATH , {
3937 request : requestMock ,
4038 express : expressMock
4139 } ) ;
42-
4340 return {
4441 app : app ,
4542 mocks : {
@@ -50,52 +47,52 @@ function getSample () {
5047 } ;
5148}
5249
53- describe ( ` appengine/analytics/app.js` , ( ) => {
54- let sample ;
50+ describe ( ' appengine/analytics/app.js' , function ( ) {
51+ var sample ;
5552
56- beforeEach ( ( ) => {
53+ beforeEach ( function ( ) {
5754 sample = getSample ( ) ;
5855
5956 assert ( sample . mocks . express . calledOnce ) ;
6057 assert ( sample . app . listen . calledOnce ) ;
6158 assert . equal ( sample . app . listen . firstCall . args [ 0 ] , process . env . PORT || 8080 ) ;
6259 } ) ;
6360
64- it ( ` should record a visit` , ( done ) => {
65- const expectedResult = ` Event tracked.` ;
61+ it ( ' should record a visit' , function ( done ) {
62+ var expectedResult = ' Event tracked.' ;
6663
6764 request ( sample . app )
68- . get ( `/` )
65+ . get ( '/' )
6966 . expect ( 200 )
70- . expect ( ( response ) => {
67+ . expect ( function ( response ) {
7168 assert . equal ( response . text , expectedResult ) ;
7269 } )
7370 . end ( done ) ;
7471 } ) ;
7572
76- it ( ` should handle request error` , ( done ) => {
77- const expectedResult = ` request_error` ;
73+ it ( ' should handle request error' , function ( done ) {
74+ var expectedResult = ' request_error' ;
7875
7976 sample . mocks . request . post . onFirstCall ( ) . callsArgWith ( 2 , expectedResult ) ;
8077
8178 request ( sample . app )
82- . get ( `/` )
79+ . get ( '/' )
8380 . expect ( 500 )
84- . expect ( ( response ) => {
85- assert . equal ( response . text , expectedResult + `\n` ) ;
81+ . expect ( function ( response ) {
82+ assert . equal ( response . text , expectedResult + '\n' ) ;
8683 } )
8784 . end ( done ) ;
8885 } ) ;
8986
90- it ( ` should handle track error` , ( done ) => {
87+ it ( ' should handle track error' , function ( done ) {
9188 sample . mocks . request . post . onFirstCall ( ) . callsArgWith ( 2 , null , {
9289 statusCode : 400
9390 } ) ;
9491
9592 request ( sample . app )
9693 . get ( '/' )
9794 . expect ( 500 )
98- . expect ( ( response ) => {
95+ . expect ( function ( response ) {
9996 assert . notEqual ( response . text . indexOf ( 'Error: Tracking failed' ) , - 1 ) ;
10097 } )
10198 . end ( done ) ;
0 commit comments