@zohodesk/testinglibrary 0.1.7 → 0.1.8-exp-bdd

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 (91) hide show
  1. package/.babelrc +18 -18
  2. package/.eslintrc.js +27 -31
  3. package/.prettierrc +5 -5
  4. package/README.md +17 -17
  5. package/bin/cli.js +2 -2
  6. package/build/bdd-framework/cli/commands/env.js +4 -4
  7. package/build/bdd-framework/cli/commands/test.js +2 -6
  8. package/build/bdd-framework/cli/options.js +4 -4
  9. package/build/bdd-framework/cli/worker.js +3 -3
  10. package/build/bdd-framework/config/dir.js +6 -6
  11. package/build/bdd-framework/config/env.js +4 -5
  12. package/build/bdd-framework/config/index.js +2 -2
  13. package/build/bdd-framework/cucumber/buildStepDefinition.js +3 -3
  14. package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
  15. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +3 -3
  16. package/build/bdd-framework/cucumber/loadSources.js +9 -9
  17. package/build/bdd-framework/cucumber/loadSteps.js +3 -8
  18. package/build/bdd-framework/decorators.js +2 -2
  19. package/build/bdd-framework/gen/formatter.js +17 -64
  20. package/build/bdd-framework/gen/i18n.js +5 -9
  21. package/build/bdd-framework/gen/index.js +8 -9
  22. package/build/bdd-framework/gen/poms.js +46 -0
  23. package/build/bdd-framework/gen/testFile.js +55 -121
  24. package/build/bdd-framework/gen/testNode.js +6 -19
  25. package/build/bdd-framework/gen/testPoms.js +39 -49
  26. package/build/bdd-framework/playwright/fixtureParameterNames.js +11 -27
  27. package/build/bdd-framework/playwright/getLocationInFile.js +11 -17
  28. package/build/bdd-framework/playwright/loadConfig.js +3 -3
  29. package/build/bdd-framework/playwright/testTypeImpl.js +15 -19
  30. package/build/bdd-framework/playwright/transform.js +6 -10
  31. package/build/bdd-framework/playwright/utils.js +6 -3
  32. package/build/bdd-framework/run/bddFixtures.js +55 -118
  33. package/build/bdd-framework/run/bddWorld.js +36 -24
  34. package/build/bdd-framework/snippets/index.js +3 -5
  35. package/build/bdd-framework/snippets/snippetSyntax.js +1 -3
  36. package/build/bdd-framework/snippets/snippetSyntaxTs.js +4 -4
  37. package/build/bdd-framework/stepDefinitions/createBdd.js +13 -30
  38. package/build/bdd-framework/stepDefinitions/createDecorators.js +108 -0
  39. package/build/bdd-framework/stepDefinitions/decorators/{class.js → poms.js} +9 -13
  40. package/build/bdd-framework/stepDefinitions/decorators/steps.js +8 -14
  41. package/build/bdd-framework/stepDefinitions/defineStep.js +4 -5
  42. package/build/bdd-framework/stepDefinitions/stepConfig.js +5 -5
  43. package/build/bdd-framework/utils/exit.js +18 -26
  44. package/build/bdd-framework/utils/index.js +4 -30
  45. package/build/bdd-framework/utils/jsStringWrap.js +9 -9
  46. package/build/bdd-framework/utils/logger.js +3 -5
  47. package/build/bdd-poc/core-runner/exportMethods.js +14 -0
  48. package/build/bdd-poc/core-runner/stepDefinitions.js +55 -0
  49. package/build/bdd-poc/main.js +10 -0
  50. package/build/bdd-poc/test/cucumber/featureFileParer.js +81 -0
  51. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +36 -0
  52. package/build/bdd-poc/test/stepGenerate/stepsnippets.js +43 -0
  53. package/build/bdd-poc/test/testDataMap.js +98 -0
  54. package/build/bdd-poc/test/testStructure.js +83 -0
  55. package/build/bdd-poc/utils/stringManipulation.js +19 -0
  56. package/build/core/playwright/custom-commands.js +1 -1
  57. package/build/core/playwright/index.js +0 -15
  58. package/build/core/playwright/readConfigFile.js +30 -37
  59. package/build/core/playwright/report-generator.js +1 -2
  60. package/build/core/playwright/setup/config-creator.js +15 -21
  61. package/build/core/playwright/setup/config-utils.js +0 -30
  62. package/build/core/playwright/test-runner.js +5 -7
  63. package/build/index.d.ts +5 -60
  64. package/build/index.js +3 -5
  65. package/build/lib/cli.js +1 -10
  66. package/build/parser/sample.feature +34 -34
  67. package/build/parser/sample.spec.js +18 -18
  68. package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -72
  69. package/build/setup-folder-structure/samples/authUsers-sample.json +8 -8
  70. package/build/setup-folder-structure/samples/env-config-sample.json +20 -20
  71. package/build/setup-folder-structure/samples/git-ignore.sample.js +32 -36
  72. package/build/setup-folder-structure/samples/uat-config-sample.js +43 -44
  73. package/build/setup-folder-structure/setupProject.js +5 -10
  74. package/build/utils/cliArgsToObject.js +25 -25
  75. package/build/utils/fileUtils.js +0 -12
  76. package/changelog.md +74 -124
  77. package/jest.config.js +63 -63
  78. package/npm-shrinkwrap.json +7781 -6469
  79. package/package.json +54 -55
  80. package/playwright.config.js +112 -112
  81. package/build/bdd-framework/config/lang.js +0 -14
  82. package/build/bdd-framework/gen/fixtures.js +0 -48
  83. package/build/bdd-framework/hooks/scenario.js +0 -107
  84. package/build/bdd-framework/hooks/worker.js +0 -83
  85. package/build/bdd-framework/run/StepInvoker.js +0 -73
  86. package/build/core/playwright/clear-caches.js +0 -29
  87. package/build/core/playwright/setup/custom-reporter.js +0 -100
  88. package/build/core/playwright/tag-processor.js +0 -68
  89. package/build/setup-folder-structure/helper.js +0 -34
  90. package/build/setup-folder-structure/reportEnhancement/addonScript.html +0 -25
  91. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +0 -25
