summaryrefslogtreecommitdiff
path: root/test/parallel/test-runner-string-to-regexp.js
blob: 4561f4a4064c8493d6c9cbd98e33dda8ea67ed71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Flags: --expose-internals
'use strict';
const common = require('../common');
const { deepStrictEqual, throws } = require('node:assert');
const { convertStringToRegExp } = require('internal/test_runner/utils');

deepStrictEqual(convertStringToRegExp('foo', 'x'), /foo/);
deepStrictEqual(convertStringToRegExp('/bar/', 'x'), /bar/);
deepStrictEqual(convertStringToRegExp('/baz/gi', 'x'), /baz/gi);
deepStrictEqual(convertStringToRegExp('/foo/9', 'x'), /\/foo\/9/);

throws(
  () => convertStringToRegExp('/foo/abcdefghijk', 'x'),
  common.expectsError({
    code: 'ERR_INVALID_ARG_VALUE',
    message: "The argument 'x' is an invalid regular expression. " +
             "Invalid flags supplied to RegExp constructor 'abcdefghijk'. " +
             "Received '/foo/abcdefghijk'",
  })
);