Skip to content

Commit 3d15a2e

Browse files
authored
Add support for win32 development (#115)
* Adding Win32 tooling * Support Win32 development
1 parent 9bdb243 commit 3d15a2e

7 files changed

+80
-3
lines changed

config.bat

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@echo off
2+
rem Configure command environment variables.
3+
rem config silent [runs silently]
4+
rem config [runs "verbosely", reporting on current settings]
5+
rem Note that anything will match "silent"
6+
if "%WPT_DIR%"=="" set WPT_DIR=test\wpt
7+
if "%WPT_SERVER_PORT%"=="" set WPT_SERVER_PORT=8082
8+
if "%WPT_SERVER_ADDRESS%"=="" set WPT_SERVER_ADDRESS=127.0.0.1
9+
if "%LOCAL_BROWSER%"=="" set LOCAL_BROWSER=chrome
10+
if "%LOCAL_WEBDRIVER_BIN%"=="" set LOCAL_WEBDRIVER_BIN=c:\src\src\out\default\chromedriver.exe
11+
if NOT "%1"=="" goto END
12+
echo Configured to run tests on %LOCAL_BROWSER% at http://%WPT_SERVER_ADDRESS%:%WPT_SERVER_PORT%
13+
echo Tests will be served from %WPT_DIR% using %LOCAL_WEBDRIVER_BIN%
14+
:END

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"dev": "run-all \"serve\" \" microbundle watch -f iife \"",
1010
"deploy": "npm run build",
1111
"test:simple": "./test/setup/wpt-repo.sh && node ./test/webdriver/wpt-server-cli.js",
12-
"test:webdriver": "./test/setup/wpt-repo.sh && node test/webdriver/index.js"
12+
"test:simple-w": "test\\setup\\wpt-repo.sh.bat && node ./test/webdriver/wpt-server-cli.js",
13+
"test:webdriver": "./test/setup/wpt-repo.sh && node test/webdriver/index.js",
14+
"test:webdriver-w": "test\\setup\\wpt-repo.sh.bat && node test/webdriver/index.js"
1315
},
1416
"repository": {
1517
"type": "git",

run-server-locally.bat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@call config silent
2+
npm run test:simple-w

run-tests-locally.bat

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@call config silent
2+
npm run test:webdriver-w

test/setup/wpt-repo.sh.bat

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@echo off
2+
rem #!/bin/bash
3+
4+
rem PROJ_DIR="$(cd "$(dirname "$1")" && pwd)"
5+
6+
rem WPT_DIR="$PROJ_DIR/test/wpt"
7+
8+
rem # if directory does not exist, clone fresh-stuff from WPT master
9+
rem if [ ! -d "$WPT_DIR" ]; then
10+
rem echo "WPT folder not found, cloning from remote..."
11+
rem git clone https://github.com/web-platform-tests/wpt $WPT_DIR
12+
rem else
13+
rem # ask git to attempt to rebase our changes on top of remote
14+
rem git -C "$WPT_DIR" pull --ff-only
15+
rem fi
16+
17+
set PROJ_DIR=%CD%
18+
set WPT_DIR=%PROJ_DIR%\test\wpt
19+
20+
if exist %WPT_DIR%\. goto UPDATE_CONTENT
21+
echo dir not found. Creating
22+
echo on
23+
git clone https://github.com/web-platform-tests/wpt %WPT_DIR%
24+
@echo off
25+
goto :END
26+
27+
:UPDATE_CONTENT
28+
echo updating content
29+
echo on
30+
git -C %WPT_DIR% pull --ff-only
31+
@echo off
32+
:END

test/webdriver/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const wptServer = require("./wpt-server");
1111
const TEST_CONFIGS = require("../tests.config.json");
1212
const harnessTests = require("./harness-tests");
1313
const { resolve } = require("path");
14+
const os = require('os');
1415

1516
// Env configs
1617
const ENV = {}
@@ -155,6 +156,12 @@ async function runWebDriverTests() {
155156
}
156157

157158
for (let testFile of testFiles) {
159+
if (os.platform() === 'win32') {
160+
// Under Win32, we're using ENV.WPT_DIR as a full path
161+
// testFile is relative, so we need to map to a full path.
162+
testFile = process.cwd() + '\\'+ testFile;
163+
}
164+
158165
// convert: test/wpt/scroll-timeline/....html
159166
// to: localhost:PORT/scroll-timeline/....html
160167
let url = testFile.replace(ENV.WPT_DIR, baseURL);

test/webdriver/wpt-server.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs');
22
const http = require('http');
3+
const os = require('os');
34

45
async function wptServer(harnessTestURLs, testConfigs, env) {
56

@@ -17,23 +18,40 @@ async function wptServer(harnessTestURLs, testConfigs, env) {
1718
function handler(req, res) {
1819
let url = req.url
1920
let fileToServe = env.WPT_DIR + url
21+
let diagnostics = false;
2022
if( polyfillsSet.has(url) ) {
2123
fileToServe = process.cwd() + url
24+
if (diagnostics) {
25+
console.log("Polyfill file requested. Mapping %s to %s",
26+
url, fileToServe);
27+
}
2228
}
2329
// this is not safe to use as generic server
2430
// anyone can navigate back to serve any file on your server
2531
// outside the desired `base` but for our use, it's fine.
2632
fs.readFile(fileToServe, "utf8", (err, data) => {
2733
if (err) {
34+
if (diagnostics) console.log("Returning 404 for %s", fileToServe);
2835
res.writeHead(404, {"Content-Type": "text/plain"});
2936
res.write('404 not found');
3037
return res.end();
3138
}
39+
// win32 uses backslashes. Need to re-write the url
40+
let mangledURL = fileToServe;
41+
if (os.platform() === 'win32') {
42+
mangledURL = "test/wpt" + url;
43+
mangledURL = mangledURL.replaceAll('/', '\\');
44+
45+
if (diagnostics) {
46+
console.log("Windows hack: remap %s to %s", fileToServe, mangledURL);
47+
}
48+
}
3249

3350
res.statusCode = 200;
51+
if (diagnostics) console.log("Testing to see if %s needs a polyfill.", fileToServe);
3452
// if the URL being served is for a harness test we need to inject the polyfill
35-
if( harnessTestURLs.has(fileToServe) ) {
36-
console.log("Injecting polyfill in " + url);
53+
if( harnessTestURLs.has(mangledURL) ) {
54+
if (diagnostics) console.log("******* Injecting polyfill in " + url);
3755
data = data.replace(/(<\/.*title.*>)/gi, `$1${polyfillStr}`);
3856
}
3957
res.write(data);

0 commit comments

Comments
 (0)