@@ -9,19 +9,41 @@ const smoke = require('./test/smoke.js');
99
1010const urls = [ ] ;
1111
12+ /**
13+ * Headers can be set:
14+ * - globally for all apps, in config.defaults.page.headers here
15+ * - per test, in smoke.js
16+ * Headers objects will be merged, cookies and flags will be concatenated
17+ * No flags allowed inside the cookie for easier merging: use the FT-Flags header instead
18+ */
19+
20+ const DEFAULT_COOKIE = 'secure=true' ;
21+ const DEFAULT_FLAGS = 'ads:off,sourcepoint:off,cookieMessage:off' ;
22+
23+ // Add any global config (inc headers) here
1224const config = {
1325 defaults : {
14- page : { } ,
26+ page : {
27+ headers : {
28+ 'Cookie' : DEFAULT_COOKIE ,
29+ 'FT-Flags' : DEFAULT_FLAGS
30+ }
31+ } ,
1532 timeout : 50000 ,
1633 hideElements : 'iframe[src*=google],iframe[src*=proxy]' ,
1734 rules : [ 'Principle1.Guideline1_3.1_3_1_AAA' ]
1835 } ,
1936 urls : [ ]
2037}
2138
22- // Override with project specifics, if any
39+
40+ // What routes returning 200 in smoke.js should we not test?
41+ // set per-project in PA11Y_ROUTE_EXCEPTIONS in config-vars
2342const exceptions = process . env . PA11Y_ROUTE_EXCEPTIONS ? process . env . PA11Y_ROUTE_EXCEPTIONS . split ( ',' ) : [ ] ;
24- config . defaults . page . headers = process . env . PA11Y_HEADERS ? JSON . parse ( process . env . PA11Y_HEADERS ) : { Cookie : 'next-flags=ads:off,sourcepoint:off,cookieMessage:off; secure=true' } ;
43+
44+ // What elements should we not run pa11y on (i.e. google ad iFrames)
45+ // set per-project in PA11Y_HIDE in config-vars
46+ // Use with caution. May break the experience for users.
2547config . defaults . hideElements = process . env . PA11Y_HIDE ? `${ process . env . PA11Y_HIDE } ,${ config . defaults . hideElements } ` : config . defaults . hideElements ;
2648
2749console . log ( 'PA11Y_ROUTE_EXCEPTIONS:' , process . env . PA11Y_ROUTE_EXCEPTIONS ) ;
@@ -36,7 +58,7 @@ config.defaults.page.headers['FT-Next-Backend-Key'] = process.env.FT_NEXT_BACKEN
3658
3759
3860smoke . forEach ( ( smokeConfig ) => {
39- for ( url in smokeConfig . urls ) {
61+ for ( let url in smokeConfig . urls ) {
4062
4163 let isException = false ;
4264
@@ -52,21 +74,48 @@ smoke.forEach((smokeConfig) => {
5274 url : process . env . TEST_URL + url
5375 }
5476
55- if ( process . env . TEST_URL . includes ( 'local' ) ) {
77+ if ( process . env . TEST_URL . includes ( 'local' ) ) {
5678 thisUrl . screenCapture = './pa11y_screenCapture/' + url + '.png' ;
5779 }
5880
81+ // Do we have test-specific headers?
5982 if ( smokeConfig . headers ) {
6083 thisUrl . page = { } ;
61- thisUrl . page . headers = smokeConfig . headers
84+
85+ let fullCookie ;
86+ let fullFlags ;
87+
88+ // Merge the headers
89+ thisUrl . page . headers = Object . assign ( { } , config . defaults . page . headers , smokeConfig . headers ) ;
90+
91+ // concatenate any test-specific cookies
92+ if ( smokeConfig . headers . Cookie ) {
93+ console . log ( '• merging cookies...' ) ;
94+
95+ // Keep flags out of the cookie for easier merging
96+ if ( smokeConfig . headers . Cookie . indexOf ( 'flags' ) !== - 1 ) {
97+ throw Error ( 'please don\'t set any flags inside the Cookie. Use the \'FT-Flags\' header' ) ;
98+ }
99+
100+ // Set the concatenated cookies
101+ thisUrl . page . headers . Cookie = smokeConfig . headers . Cookie + '; ' + config . defaults . page . headers . Cookie ;
102+ }
103+
104+ // concatenate any test-specific flags
105+ if ( smokeConfig . headers [ 'FT-Flags' ] ) {
106+ console . log ( '• merging flags...' ) ;
107+
108+ // Set the concatenated flags
109+ thisUrl . page . headers [ 'FT-Flags' ] = smokeConfig . headers [ 'FT-Flags' ] + ',' + config . defaults . page . headers [ 'FT-Flags' ] ;
110+ }
62111 }
63112
64- urls . push ( thisUrl )
113+ urls . push ( thisUrl ) ;
65114 }
66115} ) ;
67116
68- for ( viewport of viewports ) {
69- for ( url of urls ) {
117+ for ( let viewport of viewports ) {
118+ for ( let url of urls ) {
70119 url . viewport = viewport ;
71120 config . urls . push ( url ) ;
72121 }
0 commit comments