@zohodesk/testinglibrary 0.1.8-exp-bdd-v2 → 0.1.8-exp-bdd-v3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +1 -1
  2. package/build/core/playwright/index.js +6 -18
  3. package/build/core/playwright/setup/config-utils.js +14 -13
  4. package/build/core/playwright/test-runner.js +30 -26
  5. package/build/decorators.d.ts +1 -1
  6. package/build/decorators.js +2 -16
  7. package/package.json +1 -1
  8. package/build/bdd-framework/cli/commands/env.js +0 -43
  9. package/build/bdd-framework/cli/commands/export.js +0 -48
  10. package/build/bdd-framework/cli/commands/test.js +0 -61
  11. package/build/bdd-framework/cli/index.js +0 -11
  12. package/build/bdd-framework/cli/options.js +0 -20
  13. package/build/bdd-framework/cli/worker.js +0 -13
  14. package/build/bdd-framework/config/dir.js +0 -27
  15. package/build/bdd-framework/config/env.js +0 -49
  16. package/build/bdd-framework/config/index.js +0 -91
  17. package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
  18. package/build/bdd-framework/cucumber/gherkin.d.js +0 -5
  19. package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
  20. package/build/bdd-framework/cucumber/loadConfig.js +0 -17
  21. package/build/bdd-framework/cucumber/loadFeatures.js +0 -39
  22. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
  23. package/build/bdd-framework/cucumber/loadSources.js +0 -57
  24. package/build/bdd-framework/cucumber/loadSteps.js +0 -35
  25. package/build/bdd-framework/decorators.js +0 -22
  26. package/build/bdd-framework/gen/formatter.js +0 -88
  27. package/build/bdd-framework/gen/i18n.js +0 -35
  28. package/build/bdd-framework/gen/index.js +0 -163
  29. package/build/bdd-framework/gen/poms.js +0 -46
  30. package/build/bdd-framework/gen/testFile.js +0 -356
  31. package/build/bdd-framework/gen/testNode.js +0 -48
  32. package/build/bdd-framework/gen/testPoms.js +0 -123
  33. package/build/bdd-framework/index.js +0 -45
  34. package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -77
  35. package/build/bdd-framework/playwright/getLocationInFile.js +0 -46
  36. package/build/bdd-framework/playwright/loadConfig.js +0 -42
  37. package/build/bdd-framework/playwright/testTypeImpl.js +0 -57
  38. package/build/bdd-framework/playwright/transform.js +0 -80
  39. package/build/bdd-framework/playwright/types.js +0 -5
  40. package/build/bdd-framework/playwright/utils.js +0 -37
  41. package/build/bdd-framework/run/bddFixtures.js +0 -108
  42. package/build/bdd-framework/run/bddWorld.js +0 -88
  43. package/build/bdd-framework/snippets/index.js +0 -135
  44. package/build/bdd-framework/snippets/snippetSyntax.js +0 -41
  45. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
  46. package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
  47. package/build/bdd-framework/stepDefinitions/createBdd.js +0 -49
  48. package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -109
  49. package/build/bdd-framework/stepDefinitions/decorators/poms.js +0 -64
  50. package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -94
  51. package/build/bdd-framework/stepDefinitions/defineStep.js +0 -61
  52. package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
  53. package/build/bdd-framework/utils/exit.js +0 -54
  54. package/build/bdd-framework/utils/index.js +0 -44
  55. package/build/bdd-framework/utils/jsStringWrap.js +0 -44
  56. package/build/bdd-framework/utils/logger.js +0 -29
