|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const path = require('path'); |
| 4 | +const fs = require('fs'); |
| 5 | + |
| 6 | +const karmaOutput = JSON.parse(fs.readFileSync('/tmp/karma-result.json')); |
| 7 | + |
| 8 | + |
| 9 | +let generatedBlacklist = {}; |
| 10 | +for (const desc of Object.keys(karmaOutput)) { |
| 11 | + generatedBlacklist = {...generatedBlacklist, ...getFullFailure(karmaOutput[desc], desc)}; |
| 12 | +} |
| 13 | + |
| 14 | +// We want to "remember" the notes from the current blacklist on angular/angular unless the |
| 15 | +// error message has changed. We need to know where the local angular/angular repo is. |
| 16 | +const angularRepoPath = process.argv[2]; |
| 17 | +if (!angularRepoPath) { |
| 18 | + console.error('Please provide the path to your local angular/angular repo as the first argument'); |
| 19 | + process.exit(1); |
| 20 | +} |
| 21 | + |
| 22 | +// Read the contents of the previous blacklist. |
| 23 | +const previousBlacklistPath = |
| 24 | + path.join(angularRepoPath, 'tools', 'material-ci', 'angular_material_test_blacklist.js'); |
| 25 | +const previousBlacklistContent = fs.readFileSync(previousBlacklistPath, 'utf-8'); |
| 26 | + |
| 27 | +// Because the blacklist is a javascript file meant to be executed, we just actually execute it with |
| 28 | +// eval. Create a dummy `window` for it to add to. |
| 29 | +const window = {}; |
| 30 | +eval(previousBlacklistContent); |
| 31 | +const previousBlacklist = window.testBlacklist; |
| 32 | + |
| 33 | +// Copy any existing test notes. |
| 34 | +for (const testName of Object.keys(generatedBlacklist)) { |
| 35 | + if (previousBlacklist[testName] && |
| 36 | + generatedBlacklist[testName].error === previousBlacklist[testName].error) { |
| 37 | + generatedBlacklist[testName].notes = previousBlacklist[testName].notes; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +// Format the output as an executable javascript program. |
| 42 | +const output = |
| 43 | +`/** |
| 44 | + * @license |
| 45 | + * Copyright Google Inc. All Rights Reserved. |
| 46 | + * |
| 47 | + * Use of this source code is governed by an MIT-style license that can be |
| 48 | + * found in the LICENSE file at https://angular.io/license |
| 49 | + */ |
| 50 | +
|
| 51 | +/** |
| 52 | + * Blacklist of unit tests from angular/material2 with ivy that are skipped when running on |
| 53 | + * angular/angular. As bugs are resolved, items should be removed from this blacklist. |
| 54 | + * |
| 55 | + * The \`notes\` section should be used to keep track of specific issues associated with the failures. |
| 56 | + * |
| 57 | + * TODO(jelbourn): it's not currently straightforward to regenerate this blacklist from scratch. |
| 58 | + */ |
| 59 | +
|
| 60 | +// clang-format off |
| 61 | +// tslint:disable |
| 62 | +
|
| 63 | +window.testBlacklist = ${JSON.stringify(generatedBlacklist, null, 2)}; |
| 64 | +// clang-format on`; |
| 65 | + |
| 66 | +// Write that sucker to dist. |
| 67 | +fs.writeFileSync('dist/angular_material_test_blacklist.js', output, 'utf-8'); |
| 68 | + |
| 69 | + |
| 70 | +/** |
| 71 | + * Given a karma test result, get a blacklist entry in the form |
| 72 | + * {[full test name]: {error: '...', notes: '...'}} |
| 73 | + */ |
| 74 | +function getFullFailure(result, fullName = '') { |
| 75 | + if (result['log']) { |
| 76 | + if (result['log'].length) { |
| 77 | + return {[fullName]: { |
| 78 | + error: result['log'][0].split('\n')[0], |
| 79 | + notes: 'Unknown', |
| 80 | + }}; |
| 81 | + } |
| 82 | + |
| 83 | + return {}; |
| 84 | + } |
| 85 | + |
| 86 | + let failures = {}; |
| 87 | + for (const key of Object.keys(result)) { |
| 88 | + failures = {...failures, ...getFullFailure(result[key], fullName + ' ' + key)}; |
| 89 | + } |
| 90 | + |
| 91 | + return failures; |
| 92 | +} |
0 commit comments