@zohodesk/testinglibrary 0.1.3 → 0.1.4-exp.10

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 (32) hide show
  1. package/.eslintrc.js +1 -1
  2. package/build/bdd-framework/cli/commands/env.js +1 -2
  3. package/build/bdd-framework/cli/commands/export.js +1 -2
  4. package/build/bdd-framework/cli/commands/test.js +1 -2
  5. package/build/bdd-framework/cli/options.js +1 -2
  6. package/build/bdd-framework/config/index.js +1 -2
  7. package/build/bdd-framework/decorators.js +4 -8
  8. package/build/bdd-framework/playwright/utils.js +1 -4
  9. package/build/bdd-framework/run/bddFixtures.js +1 -2
  10. package/build/bdd-framework/utils/logger.js +1 -2
  11. package/build/core/jest/preprocessor/jsPreprocessor.js +2 -3
  12. package/build/core/playwright/clear-caches.js +29 -0
  13. package/build/core/playwright/custom-commands.js +1 -2
  14. package/build/core/playwright/index.js +1 -2
  15. package/build/core/playwright/readConfigFile.js +10 -6
  16. package/build/core/playwright/setup/config-creator.js +17 -14
  17. package/build/core/playwright/setup/config-utils.js +30 -0
  18. package/build/core/playwright/setup/custom-reporter.js +100 -0
  19. package/build/core/playwright/test-runner.js +3 -5
  20. package/build/index.d.ts +56 -3
  21. package/build/index.js +4 -2
  22. package/build/lib/cli.js +10 -1
  23. package/build/setup-folder-structure/helper.js +34 -0
  24. package/build/setup-folder-structure/samples/git-ignore.sample.js +8 -4
  25. package/build/setup-folder-structure/samples/uat-config-sample.js +3 -2
  26. package/build/setup-folder-structure/setupProject.js +10 -5
  27. package/build/utils/fileUtils.js +12 -0
  28. package/build/utils/logger.js +1 -2
  29. package/build/utils/stepDefinitionsFormatter.js +1 -2
  30. package/changelog.md +5 -0
  31. package/npm-shrinkwrap.json +5777 -3934
  32. package/package.json +5 -4
package/.eslintrc.js CHANGED
@@ -22,6 +22,6 @@ module.exports = {
22
22
  "sourceType": "module"
23
23
  },
24
24
  "rules": {
25
- "indent": ["error", 2]
25
+ "indent": ["error", 2, { "SwitchCase": 1 }]
26
26
  }
27
27
  }
@@ -15,7 +15,7 @@ var _loadConfig = require("../../playwright/loadConfig");
15
15
  const logger = new _logger.Logger({
16
16
  verbose: true
17
17
  });
18
- const envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
18
+ const envCommand = exports.envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
19
19
  logger.log(`Playwright-bdd environment info:\n`);
20
20
  logger.log(`platform: ${process.platform}`);
21
21
  logger.log(`node: ${process.version}`);
@@ -24,7 +24,6 @@ const envCommand = new _commander.Command('env').description('Prints environment
24
24
  showPackageVersion('@cucumber/cucumber');
25
25
  showPlaywrightConfigPath(opts.config);
26
26
  });
27
- exports.envCommand = envCommand;
28
27
  function showPackageVersion(packageName) {
29
28
  const version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
30
29
  logger.log(`${packageName}: v${version}`);
@@ -16,7 +16,7 @@ var _gen = require("../../gen");
16
16
  const logger = new _logger.Logger({
17
17
  verbose: true
18
18
  });
19
- const exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
19
+ const exportCommand = exports.exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
20
20
  const {
21
21
  resolvedConfigFile
22
22
  } = await (0, _loadConfig.loadConfig)(opts.config);
@@ -25,7 +25,6 @@ const exportCommand = new _commander.Command('export').description('Prints all s
25
25
  (0, _test.assertConfigsCount)(configs);
26
26
  await showStepsForConfigs(configs);
27
27
  });
