@@ -5,51 +5,12 @@ const path = require('path');
5
5
const fs = require ( 'fs' ) ;
6
6
const chromeless = new Chromeless ( ) ;
7
7
8
+ const allGpuModes = [ 'ForceCPU' , 'ForceGPU' , 'Automatic' ] ;
9
+
8
10
const indexHTML = path . resolve ( __dirname , 'index.html' ) ;
9
11
const testDir = ( ...args ) => path . resolve ( __dirname , 'scratch-tests' , ...args ) ;
10
12
11
- const testFile = file => test ( file , async t => {
12
- // start each test by going to the index.html, and loading the scratch file
13
- const says = await chromeless . goto ( `file://${ indexHTML } ` )
14
- . setFileInput ( '#file' , testDir ( file ) )
15
- // the index.html handler for file input will add a #loaded element when it
16
- // finishes.
17
- . wait ( '#loaded' )
18
- . evaluate ( ( ) => {
19
- // This function is run INSIDE the integration chrome browser via some
20
- // injection and .toString() magic. We can return some "simple data"
21
- // back across as a promise, so we will just log all the says that happen
22
- // for parsing after.
23
-
24
- // this becomes the `says` in the outer scope
25
- const messages = [ ] ;
26
- const TIMEOUT = 5000 ;
27
-
28
- vm . runtime . on ( 'SAY' , ( _ , __ , message ) => {
29
- messages . push ( message ) ;
30
- } ) ;
31
-
32
- vm . greenFlag ( ) ;
33
- const startTime = Date . now ( ) ;
34
-
35
- return Promise . resolve ( )
36
- . then ( async ( ) => {
37
- // waiting for all threads to complete, then we return
38
- while ( vm . runtime . threads . some ( thread => vm . runtime . isActiveThread ( thread ) ) ) {
39
- if ( ( Date . now ( ) - startTime ) >= TIMEOUT ) {
40
- // if we push the message after end, the failure from tap is not very useful:
41
- // "not ok test after end() was called"
42
- messages . unshift ( `fail Threads still running after ${ TIMEOUT } ms` ) ;
43
- break ;
44
- }
45
-
46
- await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
47
- }
48
-
49
- return messages ;
50
- } ) ;
51
- } ) ;
52
-
13
+ const checkOneGpuMode = ( t , says ) => {
53
14
// Map string messages to tap reporting methods. This will be used
54
15
// with events from scratch's runtime emitted on block instructions.
55
16
let didPlan = false ;
@@ -99,7 +60,57 @@ const testFile = file => test(file, async t => {
99
60
t . fail ( 'did not say "end"' ) ;
100
61
t . end ( ) ;
101
62
}
102
- } ) ;
63
+ } ;
64
+
65
+ const testFile = async file => {
66
+ // start each test by going to the index.html, and loading the scratch file
67
+ const says = await chromeless . goto ( `file://${ indexHTML } ` )
68
+ . setFileInput ( '#file' , testDir ( file ) )
69
+ // the index.html handler for file input will add a #loaded element when it
70
+ // finishes.
71
+ . wait ( '#loaded' )
72
+ . evaluate ( async useGpuModes => {
73
+ // This function is run INSIDE the integration chrome browser via some
74
+ // injection and .toString() magic. We can return some "simple data"
75
+ // back across as a promise, so we will just log all the says that happen
76
+ // for parsing after.
77
+
78
+ // this becomes the `says` in the outer scope
79
+ const allMessages = { } ;
80
+ const TIMEOUT = 5000 ;
81
+
82
+ vm . runtime . on ( 'SAY' , ( _ , __ , message ) => {
83
+ const messages = allMessages [ vm . renderer . _useGpuMode ] ;
84
+ messages . push ( message ) ;
85
+ } ) ;
86
+
87
+ for ( const useGpuMode of useGpuModes ) {
88
+ const messages = allMessages [ useGpuMode ] = [ ] ;
89
+
90
+ vm . renderer . setUseGpuMode ( useGpuMode ) ;
91
+ vm . greenFlag ( ) ;
92
+ const startTime = Date . now ( ) ;
93
+
94
+ // wait for all threads to complete before moving on to the next mode
95
+ while ( vm . runtime . threads . some ( thread => vm . runtime . isActiveThread ( thread ) ) ) {
96
+ if ( ( Date . now ( ) - startTime ) >= TIMEOUT ) {
97
+ // if we push the message after end, the failure from tap is not very useful:
98
+ // "not ok test after end() was called"
99
+ messages . unshift ( `fail Threads still running after ${ TIMEOUT } ms` ) ;
100
+ break ;
101
+ }
102
+
103
+ await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
104
+ }
105
+ }
106
+
107
+ return allMessages ;
108
+ } , allGpuModes ) ;
109
+
110
+ for ( const gpuMode of allGpuModes ) {
111
+ test ( `File: ${ file } , GPU Mode: ${ gpuMode } ` , t => checkOneGpuMode ( t , says [ gpuMode ] ) ) ;
112
+ }
113
+ } ;
103
114
104
115
const testBubbles = ( ) => test ( 'bubble snapshot' , async t => {
105
116
const bubbleSvg = await chromeless . goto ( `file://${ indexHTML } ` )
0 commit comments