File tree 4 files changed +99
-0
lines changed
helpers/integration-tests
4 files changed +99
-0
lines changed Original file line number Diff line number Diff line change
1
+ const { runStaticTests } = require ( './staticUrls' ) ;
2
+ const { runScannerTest } = require ( './scanner' ) ;
3
+
4
+ console . log ( 'Integration tests are running...' ) ;
5
+
6
+ const runIntegrationTests = async ( ) => {
7
+ let error = false ;
8
+
9
+ for ( const test of [ runStaticTests , runScannerTest ] ) {
10
+ const errorFound = await test ( ) ;
11
+
12
+ if ( errorFound ) {
13
+ error = true ;
14
+ }
15
+ }
16
+
17
+ console . log ( `${
18
+ error ?
19
+ '🚨 Integration tests completed with errors.' :
20
+ '🏁 Integration tests completed successfully!'
21
+ } `) ;
22
+ } ;
23
+
24
+ runIntegrationTests ( ) ;
Original file line number Diff line number Diff line change
1
+ const puppeteer = require ( 'puppeteer' ) ;
2
+
3
+ const runScannerTest = async ( ) => {
4
+ const browser = await puppeteer . launch ( ) ;
5
+ const page = await browser . newPage ( ) ;
6
+
7
+ await page . goto ( 'https://sonarwhal-staging.azurewebsites.net/scanner/' ) ;
8
+ await page . type ( '#scanner-page-scan' , 'https://leosl.github.io/' ) ;
9
+
10
+ const [ response ] = await Promise . all ( [
11
+ page . waitForNavigation ( ) ,
12
+ page . click ( '.button--red' )
13
+ ] ) ;
14
+
15
+ await browser . close ( ) ;
16
+
17
+ console . log (
18
+ `🧾 Scanner test executed with ${
19
+ response . status ( ) === 200 ? '✅ success' : '❌ failure'
20
+ } ! => Status: ${ response . status ( ) } `
21
+ ) ;
22
+
23
+ return response . status ( ) !== 200 ;
24
+ } ;
25
+
26
+ module . exports = { runScannerTest } ;
Original file line number Diff line number Diff line change
1
+ const puppeteer = require ( 'puppeteer' ) ;
2
+
3
+ const staticURLsToVerify = [
4
+ 'https://sonarwhal-staging.azurewebsites.net/' ,
5
+ 'https://sonarwhal-staging.azurewebsites.net/search/?q=bla' ,
6
+ 'https://sonarwhal-staging.azurewebsites.net/about/changelog/1' ,
7
+ 'https://sonarwhal-staging.azurewebsites.net/docs/user-guide/hints/'
8
+ ] ;
9
+
10
+ const runPuppeteer = async ( url ) => {
11
+ const browser = await puppeteer . launch ( ) ;
12
+
13
+ try {
14
+ const page = await browser . newPage ( ) ;
15
+ const response = await page . goto ( url ) ;
16
+
17
+ console . log (
18
+ `${
19
+ response . status ( ) === 200 ? '✅ Success' : '❌ Failure'
20
+ } ! ${ url } => Status: ${ response . status ( ) } `
21
+ ) ;
22
+
23
+ await browser . close ( ) ;
24
+
25
+ return response . status ( ) ;
26
+ } catch ( error ) {
27
+ console . error ( '🚨 Something went wrong while executing Puppeteer: ' , error ) ;
28
+ await browser . close ( ) ;
29
+
30
+ return 0 ;
31
+ }
32
+ } ;
33
+
34
+ const runStaticTests = async ( ) => {
35
+ let errorFound = false ;
36
+
37
+ for ( const url of staticURLsToVerify ) {
38
+ const resultStatus = await runPuppeteer ( url ) ;
39
+
40
+ if ( resultStatus !== 200 ) {
41
+ errorFound = true ;
42
+ }
43
+ }
44
+
45
+ return errorFound ;
46
+ } ;
47
+
48
+ module . exports = { runStaticTests } ;
Original file line number Diff line number Diff line change 58
58
"mktemp" : " ^1.0.0" ,
59
59
"normalize-path" : " ^3.0.0" ,
60
60
"npm-run-all" : " ^4.1.3" ,
61
+ "puppeteer" : " 1.20.0" ,
61
62
"remove-markdown" : " ^0.3.0" ,
62
63
"shelljs" : " ^0.8.3" ,
63
64
"stylelint" : " ^11.0.0" ,
You can’t perform that action at this time.
0 commit comments