1- const glob = require ( ' glob' )
2- const fs = require ( 'fs' )
3- const path = require ( ' path' )
1+ const glob = require ( " glob" ) ;
2+ const fs = require ( "fs" ) ;
3+ const path = require ( " path" ) ;
44
55function slash ( path ) {
6- const isExtendedLengthPath = / ^ \\ \\ \? \\ / . test ( path ) ;
7- const hasNonAscii = / [ ^ \u0000 - \u0080 ] + / . test ( path ) ; // eslint-disable-line no-control-regex
6+ const isExtendedLengthPath = / ^ \\ \\ \? \\ / . test ( path ) ;
7+ const hasNonAscii = / [ ^ \u0000 - \u0080 ] + / . test ( path ) ; // eslint-disable-line no-control-regex
88
9- if ( isExtendedLengthPath || hasNonAscii ) {
10- return path ;
11- }
9+ if ( isExtendedLengthPath || hasNonAscii ) {
10+ return path ;
11+ }
1212
13- return path . replace ( / \\ / g, '/' ) ;
13+ return path . replace ( / \\ / g, "/" ) ;
1414}
1515
1616function get_required_sessions ( browsers ) {
17- let combinations = [ ]
18- for ( b in browsers ) {
19- for ( v in browsers [ b ] [ "versions" ] ) {
20- combinations . push ( {
21- "browser" : browsers [ b ] [ "browser" ] ,
22- "platform" : browsers [ b ] [ "platform" ] ,
23- "version" : browsers [ b ] [ "versions" ] [ v ]
24-
25- } )
26- }
17+ let combinations = [ ] ;
18+ for ( b in browsers ) {
19+ for ( v in browsers [ b ] [ "versions" ] ) {
20+ combinations . push ( {
21+ browser : browsers [ b ] [ "browser" ] ,
22+ platform : browsers [ b ] [ "platform" ] ,
23+ version : browsers [ b ] [ "versions" ] [ v ] ,
24+ } ) ;
2725 }
28- return combinations
29-
26+ }
27+ return combinations ;
3028}
31- function get_spec_files ( files ) {
32- return new Promise ( function ( resolve , reject ) {
33- let matched_files = [ ]
34- for ( i in files ) {
35- matched_files = matched_files . concat ( glob . sync ( files [ i ] ) )
36- }
37- if ( matched_files . length == 0 ) {
38- reject ( "Spec files are not present" )
39- }
40- for ( i in matched_files ) {
41- if ( ! fs . existsSync ( matched_files [ i ] ) ) {
42- reject ( "Spec files are not present" )
43- }
29+ function get_spec_files ( files , exclude_files ) {
30+ return new Promise ( function ( resolve , reject ) {
31+ let matched_files = [ ] ;
32+ let files_to_exclude = [ ] ;
33+
34+ for ( i in files ) {
35+ matched_files = matched_files . concat ( glob . sync ( files [ i ] ) ) ;
36+ }
37+ for ( i in exclude_files ) {
38+ files_to_exclude = files_to_exclude . concat ( glob . sync ( exclude_files [ i ] ) ) ;
39+ }
40+ let remaining_files = [ ] ;
41+ for ( i in matched_files ) {
42+ let deleted = false ;
43+ for ( let j = 0 ; j < files_to_exclude . length ; j ++ ) {
44+ if ( matched_files [ i ] == files_to_exclude [ j ] ) {
45+ deleted = true ;
46+ break ;
4447 }
45- resolve ( matched_files )
46- } )
48+ }
49+ if ( deleted ) {
50+ continue ;
51+ } else {
52+ remaining_files . push ( matched_files [ i ] ) ;
53+ }
54+ if ( ! fs . existsSync ( matched_files [ i ] ) ) {
55+ reject ( "Spec files are not present" ) ;
56+ }
57+ }
58+ if ( remaining_files . length == 0 ) {
59+ reject ( "Spec files are not present" ) ;
60+ }
61+ resolve ( remaining_files ) ;
62+ } ) ;
4763}
4864
4965function get_all_tests ( lt_config ) {
50- return new Promise ( function ( resolve , reject ) {
51- let browsers = get_required_sessions ( lt_config [ 'browsers' ] )
52- get_spec_files ( lt_config [ "run_settings" ] [ "specs" ] ) . then ( function ( specs ) {
53- let tests = [ ]
54- for ( let i in specs ) {
55- let relativePath = slash ( path . relative ( process . cwd ( ) , specs [ i ] ) ) ;
56- for ( let j in browsers ) {
57- tests . push ( {
58- "spec_file" : specs [ i ] ,
59- "path" : relativePath ,
60- "browser" : browsers [ j ] [ "browser" ] ,
61- "platform" : browsers [ j ] [ "platform" ] ,
62- "version" : browsers [ j ] [ "version" ]
63- } )
64- }
65- }
66- resolve ( tests )
67-
68- } ) . catch ( function ( err ) {
69- reject ( err )
70- } )
71- } )
72-
66+ return new Promise ( function ( resolve , reject ) {
67+ let browsers = get_required_sessions ( lt_config [ "browsers" ] ) ;
68+ get_spec_files (
69+ lt_config [ "run_settings" ] [ "specs" ] ,
70+ lt_config [ "run_settings" ] [ "exclude_specs" ]
71+ )
72+ . then ( function ( specs ) {
73+ let tests = [ ] ;
74+ for ( let i in specs ) {
75+ let relativePath = slash ( path . relative ( process . cwd ( ) , specs [ i ] ) ) ;
76+ for ( let j in browsers ) {
77+ tests . push ( {
78+ spec_file : specs [ i ] ,
79+ path : relativePath ,
80+ browser : browsers [ j ] [ "browser" ] ,
81+ platform : browsers [ j ] [ "platform" ] ,
82+ version : browsers [ j ] [ "version" ] ,
83+ } ) ;
84+ }
85+ }
86+ resolve ( tests ) ;
87+ } )
88+ . catch ( function ( err ) {
89+ reject ( err ) ;
90+ } ) ;
91+ } ) ;
7392}
7493
75-
7694function make_batches ( lt_config ) {
77- return new Promise ( function ( resolve , reject ) {
78- get_all_tests ( lt_config ) . then ( function ( test_suite ) {
79- parallels = lt_config [ "run_settings" ] [ "parallels" ]
80- resolve ( [ test_suite ] )
81- } ) . then ( function ( err ) {
82- console . log ( err )
83- } ) . catch ( function ( err ) {
84- console . log ( err )
85- } )
86-
87- } )
95+ return new Promise ( function ( resolve , reject ) {
96+ get_all_tests ( lt_config )
97+ . then ( function ( test_suite ) {
98+ parallels = lt_config [ "run_settings" ] [ "parallels" ] ;
99+ resolve ( [ test_suite ] ) ;
100+ } )
101+ . then ( function ( err ) {
102+ console . log ( err ) ;
103+ } )
104+ . catch ( function ( err ) {
105+ console . log ( err ) ;
106+ } ) ;
107+ } ) ;
88108}
89109
90-
91110module . exports = {
92- make_batches : make_batches
93- }
111+ make_batches : make_batches ,
112+ } ;
0 commit comments