Skip to content

Commit

Permalink
Merge branch 'master' into task/onboarding-ux-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Jul 9, 2020
2 parents bf532c1 + 269c62a commit 65a2248
Show file tree
Hide file tree
Showing 396 changed files with 6,355 additions and 1,808 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export function MochaReporterProvider({ getService }) {
let originalLogWriters;
let reporterCaptureStartTime;

const failuresOverTime = [];

return class MochaReporter extends Mocha.reporters.Base {
constructor(runner, options) {
super(runner, options);
Expand Down Expand Up @@ -154,30 +156,50 @@ export function MochaReporterProvider({ getService }) {
// - I started by trying to extract the Base.list() logic from mocha
// but it's a lot more complicated than this is horrible.
// - In order to fix the numbering and indentation we monkey-patch
// console.log and parse the logged output.
// Mocha.reporters.Base.consoleLog and parse the logged output.
//
let output = '';
const realLog = console.log;
console.log = (...args) => (output += `${format(...args)}\n`);
const realLog = Mocha.reporters.Base.consoleLog;
Mocha.reporters.Base.consoleLog = (...args) => (output += `${format(...args)}\n`);
try {
Mocha.reporters.Base.list([runnable]);
} finally {
console.log = realLog;
Mocha.reporters.Base.consoleLog = realLog;
}

const outputLines = output.split('\n');

const errorMarkerStart = outputLines.reduce((index, line, i) => {
if (index >= 0) {
return index;
}
return /Error:/.test(line) ? i : index;
}, -1);

const errorMessage = outputLines
// drop the first ${errorMarkerStart} lines, (empty + test title)
.slice(errorMarkerStart)
// move leading colors behind leading spaces
.map((line) => line.replace(/^((?:\[.+m)+)(\s+)/, '$2$1'))
.map((line) => ` ${line}`)
.join('\n');

log.write(
`- ${colors.fail(`${symbols.err} fail: "${runnable.fullTitle()}"`)}` +
'\n' +
output
.split('\n')
// drop the first two lines, (empty + test title)
.slice(2)
// move leading colors behind leading spaces
.map((line) => line.replace(/^((?:\[.+m)+)(\s+)/, '$2$1'))
.map((line) => ` ${line}`)
.join('\n')
`- ${colors.fail(`${symbols.err} fail: ${runnable.fullTitle()}`)}` + '\n' + errorMessage
);

// Prefer to reuse the nice Mocha nested title format for final summary
const nestedTitleFormat = outputLines
.slice(1, errorMarkerStart)
.join('\n')
// make sure to remove the list number
.replace(/\d+\)/, '');

failuresOverTime.push({
title: nestedTitleFormat,
error: errorMessage,
});

// failed hooks trigger the `onFail(runnable)` callback, so we snapshot the logs for
// them here. Tests will re-capture the snapshot in `onTestEnd()`
snapshotLogsForRunnable(runnable);
Expand All @@ -188,7 +210,7 @@ export function MochaReporterProvider({ getService }) {
log.setWriters(originalLogWriters);
}

writeEpilogue(log, this.stats);
writeEpilogue(log, this.stats, failuresOverTime);
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import * as colors from './colors';
import { ms } from './ms';

export function writeEpilogue(log, stats) {
export function writeEpilogue(log, stats, failuresDetail) {
// header
log.write('');

Expand All @@ -35,6 +35,12 @@ export function writeEpilogue(log, stats) {
// failures
if (stats.failures) {
log.write('%d failing', stats.failures);
log.write('');
failuresDetail.forEach(({ title, error }, i) => {
log.write('%d) %s', i + 1, title);
log.write('');
log.write('%s', error);
});
}

// footer
Expand Down
4 changes: 3 additions & 1 deletion src/core/public/application/scoped_history.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const createMock = ({
hash = '',
key,
state,
}: Partial<Location> = {}) => {
...overrides
}: Partial<Location & ScopedHistoryMock> = {}) => {
const mock: ScopedHistoryMock = {
block: jest.fn(),
createHref: jest.fn(),
Expand All @@ -38,6 +39,7 @@ const createMock = ({
listen: jest.fn(),
push: jest.fn(),
replace: jest.fn(),
...overrides,
action: 'PUSH',
length: 1,
location: {
Expand Down
3 changes: 1 addition & 2 deletions src/dev/i18n/integrate_locale_files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { mockMakeDirAsync, mockWriteFileAsync } from './integrate_locale_files.t

import path from 'path';
import { integrateLocaleFiles, verifyMessages } from './integrate_locale_files';
// @ts-expect-error
// @ts-ignore
import { normalizePath } from './utils';

const localePath = path.resolve(__dirname, '__fixtures__', 'integrate_locale_files', 'fr.json');
Expand All @@ -36,7 +36,6 @@ const defaultIntegrateOptions = {
sourceFileName: localePath,
dryRun: false,
ignoreIncompatible: false,
ignoreMalformed: false,
ignoreMissing: false,
ignoreUnused: false,
config: {
Expand Down
21 changes: 1 addition & 20 deletions src/dev/i18n/integrate_locale_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import {
normalizePath,
readFileAsync,
writeFileAsync,
verifyICUMessage,
// @ts-expect-error
// @ts-ignore
} from './utils';

import { I18nConfig } from './config';
Expand All @@ -42,7 +41,6 @@ export interface IntegrateOptions {
sourceFileName: string;
targetFileName?: string;
dryRun: boolean;
ignoreMalformed: boolean;
ignoreIncompatible: boolean;
ignoreUnused: boolean;
ignoreMissing: boolean;
Expand Down Expand Up @@ -107,23 +105,6 @@ export function verifyMessages(
}
}

for (const messageId of localizedMessagesIds) {
const defaultMessage = defaultMessagesMap.get(messageId);
if (defaultMessage) {
try {
const message = localizedMessagesMap.get(messageId)!;
verifyICUMessage(message);
} catch (err) {
if (options.ignoreMalformed) {
localizedMessagesMap.delete(messageId);
options.log.warning(`Malformed translation ignored (${messageId}): ${err}`);
} else {
errorMessage += `\nMalformed translation (${messageId}): ${err}\n`;
}
}
}
}

if (errorMessage) {
throw createFailError(errorMessage);
}
Expand Down
4 changes: 1 addition & 3 deletions src/dev/i18n/tasks/check_compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import { integrateLocaleFiles, I18nConfig } from '..';

export interface I18nFlags {
fix: boolean;
ignoreMalformed: boolean;
ignoreIncompatible: boolean;
ignoreUnused: boolean;
ignoreMissing: boolean;
}

export function checkCompatibility(config: I18nConfig, flags: I18nFlags, log: ToolingLog) {
const { fix, ignoreIncompatible, ignoreUnused, ignoreMalformed, ignoreMissing } = flags;
const { fix, ignoreIncompatible, ignoreUnused, ignoreMissing } = flags;
return config.translations.map((translationsPath) => ({
task: async ({ messages }: { messages: Map<string, { message: string }> }) => {
// If `fix` is set we should try apply all possible fixes and override translations file.
Expand All @@ -38,7 +37,6 @@ export function checkCompatibility(config: I18nConfig, flags: I18nFlags, log: To
ignoreIncompatible: fix || ignoreIncompatible,
ignoreUnused: fix || ignoreUnused,
ignoreMissing: fix || ignoreMissing,
ignoreMalformed: fix || ignoreMalformed,
sourceFileName: translationsPath,
targetFileName: fix ? translationsPath : undefined,
config,
Expand Down
22 changes: 0 additions & 22 deletions src/dev/i18n/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,28 +208,6 @@ export function checkValuesProperty(prefixedValuesKeys, defaultMessage, messageI
}
}

/**
* Verifies valid ICU message.
* @param message ICU message.
* @param messageId ICU message id
* @returns {undefined}
*/
export function verifyICUMessage(message) {
try {
parser.parse(message);
} catch (error) {
if (error.name === 'SyntaxError') {
const errorWithContext = createParserErrorMessage(message, {
loc: {
line: error.location.start.line,
column: error.location.start.column - 1,
},
message: error.message,
});
throw errorWithContext;
}
}
}
/**
* Extracts value references from the ICU message.
* @param message ICU message.
Expand Down
5 changes: 1 addition & 4 deletions src/dev/run_i18n_check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ run(
async ({
flags: {
'ignore-incompatible': ignoreIncompatible,
'ignore-malformed': ignoreMalformed,
'ignore-missing': ignoreMissing,
'ignore-unused': ignoreUnused,
'include-config': includeConfig,
Expand All @@ -49,13 +48,12 @@ run(
fix &&
(ignoreIncompatible !== undefined ||
ignoreUnused !== undefined ||
ignoreMalformed !== undefined ||
ignoreMissing !== undefined)
) {
throw createFailError(
`${chalk.white.bgRed(
' I18N ERROR '
)} none of the --ignore-incompatible, --ignore-malformed, --ignore-unused or --ignore-missing is allowed when --fix is set.`
)} none of the --ignore-incompatible, --ignore-unused or --ignore-missing is allowed when --fix is set.`
);
}

Expand Down Expand Up @@ -101,7 +99,6 @@ run(
checkCompatibility(
config,
{
ignoreMalformed: !!ignoreMalformed,
ignoreIncompatible: !!ignoreIncompatible,
ignoreUnused: !!ignoreUnused,
ignoreMissing: !!ignoreMissing,
Expand Down
5 changes: 1 addition & 4 deletions src/dev/run_i18n_integrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ run(
'ignore-incompatible': ignoreIncompatible = false,
'ignore-missing': ignoreMissing = false,
'ignore-unused': ignoreUnused = false,
'ignore-malformed': ignoreMalformed = false,
'include-config': includeConfig,
path,
source,
Expand Down Expand Up @@ -67,13 +66,12 @@ run(
typeof ignoreIncompatible !== 'boolean' ||
typeof ignoreUnused !== 'boolean' ||
typeof ignoreMissing !== 'boolean' ||
typeof ignoreMalformed !== 'boolean' ||
typeof dryRun !== 'boolean'
) {
throw createFailError(
`${chalk.white.bgRed(
' I18N ERROR '
)} --ignore-incompatible, --ignore-unused, --ignore-malformed, --ignore-missing, and --dry-run can't have values`
)} --ignore-incompatible, --ignore-unused, --ignore-missing, and --dry-run can't have values`
);
}

Expand All @@ -99,7 +97,6 @@ run(
ignoreIncompatible,
ignoreUnused,
ignoreMissing,
ignoreMalformed,
config,
log,
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/charts/public/services/colors/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ const colors = new ColorsService();
colors.init(coreMock.createSetup().uiSettings);

export const colorsServiceMock: ColorsService = {
createColorLookupFunction: jest.fn(colors.createColorLookupFunction),
createColorLookupFunction: jest.fn(colors.createColorLookupFunction.bind(colors)),
} as any;
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ function decorateFlattenedWrapper(hit: Record<string, any>, metaFields: Record<s
// unwrap computed fields
_.forOwn(hit.fields, function (val, key: any) {
if (key[0] === '_' && !_.includes(metaFields, key)) return;
flattened[key] = Array.isArray(val) && val.length === 1 ? val[0] : val;
// Flatten an array with 0 or 1 elements to a single value.
if (Array.isArray(val) && val.length <= 1) {
flattened[key] = val[0];
} else {
flattened[key] = val;
}
});

return flattened;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ export function generateFilters(
// exists filter special case: fieldname = '_exists' and value = fieldname
const filterType = fieldName === '_exists_' ? FILTERS.EXISTS : FILTERS.PHRASE;
const actualFieldObj = fieldName === '_exists_' ? ({ name: value } as IFieldType) : fieldObj;

// Fix for #7189 - if value is empty, phrase filters become exists filters.
const isNullFilter = value === null || value === undefined;

filter = buildFilter(
tmpIndexPattern,
actualFieldObj,
filterType,
negate,
isNullFilter ? FILTERS.EXISTS : filterType,
isNullFilter ? !negate : negate,
false,
value,
null,
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/public/ui/filter_bar/filter_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ export function FilterItem(props: Props) {
const dataTestSubjValue = filter.meta.value
? `filter-value-${isValidLabel(labelConfig) ? labelConfig.title : labelConfig.status}`
: '';
const dataTestSubjNegated = filter.meta.negate ? 'filter-negated' : '';
const dataTestSubjDisabled = `filter-${isDisabled(labelConfig) ? 'disabled' : 'enabled'}`;
const dataTestSubjPinned = `filter-${isFilterPinned(filter) ? 'pinned' : 'unpinned'}`;
return `filter ${dataTestSubjDisabled} ${dataTestSubjKey} ${dataTestSubjValue} ${dataTestSubjPinned}`;
return `filter ${dataTestSubjDisabled} ${dataTestSubjKey} ${dataTestSubjValue} ${dataTestSubjPinned} ${dataTestSubjNegated}`;
}

function getPanels() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ export function createTableRowDirective($compile: ng.ICompileService, $httpParam
}

$scope.columns.forEach(function (column: any) {
const isFilterable =
$scope.flattenedRow[column] !== undefined &&
mapping(column) &&
mapping(column).filterable &&
$scope.filter;
const isFilterable = mapping(column) && mapping(column).filterable && $scope.filter;

newHtmls.push(
cellTemplate({
Expand Down
Loading

0 comments on commit 65a2248

Please sign in to comment.