renovate/lib/util/regex.spec.ts

27 lines
648 B
TypeScript
Raw Normal View History

// eslint-disable-next-line import/no-extraneous-dependencies
2019-08-25 12:29:51 +00:00
import RE2 from 're2';
2020-03-05 20:57:24 +00:00
import { CONFIG_VALIDATION } from '../constants/error-messages';
2020-05-01 16:03:48 +00:00
import { regEx } from './regex';
2019-08-25 12:29:51 +00:00
describe('util/regex', () => {
beforeEach(() => {
jest.resetModules();
});
it('uses RE2', () => {
expect(regEx('foo')).toBeInstanceOf(RE2);
});
it('throws unsafe 2', () => {
expect(() => regEx(`x++`)).toThrow(CONFIG_VALIDATION);
2019-08-25 12:29:51 +00:00
});
it('Falls back to RegExp', () => {
jest.doMock('re2', () => {
throw new Error();
});
2020-03-05 20:57:24 +00:00
const regex = require('./regex');
expect(regex.regEx('foo')).toBeInstanceOf(RegExp);
2019-08-25 12:29:51 +00:00
});
});