28
- exports.exportCommand = exportCommand;
29
28
  async function showStepsForConfigs(configs) {
30
29
  // here we don't need workers (as in test command) because if some step files
31
30
  // are already in node cache, we collected them.
@@ -17,13 +17,12 @@ var _config = require("../../config");
17
17
  var _options = require("../options");
18
18
  var _exit = require("../../utils/exit");
19
19
  const GEN_WORKER_PATH = _path.default.resolve(__dirname, '..', 'worker.js');
20
- const testCommand = new _commander.Command('test').description('Generate Playwright test files from Gherkin documents').addOption(_options.configOption).option('--tags <expression>', `Tags expression to filter scenarios for generation`).option('--verbose', `Verbose mode (default: ${Boolean(_config.defaults.verbose)})`).action(async opts => {
20
+ const testCommand = exports.testCommand = new _commander.Command('test').description('Generate Playwright test files from Gherkin documents').addOption(_options.configOption).option('--tags <expression>', `Tags expression to filter scenarios for generation`).option('--verbose', `Verbose mode (default: ${Boolean(_config.defaults.verbose)})`).action(async opts => {
21
21
  await (0, _loadConfig.loadConfig)(opts.config);
22
22
  const configs = readConfigsFromEnv();
23
23
  mergeCliOptions(configs, opts);
24
24
  await generateFilesForConfigs(configs);
25
25
  });
26
- exports.testCommand = testCommand;
27
26
  function readConfigsFromEnv() {
28
27
  const configs = Object.values((0, _env.getEnvConfigs)());
29
28
  assertConfigsCount(configs);
@@ -10,11 +10,10 @@ var _commander = require("commander");
10
10
  * Config option moved to separate file as it used in test run.
11
11
  */
12
12
 
13
- const configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
13
+ const configOption = exports.configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
14
14
  /**
15
15
  * Helper used in test run to detect config location.
16
16
  */
17
- exports.configOption = configOption;
18
17
  function getCliConfigPath() {
19
18
  return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
20
19
  }
@@ -15,14 +15,13 @@ var _utils = require("../utils");
15
15
  * BDD Config.
16
16
  */
17
17
 
18
- const defaults = {
18
+ const defaults = exports.defaults = {
19
19
  outputDir: '.features-gen',
20
20
  verbose: false,
21
21
  examplesTitleFormat: 'Example #<_index_>',
22
22
  publishQuiet: true,
23
23
  quotes: 'double'
24
24
  };
25
- exports.defaults = defaults;
26
25
  function defineBddConfig(inputConfig) {
27
26
  const config = getConfig(inputConfig);
28
27
  // In main process store config in env to be accessible by workers
@@ -12,11 +12,7 @@ Object.defineProperty(exports, "Fixture", {
12
12
  exports.When = exports.Then = exports.Step = exports.Given = void 0;
13
13
  var _poms = require("./stepDefinitions/decorators/poms");
14
14
  var _steps = require("./stepDefinitions/decorators/steps");
15
- const Given = (0, _steps.createStepDecorator)('Given');
16
- exports.Given = Given;
17
- const When = (0, _steps.createStepDecorator)('When');
18
- exports.When = When;
19
- const Then = (0, _steps.createStepDecorator)('Then');
20
- exports.Then = Then;
21
- const Step = (0, _steps.createStepDecorator)('Unknown');
22
- exports.Step = Step;
15
+ const Given = exports.Given = (0, _steps.createStepDecorator)('Given');
16
+ const When = exports.When = (0, _steps.createStepDecorator)('When');
17
+ const Then = exports.Then = (0, _steps.createStepDecorator)('Then');
18
+ const Step = exports.Step = (0, _steps.createStepDecorator)('Unknown');
@@ -28,10 +28,7 @@ function getPlaywrightRoot() {
28
28
  // See: https://github.com/microsoft/playwright/pull/26946
29
29
  const playwrightTestRoot = (0, _utils.resolvePackageRoot)('@playwright/test');
30
30
  const libDir = _path.default.join(playwrightTestRoot, 'lib');
31
-
32
- // Recently added functionality in playwright
33
- const playwrightDir = _path.default.join(playwrightTestRoot, 'node_modules', 'playwright');
34
- playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : playwrightDir;
31
+ playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : (0, _utils.resolvePackageRoot)('playwright');
35
32
  }
36
33
  return playwrightRoot;
37
34
  }
@@ -13,7 +13,7 @@ var _config = require("../config");
13
13
  var _env = require("../config/env");
14
14
  var _steps = require("../stepDefinitions/decorators/steps");
15
15
  var _dir = require("../config/dir");
16
- const test = _test.test.extend({
16
+ const test = exports.test = _test.test.extend({
17
17
  $bddWorldBase: async ({
18
18
  $tags,
19
19
  $test
@@ -101,7 +101,6 @@ const test = _test.test.extend({
101
101
  // eslint-disable-next-line
102
102
  $test: ({}, use) => use(_test.test)
103
103
  });
104
- exports.test = test;
105
104
  const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
106
105
  function isBddAutoInjectFixture(name) {
107
106
  return BDD_AUTO_INJECT_FIXTURES.includes(name);
@@ -25,5 +25,4 @@ class Logger {
25
25
  }
26
26
  // default logger
27
27
  exports.Logger = Logger;
28
- const logger = new Logger();
29
- exports.logger = logger;
28
+ const logger = exports.logger = new Logger();
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _babelJest = _interopRequireDefault(require("babel-jest"));
9
- var _default = _babelJest.default.createTransformer({
9
+ var _default = exports.default = _babelJest.default.createTransformer({
10
10
  presets: [require.resolve('@babel/preset-env'), require.resolve('@babel/preset-react')],
11
11
  plugins: [require.resolve('babel-plugin-transform-dynamic-import')]
12
- });
13
- exports.default = _default;
12
+ });
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _fileUtils = require("../../utils/fileUtils");
10
+ var _logger = require("../../utils/logger");
11
+ var _readConfigFile = require("./readConfigFile");
12
+ function clearCaches() {
13
+ try {
14
+ const {
15
+ authFilePath,
16
+ reportPath
17
+ } = (0, _readConfigFile.generateConfigFromFile)();
18
+ authFilePath.split('/').pop();
19
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Deleting auth files present in ${authFilePath}`);
20
+ (0, _fileUtils.deleteFolder)(_path.default.resolve(process.cwd(), authFilePath));
21
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Deleting Playwright report ${reportPath}`);
22
+ (0, _fileUtils.deleteFolder)(reportPath);
23
+ (0, _fileUtils.deleteFolder)(_path.default.resolve(process.cwd(), 'uat', '.features-gen'));
24
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Caches Cleared');
25
+ } catch (err) {
26
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Error While clearing cookies');
27
+ }
28
+ }
29
+ var _default = exports.default = clearCaches;
@@ -4,5 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CUSTOM_COMMANDS = void 0;
7
- const CUSTOM_COMMANDS = ['mode', 'tags'];
8
- exports.CUSTOM_COMMANDS = CUSTOM_COMMANDS;
7
+ const CUSTOM_COMMANDS = exports.CUSTOM_COMMANDS = ['mode', 'tags'];
@@ -55,7 +55,7 @@ const {
55
55
  bddMode
56
56
  } = (0, _readConfigFile.generateConfigFromFile)();
57
57
  let base = bddMode ? _bddFramework.test : _test.test;
58
- const test = base.extend({
58
+ const test = exports.test = base.extend({
59
59
  page: async ({
60
60
  page
61
61
  }, use) => {
@@ -101,7 +101,6 @@ const test = base.extend({
101
101
  },
102
102
  ...additionalPages
103
103
  });
104
- exports.test = test;
105
104
  const {
106
105
  Given,
107
106
  When,
@@ -11,10 +11,10 @@ exports.isUserConfigFileAvailable = isUserConfigFileAvailable;
11
11
  var _fs = require("fs");
12
12
  var _path = _interopRequireDefault(require("path"));
13
13
  var _logger = require("../../utils/logger");
14
- const fileName = 'uat.config.js';
15
- exports.fileName = fileName;
14
+ const fileName = exports.fileName = 'uat.config.js';
16
15
  function getDefaultConfig() {
17
16
  return {
17
+ headless: false,
18
18
  browsers: ['Chrome'],
19
19
  trace: false,
20
20
  video: false,
@@ -31,7 +31,10 @@ function getDefaultConfig() {
31
31
  },
32
32
  debug: false,
33
33
  mode: 'dev',
34
- additionalPages: {}
34
+ additionalPages: {},
35
+ featureFilesFolder: 'feature-files',
36
+ stepDefinitionsFolder: 'steps',
37
+ testIdAttribute: 'data-testid'
35
38
  };
36
39
  }
37
40
  function combineDefaultConfigWithUserConfig(userConfiguration) {
@@ -39,7 +42,7 @@ function combineDefaultConfigWithUserConfig(userConfiguration) {
39
42
  let configurationObj = {};
40
43
  Object.keys(userConfiguration).forEach(configKey => {
41
44
  let configValue = userConfiguration[configKey];
42
- if (configValue && configValue !== null) {
45
+ if (configValue !== null && configValue !== undefined) {
43
46
  configurationObj[configKey] = configValue;
44
47
  } else if (defaultConfig[configKey]) {
45
48
  configurationObj[configKey] = defaultConfig[configKey];
@@ -67,7 +70,7 @@ function combineDefaultConfigWithUserConfig(userConfiguration) {
67
70
  * @property {boolean} video - video for test cases,
68
71
  * @property {boolean} debug - debug mode
69
72
  * @property {string} mode: mode in which the test cases needs to run
70
- * @property {boolean} isAuthMode - Auth Mode
73
+ * @property {boolean} isAuthMode - Auth Mode. config whether authentication step needed before running test cases
71
74
  * @property {string} authFilePath - File Path where the cookies stored
72
75
  * @property {any} browsers: List of browsers
73
76
  * @property {string} openReportOn: default Option value (never, on-failure and always)
@@ -78,7 +81,8 @@ function combineDefaultConfigWithUserConfig(userConfiguration) {
78
81
  * @property {Object} additionalPages: custom pages configuration
79
82
  * @property {string} featureFilesFolder: folder name under which feature-files will be placed. Default is feature-files
80
83
  * @property {string} stepDefinitionsFolder: folder name under which step implementations will be placed. Default is steps
81
- * @property {viewportConfig} viewport: viewport configuration
84
+ * @property {viewportConfig} viewport: viewport configuration for the browser. Default is { width: 1280, height: 720 }
85
+ * @property {string} testIdAttribute: Change the default data-testid attribute. configure what attribute to search while calling getByTestId
82
86
  */
83
87
 
84
88
  /**
@@ -22,7 +22,8 @@ const {
22
22
  authFilePath,
23
23
  viewport,
24
24
  featureFilesFolder,
25
- stepDefinitionsFolder
25
+ stepDefinitionsFolder,
26
+ testIdAttribute
26
27
  } = (0, _readConfigFile.generateConfigFromFile)();
27
28
  const projects = (0, _configUtils.getProjects)({
28
29
  browsers,
@@ -36,6 +37,18 @@ const testDir = (0, _configUtils.getTestDir)(bddMode, process.cwd(), {
36
37
  featureFilesFolder,
37
38
  stepDefinitionsFolder
38
39
  });
40
+ const testOptions = (0, _configUtils.getTestUseOptions)({
41
+ trace,
42
+ video,
43
+ viewport,
44
+ testIdAttribute
45
+ });
46
+
47
+ /**
48
+ * Playwright configuration object
49
+ *
50
+ * @returns {import('@playwright/test').PlaywrightTestConfig}
51
+ */
39
52
  function getPlaywrightConfig() {
40
53
  return {
41
54
  testDir,
@@ -47,21 +60,12 @@ function getPlaywrightConfig() {
47
60
  reporter: [['html', {
48
61
  outputFolder: reportPath,
49
62
  open: openReportOn
50
- }]],
63
+ }], ['list'], ['./custom-reporter.js']],
51
64
  timeout: testTimeout,
52
65
  expect: {
53
66
  timeout: expectTimeout
54
67
  },
55
- use: {
56
- viewport,
57
- trace: trace ? 'on' : 'off',
58
- video: video ? {
59
- mode: 'on',
60
- size: {
61
- ...viewport
62
- }
63
- } : 'off'
64
- },
68
+ use: testOptions,
65
69
  projects: isAuthMode ? [{
66
70
  name: 'setup',
67
71
  testMatch: /.*\.setup\.js/,
@@ -69,5 +73,4 @@ function getPlaywrightConfig() {
69
73
  }, ...projects] : [...projects]
70
74
  };
71
75
  }
72
- var _default = (0, _test.defineConfig)(getPlaywrightConfig());
73
- exports.default = _default;
76
+ var _default = exports.default = (0, _test.defineConfig)(getPlaywrightConfig());
@@ -6,10 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.getProjects = getProjects;
8
8
  exports.getTestDir = getTestDir;
9
+ exports.getTestUseOptions = getTestUseOptions;
9
10
  var _test = require("@playwright/test");
10
11
  var _path = _interopRequireDefault(require("path"));
11
12
  var _readConfigFile = require("../readConfigFile");
12
13
  var _bddFramework = require("../../../bdd-framework");
14
+ /**
15
+ ** Playwright project configuration
16
+ * @returns {import('@playwright/test').Project}
17
+ */
13
18
  function getBrowserConfig({
14
19
  browserName,
15
20
  isAuthMode,
@@ -81,6 +86,12 @@ function getBrowserConfig({
81
86
  return false;
82
87
  }
83
88
  }
89
+
90
+ /**
91
+ *
92
+ * @param {*} param0
93
+ * @returns {import('@playwright/test').Project[]}
94
+ */
84
95
  function getProjects({
85
96
  browsers,
86
97
  isAuthMode,
@@ -108,4 +119,23 @@ function getTestDir(bddMode, cwd, {
108
119
  outputDir: _path.default.join(cwd, 'uat', '.features-gen'),
109
120
  publish: true
110
121
  }) : _path.default.join(cwd, 'uat');
122
+ }
123
+ function getTestUseOptions({
124
+ viewport,
125
+ trace,
126
+ video,
127
+ testIdAttribute
128
+ }) {
129
+ let defaultTestuseOptions = {
130
+ viewport,
131
+ testIdAttribute,
132
+ trace: trace ? 'on' : 'off',
133
+ video: video ? {
134
+ mode: 'on',
135
+ size: {
136
+ ...viewport
137
+ }
138
+ } : 'off'
139
+ };
140
+ return defaultTestuseOptions;
111
141
  }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _readline = _interopRequireDefault(require("readline"));
10
+ var _fileUtils = require("../../../utils/fileUtils");
11
+ var _readConfigFile = require("../readConfigFile");
12
+ var _logger = require("../../../utils/logger");
13
+ class JSONSummaryReporter {
14
+ constructor() {
15
+ this.durationInMS = -1;
16
+ this.passed = [];
17
+ this.skipped = [];
18
+ this.failed = [];
19
+ this.warned = [];
20
+ this.interrupted = [];
21
+ this.timedOut = [];
22
+ this.flakey = [];
23
+ this.status = 'unknown';
24
+ this.startedAt = 0;
25
+ this._open = (0, _readConfigFile.generateConfigFromFile)().openReportOn;
26
+ }
27
+ onBegin() {
28
+ this.startedAt = Date.now();
29
+ }
30
+ onTestEnd(test, result) {
31
+ const title = [];
32
+ const fileName = [];
33
+ let clean = true;
34
+ for (const s of test.titlePath()) {
35
+ if (s === '' && clean) {
36
+ continue;
37
+ }
38
+ clean = false;
39
+ title.push(s);
40
+ if (s.includes('.ts') || s.includes('.js')) {
41
+ fileName.push(s);
42
+ }
43
+ }
44
+ // This will publish the file name + line number test begins on
45
+ const z = `${fileName[0]}:${test.location.line}:${test.location.column}`;
46
+ // Using the t variable in the push will push a full test name + test description
47
+ const t = title.join(' > ');
48
+ // Set the status
49
+ const status = !['passed', 'skipped'].includes(result.status) && t.includes('@warn') ? 'warned' : result.status;
50
+ // Logic to push the results into the correct array
51
+ if (result.status === 'passed' && result.retry >= 1) {
52
+ this.flakey.push(z);
53
+ } else {
54
+ this[status].push(z);
55
+ }
56
+ this[status].push(z);
57
+ }
58
+ onEnd(result) {
59
+ this.durationInMS = Date.now() - this.startedAt;
60
+ this.status = result.status;
61
+ // removing duplicate tests from passed array
62
+ this.passed = this.passed.filter((element, index) => {
63
+ return this.passed.indexOf(element) === index;
64
+ });
65
+ // removing duplicate tests from the failed array
66
+ this.failed = this.failed.filter((element, index) => {
67
+ if (!this.passed.includes(element)) {
68
+ return this.failed.indexOf(element) === index;
69
+ }
70
+ });
71
+ // removing duplicate tests from the skipped array
72
+ this.skipped = this.skipped.filter((element, index) => {
73
+ return this.skipped.indexOf(element) === index;
74
+ });
75
+ // removing duplicate tests from the timedOut array
76
+ this.timedOut = this.timedOut.filter((element, index) => {
77
+ return this.timedOut.indexOf(element) === index;
78
+ });
79
+ // removing duplicate tests from the interrupted array
80
+ this.interrupted = this.interrupted.filter((element, index) => {
81
+ return this.interrupted.indexOf(element) === index;
82
+ });
83
+ // fs.writeFileSync('./summary.json', JSON.stringify(this, null, ' '));
84
+ let {
85
+ reportPath
86
+ } = (0, _readConfigFile.generateConfigFromFile)();
87
+ (0, _fileUtils.writeFileContents)(_path.default.join(reportPath, './', 'test-summary.json'), JSON.stringify(this, null, ' '));
88
+ }
89
+ onExit() {
90
+ const shouldClearLastLine = this._open !== 'always' || this._open !== 'on-failure';
91
+ if (shouldClearLastLine) {
92
+ /**Below code is to replace the playwright default report commond with abstraction tool command */
93
+ _readline.default.moveCursor(process.stdout, 0, -2); // up two line
94
+ _readline.default.clearLine(process.stdout, 1); // from cursor to end
95
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'npx ZDTestingFramework report or npm run uat-report');
96
+ return;
97
+ }
98
+ }
99
+ }
100
+ var _default = exports.default = JSONSummaryReporter;
@@ -66,7 +66,6 @@ function runPlaywright(command, args) {
66
66
  });
67
67
  childProcessForRunningPlaywright.on('exit', (code, signal) => {
68
68
  if (code !== 0) {
69
- _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
70
69
  reject(`Child Process Exited with Code ${code} and Signal ${signal}`);
71
70
  } else {
72
71
  _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Test Ran Successfully');
@@ -74,11 +73,11 @@ function runPlaywright(command, args) {
74
73
  }
75
74
  });
76
75
  process.on('exit', () => {
77
- //childProcessForRunningPlaywright.kill();
76
+ childProcessForRunningPlaywright.kill();
78
77
  reject('Terminating Playwright Process...');
79
78
  });
80
79
  process.on('SIGINT', () => {
81
- //childProcessForRunningPlaywright.kill();
80
+ childProcessForRunningPlaywright.kill();
82
81
  reject('Cleaning up...');
83
82
  });
84
83
  });
@@ -108,5 +107,4 @@ function main() {
108
107
  process.exit();
109
108
  });
110
109
  }
111
- var _default = main;
112
- exports.default = _default;
110
+ var _default = exports.default = main;
package/build/index.d.ts CHANGED
@@ -1,5 +1,58 @@
1
- import { Given, Then, When, Step, expect, test, createBdd } from './core/playwright/index';
1
+ import { expect, test } from './core/playwright/index';
2
2
  import { fireEvent, render } from '@testing-library/react';
3
+ import {
4
+ PlaywrightTestArgs,
5
+ PlaywrightTestOptions,
6
+ PlaywrightWorkerArgs,
7
+ PlaywrightWorkerOptions,
8
+ TestType
9
+ } from '@playwright/test';
3
10
 
4
- export { Given, Then, When, Step, expect, test, createBdd, fireEvent, render };
5
- export * from '@playwright/test/types/test';
11
+ export type KeyValue = { [key: string]: any };
12
+
13
+ export type BuiltInFixturesWorker = PlaywrightWorkerArgs &
14
+ PlaywrightWorkerOptions;
15
+ export type BuiltInFixtures = PlaywrightTestArgs &
16
+ PlaywrightTestOptions &
17
+ BuiltInFixturesWorker;
18
+
19
+ export type FixturesArg<T extends KeyValue = {}, W extends KeyValue = {}> = T &
20
+ W &
21
+ BuiltInFixtures;
22
+
23
+ export declare let hasCustomTest: boolean;
24
+
25
+ export declare function createBdd<
26
+ T extends KeyValue = BuiltInFixtures,
27
+ W extends KeyValue = BuiltInFixturesWorker,
28
+ World
29
+ >(
30
+ customTest?: TestType<T, W> | null,
31
+ _CustomWorld?: new (...args: any[]) => World
32
+ ): {
33
+ Given: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
34
+ When: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
35
+ Then: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
36
+ And: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
37
+ But: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
38
+ Step: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
39
+ Before: any;
40
+ After: any;
41
+ BeforeAll: any;
42
+ AfterAll: any;
43
+ };
44
+
45
+ type StepFunctionFixturesArg<
46
+ T extends KeyValue,
47
+ W extends KeyValue
48
+ > = FixturesArg<T, W>;
49
+ type StepFunction<T extends KeyValue, W extends KeyValue> = (
50
+ fixtures: StepFunctionFixturesArg<T, W>,
51
+ ...args: any[]
52
+ ) => unknown;
53
+
54
+ const { Given, Then, When, Step, And, But } = createBdd();
55
+
56
+ export { Given, Then, When, Step, And, But, expect, test, createBdd };
57
+
58
+ export * from '@playwright/test/types/test';
package/build/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.When = exports.Then = exports.Step = exports.Given = void 0;
6
+ exports.When = exports.Then = exports.Step = exports.Given = exports.But = exports.And = void 0;
7
7
  Object.defineProperty(exports, "createBdd", {
8
8
  enumerable: true,
9
9
  get: function () {
@@ -45,4 +45,6 @@ const {
45
45
  exports.Step = Step;
46
46
  exports.When = When;
47
47
  exports.Then = Then;
48
- exports.Given = Given;
48
+ exports.Given = Given;
49
+ const And = exports.And = Then;
50
+ const But = exports.But = Then;
package/build/lib/cli.js CHANGED
@@ -7,6 +7,8 @@ var _codegen = _interopRequireDefault(require("../core/playwright/codegen"));
7
7
  var _logger = require("../utils/logger");
8
8
  var _setupProject = _interopRequireDefault(require("../setup-folder-structure/setupProject"));
9
9
  var _parser = require("../parser/parser");
10
+ var _clearCaches = _interopRequireDefault(require("../core/playwright/clear-caches"));
11
+ var _helper = _interopRequireDefault(require("../setup-folder-structure/helper"));
10
12
  // import createJestRunner from '../core/jest/runner/jest-runner';
11
13
 
12
14
  const [,, option, ...otherOptions] = process.argv;
@@ -46,9 +48,16 @@ switch (option) {
46
48
  (0, _parser.generateSpecCodeForFeatureFile)(otherOptions);
47
49
  break;
48
50
  }
51
+ case 'clearCaches':
52
+ {
53
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Clearing caches...');
54
+ (0, _clearCaches.default)();
55
+ break;
56
+ }
57
+ case 'help':
49
58
  default:
50
59
  {
51
- _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Supported Commands test and report');
60
+ (0, _helper.default)();
52
61
  break;
53
62
  }
54
63
  }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _commander = require("commander");
9
+ var _fs = require("fs");
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _logger = require("../utils/logger");
12
+ function helpercmd() {
13
+ const packageJsonPath = _path.default.resolve(process.cwd(), './package.json');
14
+ if ((0, _fs.existsSync)(packageJsonPath) && process.argv.includes('--version')) {
15
+ const {
16
+ dependencies
17
+ } = require(packageJsonPath);
18
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `zohodesk/testinglibrary Version : ${dependencies['@zohodesk/testinglibrary']}`);
19
+ _commander.program.version(dependencies['@zohodesk/testinglibrary'] || '0.0.1');
20
+ return;
21
+ }
22
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Supported Commands...');
23
+ _commander.program.name('npx ZDTestingFramework');
24
+ _commander.program.command('test').description('This command is used to execute tests');
25
+ _commander.program.command('init').description('This command will initialize Project');
26
+ _commander.program.command('report').description('This command is used to generate a report summarizing the results of executed tests.');
27
+ _commander.program.command('codegen').description('This command is used to assist developer to write test case');
28
+ _commander.program.option('--headed', 'Run tests with a headed browser.');
29
+ _commander.program.option('--debug', 'This command is used to initiate a debugging session');
30
+ _commander.program.option('--tags', 'Run specific test case with mentioned tags (Usage: -- --tags="@live")');
31
+ _commander.program.option('--workers', 'Specify number of workers to run the test case parallely (Usage: -- --workers=2)');
32
+ _commander.program.parse(process.argv);
33
+ }
34
+ var _default = exports.default = helpercmd;