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.
15
13
16
14
'use strict' ;
17
15
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' ) ;
22
20
23
- const SAMPLE_PATH = path . join ( __dirname , ` ../app.js` ) ;
21
+ var SAMPLE_PATH = path . join ( __dirname , ' ../app.js' ) ;
24
22
25
23
function 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 = {
30
28
statusCode : 200 ,
31
- foo : ` bar`
29
+ foo : ' bar'
32
30
} ;
33
31
34
- const requestMock = {
35
- post : sinon . stub ( ) . yields ( null , resultsMock )
32
+ var requestMock = {
33
+ post : sinon . stub ( ) . callsArgWith ( 2 , null , resultsMock )
36
34
} ;
37
35
38
- const app = proxyquire ( SAMPLE_PATH , {
36
+ var app = proxyquire ( SAMPLE_PATH , {
39
37
request : requestMock ,
40
38
express : expressMock
41
39
} ) ;
42
-
43
40
return {
44
41
app : app ,
45
42
mocks : {
@@ -50,52 +47,52 @@ function getSample () {
50
47
} ;
51
48
}
52
49
53
- describe ( ` appengine/analytics/app.js` , ( ) => {
54
- let sample ;
50
+ describe ( ' appengine/analytics/app.js' , function ( ) {
51
+ var sample ;
55
52
56
- beforeEach ( ( ) => {
53
+ beforeEach ( function ( ) {
57
54
sample = getSample ( ) ;
58
55
59
56
assert ( sample . mocks . express . calledOnce ) ;
60
57
assert ( sample . app . listen . calledOnce ) ;
61
58
assert . equal ( sample . app . listen . firstCall . args [ 0 ] , process . env . PORT || 8080 ) ;
62
59
} ) ;
63
60
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.' ;
66
63
67
64
request ( sample . app )
68
- . get ( `/` )
65
+ . get ( '/' )
69
66
. expect ( 200 )
70
- . expect ( ( response ) => {
67
+ . expect ( function ( response ) {
71
68
assert . equal ( response . text , expectedResult ) ;
72
69
} )
73
70
. end ( done ) ;
74
71
} ) ;
75
72
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' ;
78
75
79
76
sample . mocks . request . post . onFirstCall ( ) . callsArgWith ( 2 , expectedResult ) ;
80
77
81
78
request ( sample . app )
82
- . get ( `/` )
79
+ . get ( '/' )
83
80
. expect ( 500 )
84
- . expect ( ( response ) => {
85
- assert . equal ( response . text , expectedResult + `\n` ) ;
81
+ . expect ( function ( response ) {
82
+ assert . equal ( response . text , expectedResult + '\n' ) ;
86
83
} )
87
84
. end ( done ) ;
88
85
} ) ;
89
86
90
- it ( ` should handle track error` , ( done ) => {
87
+ it ( ' should handle track error' , function ( done ) {
91
88
sample . mocks . request . post . onFirstCall ( ) . callsArgWith ( 2 , null , {
92
89
statusCode : 400
93
90
} ) ;
94
91
95
92
request ( sample . app )
96
93
. get ( '/' )
97
94
. expect ( 500 )
98
- . expect ( ( response ) => {
95
+ . expect ( function ( response ) {
99
96
assert . notEqual ( response . text . indexOf ( 'Error: Tracking failed' ) , - 1 ) ;
100
97
} )
101
98
. end ( done ) ;
0 commit comments