const { configure } = require('@testing-library/dom');
const { MockTracer } = require('@splunk/olly-tracing/mocks');

configure({ testIdAttribute: 'data-test' });

const { error } = console;

const messagesToSuppress = [
    // A few of our third-party dependencies use the old API. We don't own
    // this code, so we can't update it easily. For now, we just need to override
    // these errors. Longer-term we need to update these libraries.
    /componentWillReceiveProps has been renamed/,
    /componentWillUpdate has been renamed/,
    /It looks like you\'re using the wrong act\(\) around your test interactions\./,
    /\`withSendTelemetry\` has been deprecated/,
];

console.error = console.warn = function (message) {
    const suppressMessage = messagesToSuppress.some(pattern => pattern.test(message));
    if (suppressMessage) {
        return null;
    }

    error.apply(console, arguments); // keep default behaviour

    throw message instanceof Error ? message : new Error(message);
};

jest.mock('@splunk/olly-tracing/tracer', () => ({
    getCustomTracer: () => new MockTracer(),
}));
