|
18 | 18 | // Behaves like JSON.stringify() except only for strings and outputs strings with single quotes
|
19 | 19 | // instead of double quotes.
|
20 | 20 | // 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(); |
23 | 27 | }
|
24 | 28 |
|
25 | 29 | function checkExpectations(testURL, passes, failures, expectedFailures) {
|
|
98 | 102 |
|
99 | 103 | function checkConfig(config) {
|
100 | 104 | var requiredProperties = {
|
| 105 | + target: '<String name of polyfill target being tested>', |
101 | 106 | testURLList: '<Array of test URLs>',
|
102 | 107 | 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>', |
104 | 109 | flakyTestIndicator: '<String used in expectedFailures to indicate flaky test (pass/fail)>',
|
| 110 | + withNativeFallback: '<Boolean to indicate whether the native browser fallback should be included>', |
105 | 111 | };
|
106 | 112 | var errorMessage = '';
|
107 | 113 | if (!config) {
|
|
125 | 131 | return true;
|
126 | 132 | }
|
127 | 133 |
|
| 134 | + var filteredConfigurationAttributes = ['target', 'withNativeFallback']; |
| 135 | + |
128 | 136 | // 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'; |
130 | 147 | var testURLs = Object.keys(failures);
|
131 | 148 | testURLs.sort();
|
132 |
| - return testURLs.map(function(testURL) { |
| 149 | + result += testURLs.map(function(testURL) { |
133 | 150 | var tests = Object.keys(failures[testURL]);
|
134 | 151 | tests.sort();
|
135 | 152 | return (
|
136 |
| - ' ' + stringify(testURL) + ': {\n' + |
| 153 | + ' ' + stringify(testURL) + ': {\n' + |
137 | 154 | tests.map(function(test) {
|
138 | 155 | return (
|
139 |
| - ' ' + stringify(test) + ':\n' + |
140 |
| - ' ' + stringify(failures[testURL][test]) + ',\n'); |
| 156 | + ' ' + stringify(test) + ':\n' + |
| 157 | + ' ' + stringify(failures[testURL][test]) + ',\n'); |
141 | 158 | }).join('\n') +
|
142 |
| - ' },\n'); |
| 159 | + ' },\n'); |
143 | 160 | }).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; |
144 | 185 | }
|
145 | 186 |
|
146 | 187 | function runRemainingTests(remainingTestURLs, config, testNameDiv, iframe, outputFailures) {
|
147 | 188 | if (remainingTestURLs.length == 0) {
|
148 | 189 | karma.complete();
|
149 | 190 | window.failures = outputFailures;
|
150 |
| - window.formattedFailures = formatFailures(outputFailures); |
| 191 | + window.formattedFailures = formatFailures(config, outputFailures); |
151 | 192 | return;
|
152 | 193 | }
|
153 | 194 |
|
|
167 | 208 | // parent window and call it once testharness.js has loaded.
|
168 | 209 | window.onTestharnessLoaded = function(innerWindow) {
|
169 | 210 | innerWindow.add_completion_callback(function(results) {
|
170 |
| - var expectations = config.expectedFailures[testURL]; |
| 211 | + var expectedFailures = getExpectedFailures(config, testURL); |
171 | 212 | var failures = {};
|
172 | 213 | var passes = {};
|
173 | 214 | results.forEach(function(result) {
|
174 |
| - if (expectations && expectations[result.name] == config.flakyTestIndicator) { |
| 215 | + if (expectedFailures && expectedFailures[result.name] == config.flakyTestIndicator) { |
175 | 216 | failures[result.name] = config.flakyTestIndicator;
|
176 | 217 | return;
|
177 | 218 | }
|
|
188 | 229 | outputFailures[testURL] = failures;
|
189 | 230 | }
|
190 | 231 |
|
191 |
| - karma.result(checkExpectations(testURL, passes, failures, expectations)); |
| 232 | + karma.result(checkExpectations(testURL, passes, failures, expectedFailures)); |
192 | 233 | runRemainingTests(remainingTestURLs.slice(1), config, testNameDiv, iframe, outputFailures);
|
193 | 234 | });
|
194 | 235 | };
|
|
0 commit comments