Skip to content

Commit cdc4ca8

Browse files
authored
test: include reftests previewer with docs website (#1799)
1 parent a7d8810 commit cdc4ca8

14 files changed

+385
-51
lines changed

azure-pipelines.yml

+51-19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
inputs:
3535
PathtoPublish: 'build'
3636
artifactName: build
37+
3738
- job: Test
3839
displayName: Tests
3940
pool:
@@ -54,25 +55,6 @@ jobs:
5455
displayName: Flow
5556
- script: npm run test:node
5657
displayName: Unit tests
57-
- job: Build_docs
58-
displayName: Build docs
59-
pool:
60-
vmImage: 'Ubuntu-16.04'
61-
steps:
62-
- task: NodeTool@0
63-
inputs:
64-
versionSpec: '10.x'
65-
displayName: 'Install Node.js'
66-
- task: Npm@0
67-
inputs:
68-
command: install
69-
- script: npm run build && cd www && npm install && npm run build && cd ..
70-
displayName: Build docs
71-
- task: PublishBuildArtifacts@1
72-
displayName: Upload docs website artifact
73-
inputs:
74-
PathtoPublish: 'www/public'
75-
artifactName: docs
7658

7759
- template: ci/browser-tests.yml
7860
parameters:
@@ -138,3 +120,53 @@ jobs:
138120
displayName: Windows Internet Explorer 11
139121
vmImage: 'vs2017-win2016'
140122
targetBrowser: IE_11
123+
124+
- job: Build_docs
125+
displayName: Build docs
126+
pool:
127+
vmImage: 'Ubuntu-16.04'
128+
dependsOn:
129+
- Browser_Tests_Linux_Firefox_Stable
130+
- Browser_Tests_Linux_Chrome_Stable
131+
- Browser_Tests_OSX_Safari_IOS_9
132+
- Browser_Tests_OSX_Safari_IOS_10
133+
- Browser_Tests_OSX_Safari_IOS_11
134+
- Browser_Tests_OSX_Safari_Stable
135+
- Browser_Tests_Windows_IE9
136+
- Browser_Tests_Windows_IE10
137+
- Browser_Tests_Windows_IE11
138+
steps:
139+
- task: NodeTool@0
140+
inputs:
141+
versionSpec: '10.x'
142+
displayName: 'Install Node.js'
143+
- task: Npm@0
144+
inputs:
145+
command: install
146+
- task: DownloadBuildArtifacts@0
147+
displayName: 'Download test results'
148+
inputs:
149+
artifactName: ReftestResults
150+
downloadPath: $(System.DefaultWorkingDirectory)
151+
- task: DownloadBuildArtifacts@0
152+
displayName: 'Download dist'
153+
inputs:
154+
artifactName: dist
155+
downloadPath: $(System.DefaultWorkingDirectory)
156+
- script: cp -R tests/reftests www/static/tests/reftests && cp -R tests/assets www/static/tests/assets && cp -R ReftestResults ./www/static/results
157+
displayName: Copy reftests to docs website
158+
- script: cp -R dist ./www/static/dist
159+
displayName: Copy dist to docs website
160+
- script: npm run build:reftest-result-list www/static/results/metadata www/src/results.json
161+
displayName: Create reftest result index
162+
- script: npm run build:reftest-preview
163+
displayName: Create reftest previewer
164+
- script: rm -rf www/static/results/metadata
165+
displayName: Clean metadata folder
166+
- script: npm run build && cd www && npm install && npm run build && cd ..
167+
displayName: Build docs
168+
- task: PublishBuildArtifacts@1
169+
displayName: Upload docs website artifact
170+
inputs:
171+
PathtoPublish: 'www/public'
172+
artifactName: docs

configs/base.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"noImplicitAny": true,
4+
"noImplicitThis": true,
5+
"noUnusedLocals": true,
6+
"noUnusedParameters": true,
7+
"strictNullChecks": true,
8+
"strictPropertyInitialization": true,
9+
"resolveJsonModule": true
10+
}
11+
}

configs/preview.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./base",
3+
"include": [
4+
"../www/src/preview.ts"
5+
],
6+
"exclude": [
7+
"node_modules"
8+
]
9+
}
10+

configs/scripts.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./base",
3+
"include": [
4+
"scripts/**/*.ts"
5+
],
6+
"exclude": [
7+
"node_modules"
8+
]
9+
}
10+

karma.js

+15-30
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ const filenamifyUrl = require('filenamify-url');
1616

1717
const mkdirp = require('mkdirp');
1818
const screenshotFolder = './tmp/reftests';
19+
const metadataFolder = './tmp/reftests/metadata';
1920

2021
mkdirp.sync(path.resolve(__dirname, screenshotFolder));
21-
22+
mkdirp.sync(path.resolve(__dirname, metadataFolder));
2223

