Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit c576378

Browse files
authored
Merge pull request web-animations#127 from alancutter/testEVERYTHINGAAAA
Add testing support for toggling native fallback and configuration specific failure expectations
2 parents ef2aa01 + 939ec79 commit c576378

File tree

4 files changed

+2340
-939
lines changed

4 files changed

+2340
-939
lines changed

Gruntfile.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ module.exports = function(grunt) {
206206
}
207207

208208
function filterTests(testFiles) {
209+
console.assert(testFiles.length > 0);
209210
if (!testFilter) {
210211
return testFiles;
211212
}
@@ -226,18 +227,20 @@ module.exports = function(grunt) {
226227
karmaConfig.files = ['test/karma-mocha-setup.js'].concat(config.src, testFiles);
227228
});
228229
}
229-
function runWebPlatformTests() {
230+
function runWebPlatformTests(withNativeFallback) {
230231
var testFiles = filterTests(grunt.file.expand(config.webPlatformTests));
231232
if (testFiles.length == 0) {
232233
return Promise.resolve(true);
233234
}
234235

235-
console.info('Running web-platform-tests/web-animations tests...');
236+
var withOrWithout = withNativeFallback ? 'with' : 'without';
237+
console.info('Running web-platform-tests/web-animations tests for target ' + task.target + ' ' + withOrWithout + ' native fallback...');
236238
return runKarma(function(karmaConfig) {
237239
configCallback(karmaConfig);
238240
karmaConfig.client.testharnessTests = require('./test/web-platform-tests-expectations.js');
239241
karmaConfig.client.testharnessTests.testURLList = testFiles;
240-
karmaConfig.proxies['/base/polyfill.js'] = '/base/' + task.target + '.min.js';
242+
karmaConfig.client.testharnessTests.target = task.target;
243+
karmaConfig.client.testharnessTests.withNativeFallback = withNativeFallback;
241244
karmaConfig.files.push('test/karma-testharness-adapter.js');
242245
var servedFiles = [
243246
'test/web-platform-tests/resources/**',
@@ -256,10 +259,15 @@ module.exports = function(grunt) {
256259
}
257260

258261
var polyfillTestsPassed = false;
262+
var webPlatformTestsWithFallbackPassed = false;
263+
var webPlatformTestsWithoutFallbackPassed = false;
259264
runPolyfillTests().then(success => {
260265
polyfillTestsPassed = success;
261-
}).then(runWebPlatformTests).then(webPlatformTestsPassed => {
262-
done(polyfillTestsPassed && webPlatformTestsPassed);
266+
}).then(() => runWebPlatformTests(true)).then(success => {
267+
webPlatformTestsWithFallbackPassed = success;
268+
}).then(() => runWebPlatformTests(false)).then(success => {
269+
webPlatformTestsWithoutFallbackPassed = success;
270+
done(polyfillTestsPassed && webPlatformTestsWithFallbackPassed && webPlatformTestsWithoutFallbackPassed);
263271
}).catch(function(error) {
264272
console.error(error);
265273
done(false);

test/karma-testharness-adapter.js

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
// Behaves like JSON.stringify() except only for strings and outputs strings with single quotes
1919
// instead of double quotes.
2020
// This so we can paste test results as expectations while keeping our linter happy.
21-
function stringify(string) {
22-
return '\'' + string.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/'/g, '\\\'') + '\'';
21+
function stringify(x) {
22+
if (typeof x == 'string') {
23+
return '\'' + x.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/'/g, '\\\'') + '\'';
24+
}
25+
console.assert(typeof x != 'object');
26+
return x.toString();
2327
}
2428

2529
function checkExpectations(testURL, passes, failures, expectedFailures) {
@@ -98,10 +102,12 @@
98102

99103
function checkConfig(config) {
100104
var requiredProperties = {
105+
target: '<String name of polyfill target being tested>',
101106
testURLList: '<Array of test URLs>',
102107
skip: '<Object mapping skipped test URLs to the reason for skipping>',
103-
expectedFailures: '<Object mapping test URLs to expected inner test failures>',
108+
failureConfigurations: '<Array of objects mapping test configuration to test URLs to expected inner test failures>',
104109
flakyTestIndicator: '<String used in expectedFailures to indicate flaky test (pass/fail)>',
110+
withNativeFallback: '<Boolean to indicate whether the native browser fallback should be included>',
105111
};
106112
var errorMessage = '';
107113
if (!config) {
@@ -125,29 +131,64 @@
125131
return true;
126132
}
127133

134+
var filteredConfigurationAttributes = ['target', 'withNativeFallback'];
135+
128136
// Serialises the failures suitable for pasting into expectedFailures: {} in web-platform-tests-expectations.js
129-
function formatFailures(failures) {
137+
function formatFailures(config, failures) {
138+
var result = ' {\n';
139+
140+
result += ' configuration: {\n';
141+
filteredConfigurationAttributes.forEach(function(attribute) {
142+
result += ' ' + attribute + ': ' + stringify(config[attribute]) + ',\n';
143+
});
144+
result += ' },\n';
145+
146+
result += ' failures: {\n';
130147
var testURLs = Object.keys(failures);
131148
testURLs.sort();
132-
return testURLs.map(function(testURL) {
149+
result += testURLs.map(function(testURL) {
133150
var tests = Object.keys(failures[testURL]);
134151
tests.sort();
135152
return (
136-
' ' + stringify(testURL) + ': {\n' +
153+
' ' + stringify(testURL) + ': {\n' +
137154
tests.map(function(test) {
138155
return (
139-
' ' + stringify(test) + ':\n' +
140-
' ' + stringify(failures[testURL][test]) + ',\n');
156+
' ' + stringify(test) + ':\n' +
157+
' ' + stringify(failures[testURL][test]) + ',\n');
141158
}).join('\n') +
142-
' },\n');
159+
' },\n');
143160
}).join('\n');
161+
result += ' },\n';
162+
163+
result += ' },\n';
164+
return result;
165+
}
166+
167+
function getExpectedFailures(config, testURL) {
168+
var result = {};
169+
config.failureConfigurations.forEach(function(failureConfiguration) {
170+
var configFilter = failureConfiguration.configuration;
171+
var filterMatches = filteredConfigurationAttributes.every(function(attribute) {
172+
console.assert(attribute in config);
173+
console.assert(attribute in configFilter);
174+
return configFilter[attribute] == null || config[attribute] == configFilter[attribute];
175+
});
176+
if (!filterMatches) {
177+
return;
178+
}
179+
var testURLFailures = failureConfiguration.failures[testURL] || [];
180+
for (var testName in testURLFailures) {
181+
result[testName] = testURLFailures[testName];
182+
}
183+
});
184+
return result;
144185
}
145186

146187
function runRemainingTests(remainingTestURLs, config, testNameDiv, iframe, outputFailures) {
147188
if (remainingTestURLs.length == 0) {
148189
karma.complete();
149190
window.failures = outputFailures;
150-
window.formattedFailures = formatFailures(outputFailures);
191+
window.formattedFailures = formatFailures(config, outputFailures);
151192
return;
152193
}
153194

@@ -167,11 +208,11 @@
167208
// parent window and call it once testharness.js has loaded.
168209
window.onTestharnessLoaded = function(innerWindow) {
169210
innerWindow.add_completion_callback(function(results) {
170-
var expectations = config.expectedFailures[testURL];
211+
var expectedFailures = getExpectedFailures(config, testURL);
171212
var failures = {};
172213
var passes = {};
173214
results.forEach(function(result) {
174-
if (expectations && expectations[result.name] == config.flakyTestIndicator) {
215+
if (expectedFailures && expectedFailures[result.name] == config.flakyTestIndicator) {
175216
failures[result.name] = config.flakyTestIndicator;
176217
return;
177218
}
@@ -188,7 +229,7 @@
188229
outputFailures[testURL] = failures;
189230
}
190231

191-
karma.result(checkExpectations(testURL, passes, failures, expectations));
232+
karma.result(checkExpectations(testURL, passes, failures, expectedFailures));
192233
runRemainingTests(remainingTestURLs.slice(1), config, testNameDiv, iframe, outputFailures);
193234
});
194235
};

test/resources/testharnessreport.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,14 @@ function dump_test_results(tests, status) {
407407

408408
/* BEGIN WEB ANIMATIONS POLYFILL EXTRAS */
409409

410-
// Disable native Web Animations fallback.
411-
// TODO(alancutter): Make this configurable in testing targets.
412-
Element.prototype.animate = null;
413-
414-
// The path /base/polyfill.js is expected to be a proxy for the appropriate polyfill script configured in Karma.
415-
document.write('<script src="/base/polyfill.js"></script>');
416-
if (window.parent && parent.window.onTestharnessLoaded) {
417-
parent.window.onTestharnessLoaded(window);
418-
} else {
419-
metadata_generator.setup();
410+
// This must be run under a Karma server via "grunt test".
411+
var config = window.parent.__karma__.config.testharnessTests;
412+
if (!config.withNativeFallback) {
413+
// Disable native Web Animations fallback.
414+
Element.prototype.animate = null;
420415
}
416+
document.write('<script src="/base/' + config.target + '.min.js"></script>');
417+
parent.window.onTestharnessLoaded(window);
421418

422419
/* END WEB ANIMATIONS POLYFILL EXTRAS */
423420

0 commit comments

Comments
 (0)