1
1
"use strict" ;
2
- /* eslint-disable no-console, no-process-exit, global-require */
2
+ /* eslint-disable no-console */
3
3
const fs = require ( "fs" ) ;
4
4
const path = require ( "path" ) ;
5
- const dns = require ( "dns" ) ;
6
- const childProcess = require ( "child_process" ) ;
7
- const { EventEmitter } = require ( "events" ) ;
8
- const q = require ( "q" ) ;
9
5
const { specify } = require ( "mocha-sugar-free" ) ;
10
6
const { inBrowserContext, nodeResolverPromise } = require ( "../util.js" ) ;
11
- const requestHead = require ( "request-promise-native" ) . head ;
12
7
const jsdom = require ( "../../lib/old-api.js" ) ;
13
8
14
- const wptDir = path . resolve ( __dirname , "tests" ) ;
15
-
16
- const configPaths = {
17
- default : path . resolve ( __dirname , "wpt-config.json" ) ,
18
- toUpstream : path . resolve ( __dirname , "tuwpt-config.json" )
19
- } ;
20
-
21
- const configs = {
22
- default : require ( configPaths . default ) ,
23
- toUpstream : require ( configPaths . toUpstream )
24
- } ;
25
-
26
9
const globalPool = { maxSockets : 6 } ;
27
10
28
- module . exports = ( { toUpstream = false } = { } ) => {
11
+ module . exports = urlPrefixFactory => {
29
12
if ( inBrowserContext ( ) ) {
30
13
return ( ) => {
31
14
// TODO: browser support for running WPT
32
15
} ;
33
16
}
34
17
35
- const configType = toUpstream ? "toUpstream" : "default" ;
36
- const configPath = configPaths [ configType ] ;
37
- const config = configs [ configType ] ;
38
-
39
- const server = new EventEmitter ( ) ;
40
-
41
- let serverHasStarted ;
42
- server . started = new Promise ( resolve => {
43
- serverHasStarted = resolve ;
44
- } ) ;
45
- server . isStarted = false ;
46
-
47
- let urlPrefix = `http://${ config . host } :${ config . ports . http [ 0 ] } /` ;
48
-
49
- dns . lookup ( "web-platform.test" , err => {
50
- if ( err ) {
51
- console . warn ( ) ;
52
- console . warn ( "Host entries not present for web platform tests." ) ;
53
- console . warn ( "See https://github.com/w3c/web-platform-tests#running-the-tests" ) ;
54
-
55
- if ( ! toUpstream ) {
56
- console . warn ( "Falling back to hosted versions at w3c-test.org" ) ;
57
- urlPrefix = "http://w3c-test.org/" ;
58
- }
59
- serverHasStarted ( ) ;
60
- return ;
61
- }
62
-
63
- const configArg = path . relative ( path . resolve ( wptDir ) , configPath ) ;
64
- const args = [ "./wpt.py" , "serve" , "--config" , configArg ] ;
65
- const python = childProcess . spawn ( "python" , args , {
66
- cwd : wptDir ,
67
- stdio : "inherit"
68
- } ) ;
69
-
70
- python . on ( "error" , e => {
71
- console . warn ( ) ;
72
- console . warn ( "Error starting python server process:" , e . message ) ;
73
-
74
- if ( toUpstream ) {
75
- console . error ( "Cannot proceed with running the tests." ) ;
76
- process . exit ( 1 ) ;
77
- } else {
78
- console . warn ( "Falling back to hosted versions at w3ctest.org" ) ;
79
- urlPrefix = "http://w3c-test.org/" ;
80
- serverHasStarted ( ) ;
81
- }
82
- } ) ;
83
-
84
- pollForServer ( ( ) => urlPrefix ) . then ( serverHasStarted ) ;
85
-
86
- process . on ( "exit" , ( ) => {
87
- // Python doesn't register a default handler for SIGTERM and it doesn't run __exit__() methods of context managers
88
- // when it gets that signal. Using SIGINT avoids this problem
89
- python . kill ( "SIGINT" ) ;
90
- } ) ;
91
- } ) ;
92
-
93
18
return ( testPath , title = testPath ) => {
94
19
specify ( {
95
20
title,
@@ -99,22 +24,12 @@ module.exports = ({ toUpstream = false } = {}) => {
99
24
slow : 10000 ,
100
25
skipIfBrowser : true ,
101
26
fn ( ) {
102
- return server . started . then ( ( ) => createJSDOM ( urlPrefix , testPath ) ) ;
27
+ return createJSDOM ( urlPrefixFactory ( ) , testPath ) ;
103
28
}
104
29
} ) ;
105
30
} ;
106
31
} ;
107
32
108
- function pollForServer ( urlGetter ) {
109
- console . log ( "Checking if the web platform tests server is up" ) ;
110
- return requestHead ( urlGetter ( ) )
111
- . then ( ( ) => console . log ( "Server is up!" ) )
112
- . catch ( err => {
113
- console . log ( `Server is not up yet (${ err . message } ); trying again` ) ;
114
- return q . delay ( 500 ) . then ( ( ) => pollForServer ( urlGetter ) ) ;
115
- } ) ;
116
- }
117
-
118
33
function createJSDOM ( urlPrefix , testPath ) {
119
34
const reporterPathname = "/resources/testharnessreport.js" ;
120
35
const unhandledExceptions = [ ] ;
0 commit comments