2324
const CORS_PORT = 8081;
2425
const corsApp = express();
@@ -65,9 +66,10 @@ const writeScreenshot = (buffer, body) => {
6566
const filename = `${filenamifyUrl(
6667
body.test.replace(/^\/tests\/reftests\//, '').replace(/\.html$/, ''),
6768
{replacement: '-'}
68-
)}!${[process.env.TARGET_BROWSER, body.platform.name, body.platform.version].join('-')}.png`;
69+
)}!${[process.env.TARGET_BROWSER, body.platform.name, body.platform.version].join('-')}`;
6970

70-
fs.writeFileSync(path.resolve(__dirname, screenshotFolder, filename), buffer);
71+
fs.writeFileSync(path.resolve(__dirname, screenshotFolder, `${filename}.png`), buffer);
72+
return filename;
7173
};
7274

7375
app.post('/screenshot', (req, res) => {
@@ -76,33 +78,16 @@ app.post('/screenshot', (req, res) => {
7678
}
7779

7880
const buffer = new Buffer(req.body.screenshot.substring(prefix.length), 'base64');
79-
writeScreenshot(buffer, req.body);
80-
return res.sendStatus(200);
81-
});
82-
83-
const chunks = {};
84-
85-
app.post('/screenshot/chunk', (req, res) => {
86-
if (!req.body || !req.body.screenshot) {
87-
return res.sendStatus(400);
88-
}
89-
90-
const key = `${req.body.platform.name}-${req.body.platform.version}-${req.body.test
91-
.replace(/^\/tests\/reftests\//, '')
92-
.replace(/\.html$/, '')}`;
93-
if (!Array.isArray(chunks[key])) {
94-
chunks[key] = Array.from(Array(req.body.totalCount));
95-
}
96-
97-
chunks[key][req.body.part] = req.body.screenshot;
98-
99-
if (chunks[key].every(s => typeof s === 'string')) {
100-
const str = chunks[key].reduce((acc, s) => acc + s, '');
101-
const buffer = new Buffer(str.substring(prefix.length), 'base64');
102-
delete chunks[key];
103-
writeScreenshot(buffer, req.body);
104-
}
105-
81+
const filename = writeScreenshot(buffer, req.body);
82+
fs.writeFileSync(path.resolve(__dirname, metadataFolder, `${filename}.json`), JSON.stringify({
83+
windowWidth: req.body.windowWidth,
84+
windowHeight: req.body.windowHeight,
85+
platform: req.body.platform,
86+
devicePixelRatio: req.body.devicePixelRatio,
87+
test: req.body.test,
88+
id: process.env.TARGET_BROWSER,
89+
screenshot: filename
90+
}));
10691
return res.sendStatus(200);
10792
});
10893

package-lock.json

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url": "https://hertzen.com"
1313
},
1414
"engines": {
15-
"node": ">=4.0.0"
15+
"node": ">=8.0.0"
1616
},
1717
"repository": {
1818
"type": "git",
@@ -26,6 +26,7 @@
2626
"@babel/core": "^7.4.3",
2727
"@babel/preset-env": "^7.4.3",
2828
"@babel/preset-flow": "^7.0.0",
29+
"@types/node": "^11.13.2",
2930
"appium-ios-simulator": "^3.10.0",
3031
"babel-eslint": "^10.0.1",
3132
"babel-loader": "^8.0.5",
@@ -65,6 +66,9 @@
6566
"serve-index": "^1.9.1",
6667
"slash": "1.0.0",
6768
"standard-version": "^5.0.2",
69+
"ts-loader": "^5.3.3",
70+
"ts-node": "^8.0.3",
71+
"typescript": "^3.4.3",
6872
"uglifyjs-webpack-plugin": "^1.1.2",
6973
"webpack": "^4.29.6",
7074
"webpack-cli": "^3.3.0"
@@ -73,6 +77,8 @@
7377
"build": "rimraf dist/ && node scripts/create-reftest-list && npm run build:npm && npm run build:browser",
7478
"build:npm": "babel src/ -d dist/npm/ --plugins=dev-expression && replace-in-file __VERSION__ '\"$npm_package_version\"' dist/npm/index.js",
7579
"build:browser": "webpack",
80+
"build:reftest-result-list": "ts-node scripts/create-reftest-result-list.ts",
81+
"build:reftest-preview": "webpack --config www/webpack.config.js",
7682
"release": "standard-version",
7783
"rollup": "rollup -c",
7884
"format": "prettier --single-quote --no-bracket-spacing --tab-width 4 --print-width 100 --write \"{src,www/src,tests,scripts}/**/*.js\"",

scripts/create-reftest-result-list.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {readdirSync, readFileSync, writeFileSync} from 'fs';
2+
import {resolve} from 'path';
3+
4+
if (process.argv.length <= 2){
5+
console.log('No metadata path provided');
6+
process.exit(1);
7+
}
8+
9+
if (process.argv.length <= 3){
10+
console.log('No output file given');
11+
process.exit(1);
12+
}
13+
14+
const path = resolve(__dirname, '../', process.argv[2]);
15+
const files = readdirSync(path);
16+
17+
interface RefTestMetadata {
18+
19+
}
20+
21+
interface RefTestSingleMetadata extends RefTestMetadata{
22+
test: string;
23+
}
24+
25+
interface RefTestResults {
26+
[key: string]: Array<RefTestMetadata>
27+
}
28+
29+
const result: RefTestResults = files.reduce((result: RefTestResults, file) => {
30+
const json: RefTestSingleMetadata = JSON.parse(readFileSync(resolve(__dirname, path, file)).toString());
31+
if (!result[json.test]) {
32+
result[json.test] = [];
33+
}
34+
35+
result[json.test].push(json);
36+
delete json.test;
37+
38+
return result;
39+
}, {});
40+
41+
const output = resolve(__dirname, '../', process.argv[3]);
42+
writeFileSync(output, JSON.stringify(result));
43+
44+
console.log(`Wrote file ${output}`);

tests/testrunner.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,10 @@ const assertPath = (result, expected, desc) => {
369369
platform: {
370370
name: platform.name,
371371
version: platform.version
372-
}
372+
},
373+
devicePixelRatio: window.devicePixelRatio || 1,
374+
windowWidth: window.innerWidth,
375+
windowHeight: window.innerHeight
373376
}));
374377
});
375378

0 commit comments

Comments
 (0)