@@ -19,6 +19,9 @@ function createSandbox(setupScripts) {
19
19
// eslint-disable-next-line global-require
20
20
return require ( p ) ;
21
21
}
22
+ if ( p . startsWith ( "../implementations/" ) ) {
23
+ return class Stub { } ;
24
+ }
22
25
23
26
const resolved = path . resolve ( __dirname , "../output" , p ) ;
24
27
const src = readFileSync ( resolved , { encoding : "utf8" } ) ;
@@ -34,15 +37,7 @@ function createSandbox(setupScripts) {
34
37
return sandbox ;
35
38
}
36
39
37
- async function testInterface ( name , setupScripts ) {
38
- const idlToTest = await fs . readFile (
39
- path . join ( __dirname , `../cases/${ name } .webidl` ) ,
40
- {
41
- encoding : "utf8"
42
- }
43
- ) ;
44
-
45
- const sandbox = createSandbox ( setupScripts ) ;
40
+ async function prepareInterface ( { name, content } , idlArray , sandbox ) {
46
41
vm . runInContext (
47
42
`
48
43
Object.defineProperty(self, '${ name } ', {
@@ -54,47 +49,7 @@ async function testInterface(name, setupScripts) {
54
49
sandbox
55
50
) ;
56
51
57
- const prom = new Promise ( ( resolve , reject ) => {
58
- const errors = [ ] ;
59
-
60
- sandbox . add_result_callback ( test => {
61
- if ( test . status === 1 ) {
62
- errors . push (
63
- `Failed in "${ test . name } ": \n${ test . message } \n\n${ test . stack } `
64
- ) ;
65
- } else if ( test . status === 2 ) {
66
- errors . push (
67
- `Timeout in "${ test . name } ": \n${ test . message } \n\n${ test . stack } `
68
- ) ;
69
- } else if ( test . status === 3 ) {
70
- errors . push (
71
- `Uncompleted test "${ test . name } ": \n${ test . message } \n\n${ test . stack } `
72
- ) ;
73
- }
74
- } ) ;
75
-
76
- sandbox . add_completion_callback ( ( tests , harnessStatus ) => {
77
- if ( harnessStatus . status === 2 ) {
78
- errors . push ( new Error ( `test harness should not timeout` ) ) ;
79
- }
80
-
81
- if ( errors . length === 1 ) {
82
- reject ( new Error ( errors [ 0 ] ) ) ;
83
- } else if ( errors . length ) {
84
- reject (
85
- new Error ( `${ errors . length } errors in test:\n\n${ errors . join ( "\n" ) } ` )
86
- ) ;
87
- } else {
88
- resolve ( ) ;
89
- }
90
- } ) ;
91
- } ) ;
92
-
93
- const idlArray = new sandbox . IdlArray ( ) ;
94
- idlArray . add_idls ( idlToTest ) ;
95
-
96
- idlArray . test ( ) ;
97
- await prom ;
52
+ idlArray . add_idls ( content ) ;
98
53
}
99
54
100
55
describe ( "IDL Harness" , ( ) => {
@@ -114,7 +69,67 @@ describe("IDL Harness", () => {
114
69
) ;
115
70
} ) ;
116
71
117
- test ( "URL.js" , async ( ) => {
118
- await testInterface ( "URL" , setupScripts ) ;
72
+ const files = [ "URL" , "Unscopable" ] ;
73
+ test ( `IDLHarness.js` , async ( ) => {
74
+ const idlSources = await Promise . all (
75
+ files . map ( async f => ( {
76
+ name : f . replace ( / \. w e b i d l $ / , "" ) ,
77
+ content : await fs . readFile (
78
+ path . join ( __dirname , `../cases/${ f } .webidl` ) ,
79
+ {
80
+ encoding : "utf8"
81
+ }
82
+ )
83
+ } ) )
84
+ ) ;
85
+ const sandbox = createSandbox ( setupScripts ) ;
86
+
87
+ const idlArray = new sandbox . IdlArray ( ) ;
88
+ idlSources . forEach ( source => {
89
+ prepareInterface ( source , idlArray , sandbox ) ;
90
+ } ) ;
91
+
92
+ const prom = new Promise ( ( resolve , reject ) => {
93
+ const errors = [ ] ;
94
+
95
+ sandbox . add_result_callback ( test => {
96
+ if ( test . status === 1 ) {
97
+ errors . push (
98
+ `Failed in "${ test . name } ": \n${ test . message } \n\n${ test . stack } `
99
+ ) ;
100
+ } else if ( test . status === 2 ) {
101
+ errors . push (
102
+ `Timeout in "${ test . name } ": \n${ test . message } \n\n${ test . stack } `
103
+ ) ;
104
+ } else if ( test . status === 3 ) {
105
+ errors . push (
106
+ `Uncompleted test "${ test . name } ": \n${ test . message } \n\n${
107
+ test . stack
108
+ } `
109
+ ) ;
110
+ }
111
+ } ) ;
112
+
113
+ sandbox . add_completion_callback ( ( tests , harnessStatus ) => {
114
+ if ( harnessStatus . status === 2 ) {
115
+ errors . push ( new Error ( `test harness should not timeout` ) ) ;
116
+ }
117
+
118
+ if ( errors . length === 1 ) {
119
+ reject ( new Error ( errors [ 0 ] ) ) ;
120
+ } else if ( errors . length ) {
121
+ reject (
122
+ new Error (
123
+ `${ errors . length } errors in test:\n\n${ errors . join ( "\n" ) } `
124
+ )
125
+ ) ;
126
+ } else {
127
+ resolve ( ) ;
128
+ }
129
+ } ) ;
130
+ } ) ;
131
+
132
+ idlArray . test ( ) ;
133
+ await prom ;
119
134
} ) ;
120
135
} ) ;
0 commit comments