3
3
import * as firebaseFunctions from 'firebase-functions' ;
4
4
import * as firebaseAdmin from 'firebase-admin' ;
5
5
6
- import { verifyJWTAndUpdateData } from './data ' ;
6
+ import { verifyJwtAndTransferResultToTrustedLocation } from './verify-and-copy-report ' ;
7
7
import { convertGoldenImagesToData } from './image_data' ;
8
8
import { convertTestImageDataToFiles } from './data_image' ;
9
9
import { copyTestImagesToGoldens } from './test_goldens' ;
10
10
import { updateGithubStatus } from './github' ;
11
11
12
12
/**
13
13
* Usage: Firebase functions only accept javascript file index.js
14
- * tsc
14
+ * tsc -p tools/screenshot-test/functions/tsconfig.json
15
+ * cd functions
16
+ * npm install
15
17
* firebase deploy --only functions
16
18
*
17
19
*
18
20
* Data and images handling for Screenshot test.
19
21
*
20
- * All users can post data to temporary folder. These Functions will check the data with JsonWebToken and
21
- * move the valid data out of temporary folder.
22
+ * All users can post data to temporary folder. These Functions will check the data with
23
+ * JsonWebToken and move the valid data out of temporary folder.
22
24
*
23
25
* For valid data posted to database /$temp/screenshot/reports/$prNumber/$secureToken, move it to
24
26
* /screenshot/reports/$prNumber.
25
- * These are data for screenshot results (success or failure), GitHub PR/commit and TravisCI job information
27
+ * These are data for screenshot results (success or failure), GitHub PR/commit and TravisCI job
28
+ * information.
26
29
*
27
- * For valid image results written to database /$temp/screenshot/images/$prNumber/$secureToken/, save the image
28
- * data to image files and upload to google cloud storage under location /screenshots/$prNumber
29
- * These are screenshot test result images, and difference images generated from screenshot comparison.
30
+ * For valid image results written to database /$temp/screenshot/images/$prNumber/$secureToken/,
31
+ * save the image data to image files and upload to google cloud storage under
32
+ * location /screenshots/$prNumber
33
+ * These are screenshot test result images, and difference images generated from screenshot
34
+ * comparison.
30
35
*
31
- * For golden images uploaded to /goldens, read the data from images files and write the data to Firebase database
32
- * under location /screenshot/goldens
33
- * Screenshot tests can only read restricted database data with no credentials, and they cannot access
34
- * Google Cloud Storage. Therefore we copy the image data to database to make it available to screenshot tests.
36
+ * For golden images uploaded to /goldens, read the data from images files and write the data to
37
+ * Firebase database under location /screenshot/goldens
38
+ * Screenshot tests can only read restricted database data with no credentials, and they cannot
39
+ * access.
40
+ * Google Cloud Storage. Therefore we copy the image data to database to make it available to
41
+ * screenshot tests.
35
42
*
36
- * The JWT is stored in the data path, so every write to database needs a valid JWT to be copied to database/storage.
43
+ * The JWT is stored in the data path, so every write to database needs a valid JWT to be copied to
44
+ * database/storage.
37
45
* All invalid data will be removed.
38
46
* The JWT has 3 parts: header, payload and signature. These three parts are joint by '/' in path.
39
47
*/
@@ -65,11 +73,11 @@ const trustedReportPath = `screenshot/reports/{prNumber}`;
65
73
* sha (github PR info), result (true or false for all the tests), travis job number
66
74
*/
67
75
const testDataPath = `${ reportPath } /{dataType}` ;
68
- exports . testData = firebaseFunctions . database . ref ( testDataPath )
76
+ export let testData = firebaseFunctions . database . ref ( testDataPath )
69
77
. onWrite ( ( event : any ) => {
70
78
const dataType = event . params . dataType ;
71
79
if ( dataTypes . includes ( dataType ) ) {
72
- return verifyJWTAndUpdateData ( event , dataType ) ;
80
+ return verifyJwtAndTransferResultToTrustedLocation ( event , dataType ) ;
73
81
}
74
82
} ) ;
75
83
@@ -79,9 +87,9 @@ exports.testData = firebaseFunctions.database.ref(testDataPath)
79
87
* Data copied: test result for each file/test with ${filename}. The value should be true or false.
80
88
*/
81
89
const testResultsPath = `${ reportPath } /results/{filename}` ;
82
- exports . testResults = firebaseFunctions . database . ref ( testResultsPath )
90
+ export let testResults = firebaseFunctions . database . ref ( testResultsPath )
83
91
. onWrite ( ( event : any ) => {
84
- return verifyJWTAndUpdateData ( event , `results/${ event . params . filename } ` ) ;
92
+ return verifyJwtAndTransferResultToTrustedLocation ( event , `results/${ event . params . filename } ` ) ;
85
93
} ) ;
86
94
87
95
/**
@@ -90,14 +98,14 @@ exports.testResults = firebaseFunctions.database.ref(testResultsPath)
90
98
* Data copied: test result images. Convert from data to image files in storage.
91
99
*/
92
100
const imageDataToFilePath = `${ imagePath } /{dataType}/{filename}` ;
93
- exports . imageDataToFile = firebaseFunctions . database . ref ( imageDataToFilePath )
101
+ export let imageDataToFile = firebaseFunctions . database . ref ( imageDataToFilePath )
94
102
. onWrite ( convertTestImageDataToFiles ) ;
95
103
96
104
/**
97
105
* Copy valid goldens from storage /goldens/ to database /screenshot/goldens/
98
106
* so we can read the goldens without credentials.
99
107
*/
100
- exports . goldenImageToData = firebaseFunctions . storage . bucket (
108
+ export let goldenImageToData = firebaseFunctions . storage . bucket (
101
109
firebaseFunctions . config ( ) . firebase . storageBucket ) . object ( ) . onChange ( ( event : any ) => {
102
110
return convertGoldenImagesToData ( event . data . name , event . data . resourceState , event . data . bucket ) ;
103
111
} ) ;
@@ -107,7 +115,8 @@ exports.goldenImageToData = firebaseFunctions.storage.bucket(
107
115
* Copy images from /screenshot/$prNumber/test/ to /goldens/
108
116
*/
109
117
const approveImagesPath = `${ trustedReportPath } /approved` ;
110
- exports . approveImages = firebaseFunctions . database . ref ( approveImagesPath ) . onWrite ( ( event : any ) => {
118
+ export let approveImages = firebaseFunctions . database . ref ( approveImagesPath )
119
+ . onWrite ( ( event : any ) => {
111
120
return copyTestImagesToGoldens ( event . params . prNumber ) ;
112
121
} ) ;
113
122
@@ -117,4 +126,5 @@ exports.approveImages = firebaseFunctions.database.ref(approveImagesPath).onWrit
117
126
* The Github Status Token is set in config.secret.github
118
127
*/
119
128
const githubStatusPath = `${ trustedReportPath } /result/{sha}` ;
120
- exports . githubStatus = firebaseFunctions . database . ref ( githubStatusPath ) . onWrite ( updateGithubStatus ) ;
129
+ export let githubStatus = firebaseFunctions . database . ref ( githubStatusPath )
130
+ . onWrite ( updateGithubStatus ) ;
0 commit comments