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