@@ -1,49 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createBdd = createBdd;
7
- exports.extractFixtureNames = extractFixtureNames;
8
- var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
9
- var _bddFixtures = require("../run/bddFixtures");
10
- var _testTypeImpl = require("../playwright/testTypeImpl");
11
- var _defineStep = require("./defineStep");
12
- var _exit = require("../utils/exit");
13
- /**
14
- * Stuff related to writing steps in Playwright-style.
15
- */
16
-
17
- function createBdd(customTest) {
18
- const hasCustomTest = isCustomTest(customTest);
19
- const Given = defineStepCtor('Given', hasCustomTest);
20
- const When = defineStepCtor('When', hasCustomTest);
21
- const Then = defineStepCtor('Then', hasCustomTest);
22
- const Step = defineStepCtor('Unknown', hasCustomTest);
23
- return {
24
- Given,
25
- When,
26
- Then,
27
- Step
28
- };
29
- }
30
- function defineStepCtor(keyword, hasCustomTest) {
31
- return (pattern, fn) => {
32
- (0, _defineStep.defineStep)({
33
- keyword,
34
- pattern,
35
- fn,
36
- hasCustomTest
37
- });
38
- };
39
- }
40
- function extractFixtureNames(fn) {
41
- return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
42
- }
43
- function isCustomTest(customTest) {
44
- const isCustomTest = Boolean(customTest && customTest !== _bddFixtures.test);
45
- if (isCustomTest && customTest && !(0, _testTypeImpl.isParentChildTest)(_bddFixtures.test, customTest)) {
46
- (0, _exit.exit)(`createBdd() should use test extended from "@zohodesk/testinglibrary"`);
47
- }
48
- return isCustomTest;
49
- }
@@ -1,109 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Fixture = Fixture;
7
- exports.appendDecoratorSteps = appendDecoratorSteps;
8
- exports.createStepDecorator = createStepDecorator;
9
- exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
10
- var _bddFixtures = require("../run/bddFixtures");
11
- var _defineStep = require("./defineStep");
12
- var _buildStepDefinition = require("../cucumber/buildStepDefinition");
13
- /* eslint-disable no-unused-vars */
14
- /**
15
- * Define steps via decorators.
16
- */
17
-
18
- const pomGraph = new Map();
19
- const decoratedStepSymbol = Symbol('decoratedStep');
20
- const decoratedSteps = new Set();
21
- function Fixture(fixtureName) {
22
- // context parameter is required for decorator by TS even though it's not used
23
- return (Ctor, _context) => {
24
- createPomNode(Ctor, fixtureName);
25
- };
26
- }
27
- function createStepDecorator(keyword) {
28
- return pattern => {
29
- // context parameter is required for decorator by TS even though it's not used
30
- return (method, _context) => {
31
- method[decoratedStepSymbol] = {
32
- keyword,
33
- pattern,
34
- fn: method,
35
- hasCustomTest: true,
36
- isDecorator: true
37
- };
38
- };
39
- };
40
- }
41
- function appendDecoratorSteps(supportCodeLibrary) {
42
- decoratedSteps.forEach(stepConfig => {
43
- const {
44
- keyword,
45
- pattern,
46
- fn
47
- } = stepConfig;
48
- stepConfig.fn = (fixturesArg, ...args) => {
49
- const fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
50
- return fn.call(fixture, ...args);
51
- };
52
- const code = (0, _defineStep.buildCucumberStepFn)(stepConfig);
53
- const stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
54
- keyword,
55
- pattern,
56
- code,
57
- line: 0,
58
- // not used in playwright-bdd
59
- options: {},
60
- // not used in playwright-bdd
61
- uri: '' // not used in playwright-bdd
62
- }, supportCodeLibrary);
63
- supportCodeLibrary.stepDefinitions.push(stepDefinition);
64
- });
65
- decoratedSteps.clear();
66
- // todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
67
- }
68
-
69
- function getPomNodeByFixtureName(fixtureName) {
70
- for (const pomNode of pomGraph.values()) {
71
- if (pomNode.fixtureName === fixtureName) return pomNode;
72
- }
73
- }
74
- function createPomNode(Ctor, fixtureName) {
75
- const pomNode = {
76
- fixtureName,
77
- children: new Set()
78
- };
79
- pomGraph.set(Ctor, pomNode);
80
- getDecoratedSteps(Ctor).forEach(stepConfig => {
81
- stepConfig.pomNode = pomNode;
82
- decoratedSteps.add(stepConfig);
83
- });
84
- const parentCtor = Object.getPrototypeOf(Ctor);
85
- if (!parentCtor) return;
86
- const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
87
- parentPomNode === null || parentPomNode === void 0 || parentPomNode.children.add(pomNode);
88
- return pomNode;
89
- }
90
- function getDecoratedSteps(Ctor) {
91
- if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) return [];
92
- const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
93
- return Object.keys(propertyDescriptors)
94
- // filter out getters / setters
95
- .filter(methodName => typeof propertyDescriptors[methodName].value === 'function').map(methodName => {
96
- return propertyDescriptors[methodName].value[decoratedStepSymbol];
97
- }).filter(Boolean);
98
- }
99
- function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
100
- // there should be exatcly one suitable fixture in fixturesArg
101
- const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
102
- if (fixtureNames.length === 0) {
103
- throw new Error(`No suitable fixtures found for decorator step "${stepConfig.pattern}"`);
104
- }
105
- if (fixtureNames.length > 1) {
106
- throw new Error(`Several suitable fixtures found for decorator step "${stepConfig.pattern}"`);
107
- }
108
- return fixturesArg[fixtureNames[0]];
109
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Fixture = Fixture;
7
- exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
8
- var _steps = require("./steps");
9
- var _exit = require("../../utils/exit");
10
- /**
11
- * POM classes marked with @Fixture
12
- */
13
-
14
- /**
15
- * Graph of POM class inheritance.
16
- * Allows to guess correct fixture by step text.
17
- */
18
- const pomGraph = new Map();
19
- /**
20
- * @Fixture decorator.
21
- */
22
- function Fixture(fixtureName) {
23
- // context parameter is required for decorator by TS even though it's not used
24
- return Ctor => {
25
- createPomNode(Ctor, fixtureName);
26
- };
27
- }
28
- function createPomNode(Ctor, fixtureName) {
29
- const pomNode = {
30
- fixtureName,
31
- className: Ctor.name,
32
- children: new Set()
33
- };
34
- ensureUniqueFixtureName(pomNode);
35
- pomGraph.set(Ctor, pomNode);
36
- (0, _steps.linkStepsWithPomNode)(Ctor, pomNode);
37
- linkParentWithPomNode(Ctor, pomNode);
38
- return pomNode;
39
- }
40
- function ensureUniqueFixtureName({
41
- fixtureName,
42
- className
43
- }) {
44
- if (!fixtureName) {
45
- return;
46
- }
47
- const existingPom = getPomNodeByFixtureName(fixtureName);
48
- if (existingPom) {
49
- (0, _exit.exit)(`Duplicate fixture name "${fixtureName}"`, `defined for classes: ${existingPom.className}, ${className}`);
50
- }
51
- }
52
- function linkParentWithPomNode(Ctor, pomNode) {
53
- const parentCtor = Object.getPrototypeOf(Ctor);
54
- if (!parentCtor) return;
55
- // if parentCtor is not in pomGraph, add it.
56
- // Case: parent class is not marked with @Fixture, but has decorator steps (base class)
57
- const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
58
- parentPomNode.children.add(pomNode);
59
- }
60
- function getPomNodeByFixtureName(fixtureName) {
61
- for (const pomNode of pomGraph.values()) {
62
- if (pomNode.fixtureName === fixtureName) return pomNode;
63
- }
64
- }
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.appendDecoratorSteps = appendDecoratorSteps;
7
- exports.createStepDecorator = createStepDecorator;
8
- exports.linkStepsWithPomNode = linkStepsWithPomNode;
9
- var _bddFixtures = require("../../run/bddFixtures");
10
- var _buildStepDefinition = require("../../cucumber/buildStepDefinition");
11
- var _defineStep = require("../defineStep");
12
- /**
13
- * Define steps via decorators.
14
- */
15
-
16
- // initially we sotre step data inside method,
17
- // and then extract it in @Fixture decorator call
18
- const decoratedStepSymbol = Symbol('decoratedStep');
19
- // global list of all decorator steps
20
- const decoratedSteps = new Set();
21
- /**
22
- * Creates @Given, @When, @Then decorators.
23
- */
24
- function createStepDecorator(keyword) {
25
- return pattern => {
26
- // context parameter is required for decorator by TS even though it's not used
27
- // eslint-disable-next-line no-unused-vars
28
- return (method, _context) => {
29
- saveStepConfigToMethod(method, {
30
- keyword,
31
- pattern,
32
- fn: method,
33
- hasCustomTest: true
34
- });
35
- };
36
- };
37
- }
38
- function linkStepsWithPomNode(Ctor, pomNode) {
39
- if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) return;
40
- const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
41
- return Object.values(propertyDescriptors).forEach(descriptor => {
42
- const stepConfig = getStepConfigFromMethod(descriptor);
43
- if (!stepConfig) return;
44
- stepConfig.pomNode = pomNode;
45
- decoratedSteps.add(stepConfig);
46
- });
47
- }
48
- /**
49
- * Append decorator steps to Cucumber's supportCodeLibrary.
50
- */
51
- function appendDecoratorSteps(supportCodeLibrary) {
52
- decoratedSteps.forEach(stepConfig => {
53
- const {
54
- keyword,
55
- pattern,
56
- fn
57
- } = stepConfig;
58
- stepConfig.fn = (fixturesArg, ...args) => {
59
- const fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
60
- return fn.call(fixture, ...args);
61
- };
62
- const code = (0, _defineStep.buildCucumberStepCode)(stepConfig);
63
- const stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
64
- keyword,
65
- pattern,
66
- code,
67
- line: 0,
68
- options: {},
69
- uri: '' // not used in playwright-bdd
70
- }, supportCodeLibrary);
71
- supportCodeLibrary.stepDefinitions.push(stepDefinition);
72
- });
73
- decoratedSteps.clear();
74
- // todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
75
- }
76
-
77
- function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
78
- // there should be exatcly one suitable fixture in fixturesArg
79
- const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
80
- if (fixtureNames.length === 0) {
81
- throw new Error(`No suitable fixtures found for decorator step "${stepConfig.pattern}"`);
82
- }
83
- if (fixtureNames.length > 1) {
84
- throw new Error(`Several suitable fixtures found for decorator step "${stepConfig.pattern}"`);
85
- }
86
- return fixturesArg[fixtureNames[0]];
87
- }
88
- function saveStepConfigToMethod(method, stepConfig) {
89
- method[decoratedStepSymbol] = stepConfig;
90
- }
91
- function getStepConfigFromMethod(descriptor) {
92
- // filter out getters / setters
93
- return typeof descriptor.value === 'function' ? descriptor.value[decoratedStepSymbol] : undefined;
94
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.buildCucumberStepCode = buildCucumberStepCode;
7
- exports.defineStep = defineStep;
8
- exports.getStepCode = getStepCode;
9
- var _cucumber = require("@cucumber/cucumber");
10
- var _exit = require("../utils/exit");
11
- /**
12
- * Defines step by config.
13
- * Calls cucumber's Given(), When(), Then() under the hood.
14
- */
15
- function defineStep(stepConfig) {
16
- const {
17
- keyword,
18
- pattern
19
- } = stepConfig;
20
- const cucumberDefineStepFn = getCucumberDefineStepFn(keyword);
21
- const code = buildCucumberStepCode(stepConfig);
22
- try {
23
- cucumberDefineStepFn(pattern, code);
24
- } catch (e) {
25
- // todo: detect that this is import from test file
26
- // and skip/delay registering cucumber steps until cucumber is loaded
27
- const isMissingCucumber = /Cucumber that isn't running/i.test(e.message);
28
- if (isMissingCucumber) {
29
- (0, _exit.exit)(`Option "importTestFrom" should point to a separate file without step definitions`, `(e.g. without calls of Given, When, Then)`);
30
- } else {
31
- throw e;
32
- }
33
- }
34
- }
35
- function buildCucumberStepCode(stepConfig) {
36
- const code = function (...args) {
37
- const fixturesArg = Object.assign({}, this.customFixtures, {
38
- $testInfo: this.testInfo,
39
- $test: this.test,
40
- $tags: this.tags
41
- });
42
- return stepConfig.fn.call(this, fixturesArg, ...args);
43
- };
44
- code.stepConfig = stepConfig;
45
- return code;
46
- }
47
- function getStepCode(stepDefinition) {
48
- return stepDefinition.code;
49
- }
50
- function getCucumberDefineStepFn(keyword) {
51
- switch (keyword) {
52
- case 'Given':
53
- return _cucumber.Given;
54
- case 'When':
55
- return _cucumber.When;
56
- case 'Then':
57
- return _cucumber.Then;
58
- default:
59
- return _cucumber.defineStep;
60
- }
61
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getStepConfig = getStepConfig;
7
- exports.isDecorator = isDecorator;
8
- exports.isPlaywrightStyle = isPlaywrightStyle;
9
- /**
10
- * Playwright-bdd's step config.
11
- */
12
- function getStepConfig(step) {
13
- return step.code.stepConfig;
14
- }
15
- function isDecorator(stepConfig) {
16
- return Boolean(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.pomNode);
17
- }
18
- /**
19
- * Cucumber-style steps don't have stepConfig
20
- * b/c they created directly via cucumber's Given, When, Then.
21
- */
22
- function isPlaywrightStyle(stepConfig) {
23
- return Boolean(stepConfig);
24
- }
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.exit = exit;
7
- exports.withExitHandler = withExitHandler;
8
- var _logger = require("./logger");
9
- var _worker_threads = require("worker_threads");
10
- /**
11
- * Exit utils.
12
- *
13
- * When calling process.exit() in worker thread used for file generation,
14
- * logs are not flushed (https://github.com/vitalets/playwright-bdd/issues/59).
15
- * That's why instead of process.exit we throw ExitError
16
- * that just sets process.exitCode = 1 and allow program to exit normally.
17
- *
18
- * On the other hand, when running in main thread, especially inside Playwright,
19
- * thrown error is captured by Playwright and show with additional messages (e.g. no tests found).
20
- * That's why in main thread we to call process.exit() to show only needed error.
21
- *
22
- * Relevant discussions:
23
- * - https://github.com/nodejs/node/issues/6379
24
- * - https://github.com/nodejs/node-v0.x-archive/issues/3737
25
- * - https://github.com/cucumber/cucumber-js/pull/123
26
- */
27
-
28
- class ExitError extends Error {
29
- get stack() {
30
- return '';
31
- }
32
- }
33
- async function withExitHandler(fn) {
34
- try {
35
- return await fn();
36
- } catch (e) {
37
- if (e instanceof ExitError) {
38
- process.exitCode = 1;
39
- } else {
40
- throw e;
41
- }
42
- }
43
- }
44
- function exit(...messages) {
45
- messages = messages.filter(Boolean);
46
- if (_worker_threads.isMainThread) {
47
- if (messages.length) {
48
- _logger.logger.error('Error:', ...messages);
49
- }
50
- process.exit(1);
51
- } else {
52
- throw new ExitError(messages.join(' '));
53
- }
54
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getPackageVersion = getPackageVersion;
8
- exports.getSymbolByName = getSymbolByName;
9
- exports.removeDuplicates = removeDuplicates;
10
- exports.resolvePackageRoot = resolvePackageRoot;
11
- exports.template = template;
12
- var _fs = _interopRequireDefault(require("fs"));
13
- var _path = _interopRequireDefault(require("path"));
14
- // See: https://stackoverflow.com/questions/50453640/how-can-i-get-the-value-of-a-symbol-property
15
- function getSymbolByName(target, name) {
16
- const ownKeys = Reflect.ownKeys(target);
17
- const symbol = ownKeys.find(key => key.toString() === `Symbol(${name})`);
18
- if (!symbol) {
19
- throw new Error(`Symbol "${name}" not found in target. ownKeys: ${ownKeys}`);
20
- }
21
- return symbol;
22
- }
23
- /**
24
- * Inserts params into template.
25
- * Params defined as <param>.
26
- */
27
- function template(t, params = {}) {
28
- return t.replace(/<(.+?)>/g, (match, key) => {
29
- return params[key] !== undefined ? String(params[key]) : match;
30
- });
31
- }
32
- function removeDuplicates(arr) {
33
- return [...new Set(arr)];
34
- }
35
- function resolvePackageRoot(packageName) {
36
- const packageJsonPath = require.resolve(`${packageName}/package.json`);
37
- return _path.default.dirname(packageJsonPath);
38
- }
39
- function getPackageVersion(packageName) {
40
- const packageRoot = resolvePackageRoot(packageName);
41
- const packageJsonPath = _path.default.join(packageRoot, 'package.json');
42
- const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf8'));
43
- return packageJson.version || '';
44
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.jsStringWrap = jsStringWrap;
7
- /**
8
- * Adopted version of https://github.com/joliss/js-string-escape
9
- * - added support of backticks
10
- * - added 'quotes' option to indicate which quotes to escape
11
- * - wrap result string with provided quotes
12
- *
13
- * Considered alternative is https://github.com/mathiasbynens/jsesc,
14
- * but it provides additional functionality and much slower
15
- * See: https://github.com/mathiasbynens/jsesc/issues/16
16
- */
17
- function jsStringWrap(str, {
18
- quotes = 'single'
19
- } = {}) {
20
- const wrapQuote = quotes === 'single' ? "'" : quotes === 'double' ? '"' : '`';
21
- // eslint-disable-next-line complexity
22
- const escapedStr = ('' + str).replace(/["'`\\\n\r\u2028\u2029]/g, character => {
23
- // Escape all characters not included in SingleStringCharacters and
24
- // DoubleStringCharacters on
25
- // http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
26
- switch (character) {
27
- case wrapQuote:
28
- case '\\':
29
- return '\\' + character;
30
- // Four possible LineTerminator characters need to be escaped:
31
- case '\n':
32
- return '\\n';
33
- case '\r':
34
- return '\\r';
35
- case '\u2028':
36
- return '\\u2028';
37
- case '\u2029':
38
- return '\\u2029';
39
- default:
40
- return character;
41
- }
42
- });
43
- return `${wrapQuote}${escapedStr}${wrapQuote}`;
44
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.logger = exports.Logger = void 0;
7
- /**
8
- * Simple logger
9
- */
10
- class Logger {
11
- options;
12
- constructor(options = {}) {
13
- this.options = options;
14
- }
15
- log(...args) {
16
- if (this.options.verbose) console.log(...args);
17
- }
18
- warn(...args) {
19
- // using log() to output warnings to stdout, not stderr
20
- console.log(...args);
21
- }
22
- error(...args) {
23
- console.error(...args);
24
- }
25
- }
26
- // default logger
27
- exports.Logger = Logger;
28
- const logger = new Logger();
29
- exports.logger = logger;