package/package.json CHANGED
@@ -1,55 +1,54 @@
1
- {
2
- "name": "@zohodesk/testinglibrary",
3
- "version": "0.1.7",
4
- "description": "",
5
- "main": "./build/index.js",
6
- "scripts": {
7
- "postinstall": "node bin/postinstall.js",
8
- "test": "echo \"Error: no test specified\" && exit 1",
9
- "clean": "rm -rf build && mkdir build",
10
- "build-babel": "babel -d ./build ./src --copy-files",
11
- "build": "npm run clean && npm run build-babel",
12
- "prepare": "npm run build",
13
- "lint": "eslint src/* --fix"
14
- },
15
- "exports": {
16
- ".": "./build/index.js",
17
- "./decorators": "./build/decorators.js"
18
- },
19
- "keywords": [],
20
- "author": "",
21
- "license": "ISC",
22
- "dependencies": {
23
- "@babel/preset-react": "7.22.5",
24
- "@cucumber/cucumber": "9.2.0",
25
- "@playwright/test": "1.40.1",
26
- "@testing-library/jest-dom": "5.11.9",
27
- "@testing-library/react": "11.2.7",
28
- "@testing-library/react-hooks": "7.0.2",
29
- "babel-jest": "29.6.2",
30
- "babel-plugin-transform-dynamic-import": "2.1.0",
31
- "fast-glob": "3.3.1",
32
- "jest": "29.6.2",
33
- "jest-environment-jsdom": "29.6.2",
34
- "msw": "1.2.3",
35
- "playwright": "1.40.1"
36
- },
37
- "bin": {
38
- "ZDTestingFramework": "./bin/cli.js"
39
- },
40
- "peerDependencies": {
41
- "react": "*",
42
- "react-dom": "*",
43
- "eslint": "*"
44
- },
45
- "devDependencies": {
46
- "@babel/cli": "7.22.15",
47
- "@babel/core": "7.22.17",
48
- "@babel/node": "7.22.15",
49
- "@babel/plugin-transform-runtime": "7.22.15",
50
- "@babel/polyfill": "7.12.1",
51
- "@babel/preset-env": "7.22.15",
52
- "@babel/runtime": "7.22.15",
53
- "commander": "^11.0.0"
54
- }
55
- }
1
+ {
2
+ "name": "@zohodesk/testinglibrary",
3
+ "version": "0.1.8-exp-bdd",
4
+ "description": "",
5
+ "main": "./build/index.js",
6
+ "scripts": {
7
+ "postinstall": "node bin/postinstall.js",
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "clean": "rmdir /s /q build && mkdir build",
10
+ "build-babel": "babel -d ./build ./src --copy-files",
11
+ "build": "npm run clean && npm run build-babel",
12
+ "prepare": "npm run build",
13
+ "lint": "eslint src/* --fix"
14
+ },
15
+ "exports": {
16
+ ".": "./build/index.js",
17
+ "./decorators": "./build/decorators.js"
18
+ },
19
+ "keywords": [],
20
+ "author": "",
21
+ "license": "ISC",
22
+ "dependencies": {
23
+ "@babel/preset-react": "7.22.5",
24
+ "@cucumber/cucumber": "9.2.0",
25
+ "@playwright/test": "1.39.0",
26
+ "@testing-library/jest-dom": "5.11.9",
27
+ "@testing-library/react": "11.2.7",
28
+ "@testing-library/react-hooks": "7.0.2",
29
+ "babel-jest": "29.6.2",
30
+ "babel-plugin-transform-dynamic-import": "2.1.0",
31
+ "commander": "11.0.0",
32
+ "fast-glob": "3.3.1",
33
+ "jest": "29.6.2",
34
+ "jest-environment-jsdom": "29.6.2",
35
+ "msw": "1.2.3"
36
+ },
37
+ "bin": {
38
+ "ZDTestingFramework": "./bin/cli.js"
39
+ },
40
+ "peerDependencies": {
41
+ "react": "*",
42
+ "react-dom": "*",
43
+ "eslint": "*"
44
+ },
45
+ "devDependencies": {
46
+ "@babel/cli": "7.22.15",
47
+ "@babel/core": "7.22.17",
48
+ "@babel/node": "7.22.15",
49
+ "@babel/plugin-transform-runtime": "7.22.15",
50
+ "@babel/polyfill": "7.12.1",
51
+ "@babel/preset-env": "7.22.15",
52
+ "@babel/runtime": "7.22.15"
53
+ }
54
+ }
@@ -1,112 +1,112 @@
1
- // @ts-check
2
- const { defineConfig, devices } = require('@playwright/test');
3
- const path = require('path');
4
- const numCPUs = require('os').cpus().length;
5
-
6
- /**
7
- * Read environment variables from file.
8
- * https://github.com/motdotla/dotenv
9
- */
10
- // require('dotenv').config();
11
-
12
- /**
13
- * @see https://playwright.dev/docs/test-configuration
14
- */
15
- export default defineConfig({
16
- testDir: path.join(path.resolve(process.cwd()), 'uat'),
17
- outputDir: path.join(process.cwd(), 'uat', 'test-results'),
18
- /* Run tests in files in parallel */
19
- fullyParallel: true,
20
- /* Fail the build on CI if you accidentally left test.only in the source code. */
21
- forbidOnly: !!process.env.CI,
22
- /* Retry on CI only */
23
- retries: process.env.CI ? 2 : 0,
24
- /* Opt out of parallel tests on CI. */
25
- workers: process.env.CI ? 1 : 1,
26
- /* Reporter to use. See https://playwright.dev/docs/test-reporters */
27
- reporter: [['html', { outputFolder: path.join(process.cwd(), 'uat', 'playwright-report'), open: "always" }]],
28
- timeout: 60 * 1000,
29
- expect: {
30
- timeout: 5 * 1000,
31
- },
32
-
33
- /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
34
- use: {
35
- /* Base URL to use in actions like `await page.goto('/')`. */
36
- //baseURL: process.env.domain,
37
-
38
- /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
39
- trace: 'on',
40
- video: {
41
- mode: 'on',
42
- size: { width: 640, height: 480 }
43
- }
44
- },
45
-
46
- /* Configure projects for major browsers */
47
- projects: [
48
- { name: 'setup', testMatch: /.*\.setup\.js/ },
49
- {
50
- name: 'chromium',
51
- use: {
52
- ...devices['Desktop Chrome'],
53
- storageState: path.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')
54
- },
55
- dependencies: ['setup'],
56
- },
57
-
58
- {
59
- name: 'firefox',
60
- timeout: 4 * 60 * 1000,
61
- expect: {
62
- timeout: 80 * 1000,
63
- },
64
- use: {
65
- ...devices['Desktop Firefox'],
66
- storageState: path.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')
67
- },
68
- dependencies: ['setup'],
69
- },
70
-
71
- {
72
- name: 'webkit',
73
- timeout: 2 * 60 * 1000,
74
- expect: {
75
- timeout: 80 * 1000,
76
- },
77
- use: {
78
- ...devices['Desktop Safari'],
79
- storageState: path.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')
80
- },
81
- dependencies: ['setup'],
82
- },
83
-
84
- /* Test against mobile viewports. */
85
- // {
86
- // name: 'Mobile Chrome',
87
- // use: { ...devices['Pixel 5'] },
88
- // },
89
- // {
90
- // name: 'Mobile Safari',
91
- // use: { ...devices['iPhone 12'] },
92
- // },
93
-
94
- /* Test against branded browsers. */
95
- // {
96
- // name: 'Microsoft Edge',
97
- // use: { ...devices['Desktop Edge'], channel: 'msedge' },
98
- // },
99
- // {
100
- // name: 'Google Chrome',
101
- // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
102
- // },
103
- ],
104
-
105
- /* Run your local dev server before starting the tests */
106
- // webServer: {
107
- // command: 'npm run start',
108
- // url: 'http://127.0.0.1:3000',
109
- // reuseExistingServer: !process.env.CI,
110
- // },
111
- });
112
-
1
+ // @ts-check
2
+ const { defineConfig, devices } = require('@playwright/test');
3
+ const path = require('path');
4
+ const numCPUs = require('os').cpus().length;
5
+
6
+ /**
7
+ * Read environment variables from file.
8
+ * https://github.com/motdotla/dotenv
9
+ */
10
+ // require('dotenv').config();
11
+
12
+ /**
13
+ * @see https://playwright.dev/docs/test-configuration
14
+ */
15
+ export default defineConfig({
16
+ testDir: path.join(path.resolve(process.cwd()), 'uat'),
17
+ outputDir: path.join(process.cwd(), 'uat', 'test-results'),
18
+ /* Run tests in files in parallel */
19
+ fullyParallel: true,
20
+ /* Fail the build on CI if you accidentally left test.only in the source code. */
21
+ forbidOnly: !!process.env.CI,
22
+ /* Retry on CI only */
23
+ retries: process.env.CI ? 2 : 0,
24
+ /* Opt out of parallel tests on CI. */
25
+ workers: process.env.CI ? 1 : 1,
26
+ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
27
+ reporter: [['html', { outputFolder: path.join(process.cwd(), 'uat', 'playwright-report'), open: "always" }]],
28
+ timeout: 60 * 1000,
29
+ expect: {
30
+ timeout: 5 * 1000,
31
+ },
32
+
33
+ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
34
+ use: {
35
+ /* Base URL to use in actions like `await page.goto('/')`. */
36
+ //baseURL: process.env.domain,
37
+
38
+ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
39
+ trace: 'on',
40
+ video: {
41
+ mode: 'on',
42
+ size: { width: 640, height: 480 }
43
+ }
44
+ },
45
+
46
+ /* Configure projects for major browsers */
47
+ projects: [
48
+ { name: 'setup', testMatch: /.*\.setup\.js/ },
49
+ {
50
+ name: 'chromium',
51
+ use: {
52
+ ...devices['Desktop Chrome'],
53
+ storageState: path.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')
54
+ },
55
+ dependencies: ['setup'],
56
+ },
57
+
58
+ {
59
+ name: 'firefox',
60
+ timeout: 4 * 60 * 1000,
61
+ expect: {
62
+ timeout: 80 * 1000,
63
+ },
64
+ use: {
65
+ ...devices['Desktop Firefox'],
66
+ storageState: path.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')
67
+ },
68
+ dependencies: ['setup'],
69
+ },
70
+
71
+ {
72
+ name: 'webkit',
73
+ timeout: 2 * 60 * 1000,
74
+ expect: {
75
+ timeout: 80 * 1000,
76
+ },
77
+ use: {
78
+ ...devices['Desktop Safari'],
79
+ storageState: path.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json')
80
+ },
81
+ dependencies: ['setup'],
82
+ },
83
+
84
+ /* Test against mobile viewports. */
85
+ // {
86
+ // name: 'Mobile Chrome',
87
+ // use: { ...devices['Pixel 5'] },
88
+ // },
89
+ // {
90
+ // name: 'Mobile Safari',
91
+ // use: { ...devices['iPhone 12'] },
92
+ // },
93
+
94
+ /* Test against branded browsers. */
95
+ // {
96
+ // name: 'Microsoft Edge',
97
+ // use: { ...devices['Desktop Edge'], channel: 'msedge' },
98
+ // },
99
+ // {
100
+ // name: 'Google Chrome',
101
+ // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
102
+ // },
103
+ ],
104
+
105
+ /* Run your local dev server before starting the tests */
106
+ // webServer: {
107
+ // command: 'npm run start',
108
+ // url: 'http://127.0.0.1:3000',
109
+ // reuseExistingServer: !process.env.CI,
110
+ // },
111
+ });
112
+
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.LANG_EN = void 0;
7
- exports.isEnglish = isEnglish;
8
- /**
9
- * Helpers for Cucumber language option.
10
- */
11
- const LANG_EN = exports.LANG_EN = 'en';
12
- function isEnglish(lang) {
13
- return !lang || lang === LANG_EN;
14
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.extractFixtureNames = extractFixtureNames;
7
- exports.extractFixtureNamesFromFnBodyMemo = extractFixtureNamesFromFnBodyMemo;
8
- var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
9
- var _bddFixtures = require("../run/bddFixtures");
10
- var _exit = require("../utils/exit");
11
- const bodyFixturesSymbol = Symbol('bodyFixtures');
12
- /**
13
- * This function is used for playwright-style steps and decorators.
14
- * It extracts fixtures names from first parameter of function
15
- * using Playwright's helper.
16
- */
17
- function extractFixtureNames(fn) {
18
- return (0, _fixtureParameterNames.fixtureParameterNames)(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
19
- }
20
- /**
21
- * This function is used for cucumber-style steps.
22
- * It looks for `this.useFixture('xxx')` entries in function body
23
- * and extracts fixtures names from it.
24
- */
25
- function extractFixtureNamesFromFnBodyMemo(fn) {
26
- if (typeof fn !== 'function') {
27
- return [];
28
- }
29
- const fnWithFixtures = fn;
30
- if (!fnWithFixtures[bodyFixturesSymbol]) {
31
- fnWithFixtures[bodyFixturesSymbol] = extractFixtureNamesFromFnBody(fn).filter(name => !(0, _bddFixtures.isBddAutoInjectFixture)(name));
32
- }
33
- return fnWithFixtures[bodyFixturesSymbol];
34
- }
35
- function extractFixtureNamesFromFnBody(fn) {
36
- const matches = fn.toString().matchAll(/this\.useFixture\((.+)\)/gi) || [];
37
- return [...matches].map(match => getFixtureName(match[1]));
38
- }
39
- function getFixtureName(arg) {
40
- if (!/^['"`]/.test(arg)) {
41
- // todo: log file location with incorrect useFixture
42
- (0, _exit.exit)('this.useFixture() can accept only static string as an argument.');
43
- }
44
- if (arg.startsWith('`') && arg.includes('${')) {
45
- (0, _exit.exit)('this.useFixture() can accept only static string as an argument.');
46
- }
47
- return arg.replace(/['"`]/g, '');
48
- }
@@ -1,107 +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.getScenarioHooksFixtures = getScenarioHooksFixtures;
8
- exports.hasScenarioHooks = hasScenarioHooks;
9
- exports.runScenarioHooks = runScenarioHooks;
10
- exports.scenarioHookFactory = scenarioHookFactory;
11
- var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
12
- var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
13
- var _utils = require("../utils");
14
- /**
15
- * Scenario level hooks: Before / After.
16
- *
17
- * before(async ({ page }) => {})
18
- */
19
-
20
- const scenarioHooks = [];
21
- let scenarioHooksFixtures;
22
- /**
23
- * Returns Before() / After() functions.
24
- */
25
- function scenarioHookFactory(type) {
26
- return (...args) => {
27
- addHook({
28
- type,
29
- options: getOptionsFromArgs(args),
30
- fn: getFnFromArgs(args)
31
- });
32
- };
33
- }
34
- function hasScenarioHooks() {
35
- return scenarioHooks.length > 0;
36
- }
37
- // eslint-disable-next-line complexity
38
- async function runScenarioHooks(type, fixtures) {
39
- let error;
40
- for (const hook of scenarioHooks) {
41
- if (hook.type !== type) {
42
- continue;
43
- }
44
- if (hook.tagsExpression && !hook.tagsExpression.evaluate(fixtures.$tags)) {
45
- continue;
46
- }
47
- const {
48
- timeout
49
- } = hook.options;
50
- try {
51
- await (0, _utils.callWithTimeout)(() => hook.fn.call(fixtures.$bddWorld, fixtures), timeout, `${type} hook timeout (${timeout} ms)`);
52
- } catch (e) {
53
- if (type === 'before') {
54
- throw e;
55
- }
56
- if (!error) {
57
- error = e;
58
- }
59
- }
60
- }
61
- if (error) {
62
- throw error;
63
- }
64
- }
65
- function getScenarioHooksFixtures() {
66
- if (!scenarioHooksFixtures) {
67
- const fixturesFakeObj = {
68
- $bddWorld: null,
69
- $tags: null,
70
- $testInfo: null
71
- };
72
- const set = new Set();
73
- scenarioHooks.forEach(hook => {
74
- (0, _fixtureParameterNames.fixtureParameterNames)(hook.fn).filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixturesFakeObj, fixtureName)).forEach(fixtureName => set.add(fixtureName));
75
- });
76
- scenarioHooksFixtures = [...set];
77
- }
78
- return scenarioHooksFixtures;
79
- }
80
- function getOptionsFromArgs(args) {
81
- if (typeof args[0] === 'string') {
82
- return {
83
- tags: args[0]
84
- };
85
- }
86
- if (typeof args[0] === 'object') {
87
- return args[0];
88
- }
89
- return {};
90
- }
91
- function getFnFromArgs(args) {
92
- return args.length === 1 ? args[0] : args[1];
93
- }
94
- function setTagsExpression(hook) {
95
- if (hook.options.tags) {
96
- hook.tagsExpression = (0, _tagExpressions.default)(hook.options.tags);
97
- }
98
- }
99
- function addHook(hook) {
100
- setTagsExpression(hook);
101
- if (hook.type === 'before') {
102
- scenarioHooks.push(hook);
103
- } else {
104
- // 'after' hooks run in reverse order
105
- scenarioHooks.unshift(hook);
106
- }
107
- }
@@ -1,83 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getWorkerHooksFixtures = getWorkerHooksFixtures;
7
- exports.runWorkerHooks = runWorkerHooks;
8
- exports.workerHookFactory = workerHookFactory;
9
- var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
10
- var _utils = require("../utils");
11
- /**
12
- * Worker-level hooks: BeforeAll / AfterAll.
13
- */
14
-
15
- const workerHooks = [];
16
- let workerHooksFixtures;
17
- /**
18
- * Returns BeforeAll() / AfterAll() functions.
19
- */
20
- function workerHookFactory(type) {
21
- return (...args) => {
22
- addHook({
23
- type,
24
- options: getOptionsFromArgs(args),
25
- fn: getFnFromArgs(args)
26
- });
27
- };
28
- }
29
- // eslint-disable-next-line complexity
30
- async function runWorkerHooks(type, fixtures) {
31
- let error;
32
- for (const hook of workerHooks) {
33
- if (hook.type !== type) {
34
- continue;
35
- }
36
- const {
37
- timeout
38
- } = hook.options;
39
- try {
40
- await (0, _utils.callWithTimeout)(() => hook.fn(fixtures), timeout, `${type} hook timeout (${timeout} ms)`);
41
- } catch (e) {
42
- if (type === 'beforeAll') {
43
- throw e;
44
- }
45
- if (!error) {
46
- error = e;
47
- }
48
- }
49
- }
50
- if (error) {
51
- throw error;
52
- }
53
- }
54
- function getWorkerHooksFixtures() {
55
- if (!workerHooksFixtures) {
56
- const fixturesFakeObj = {
57
- $workerInfo: null
58
- };
59
- const set = new Set();
60
- workerHooks.forEach(hook => {
61
- (0, _fixtureParameterNames.fixtureParameterNames)(hook.fn).filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixturesFakeObj, fixtureName)).forEach(fixtureName => set.add(fixtureName));
62
- });
63
- workerHooksFixtures = [...set];
64
- }
65
- return workerHooksFixtures;
66
- }
67
- function getOptionsFromArgs(args) {
68
- if (typeof args[0] === 'object') {
69
- return args[0];
70
- }
71
- return {};
72
- }
73
- function getFnFromArgs(args) {
74
- return args.length === 1 ? args[0] : args[1];
75
- }
76
- function addHook(hook) {
77
- if (hook.type === 'beforeAll') {
78
- workerHooks.push(hook);
79
- } else {
80
- // 'afterAll' hooks run in reverse order
81
- workerHooks.unshift(hook);
82
- }
83
- }
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.StepInvoker = void 0;
7
- var _loadSteps = require("../cucumber/loadSteps");
8
- var _getLocationInFile = require("../playwright/getLocationInFile");
9
- var _testTypeImpl = require("../playwright/testTypeImpl");
10
- var _defineStep = require("../stepDefinitions/defineStep");
11
- var _lang = require("../config/lang");
12
- /**
13
- * Class to invoke steps in generated files.
14
- */
15
-
16
- class StepInvoker {
17
- world;
18
- keyword;
19
- text = '';
20
- argument;
21
- constructor(world, keyword) {
22
- this.world = world;
23
- this.keyword = keyword;
24
- this.invoke = this.invoke.bind(this);
25
- }
26
- async invoke(text, argument, stepFixtures) {
27
- this.text = text;
28
- this.argument = argument;
29
- const {
30
- world
31
- } = this;
32
- world.stepFixtures = stepFixtures || {};
33
- const stepDefinition = this.getStepDefinition();
34
- // Get location of step call in generated test file.
35
- // This call must be exactly here to have correct call stack (before async calls)
36
- const location = (0, _getLocationInFile.getLocationInFile)(world.test.info().file);
37
- const stepTitle = this.getStepTitle();
38
- const code = (0, _defineStep.getStepCode)(stepDefinition);
39
- const parameters = await this.getStepParameters(stepDefinition);
40
- return (0, _testTypeImpl.runStepWithCustomLocation)(world.test, stepTitle, location, () => code.apply(world, parameters));
41
- }
42
- getStepDefinition() {
43
- const stepDefinition = (0, _loadSteps.findStepDefinition)(this.world.options.supportCodeLibrary, this.text, this.world.testInfo.file);
44
- if (!stepDefinition) {
45
- throw new Error(`Undefined step: "${this.text}"`);
46
- }
47
- return stepDefinition;
48
- }
49
- async getStepParameters(stepDefinition) {
50
- const {
51
- text,
52
- argument,
53
- world
54
- } = this;
55
- const {
56
- parameters
57
- } = await stepDefinition.getInvocationParameters({
58
- hookParameter: {},
59
- step: {
60
- text,
61
- argument
62
- },
63
- world
64
- });
65
- return parameters;
66
- }
67
- getStepTitle() {
68
- // Currently prepend keyword only for English.
69
- // For other langs it's more complex as we need to pass original keyword from step.
70
- return (0, _lang.isEnglish)(this.world.options.lang) ? `${this.keyword} ${this.text}` : this.text;
71
- }
72
- }
73
- exports.StepInvoker = StepInvoker;