@zohodesk/testinglibrary 0.1.12-experimental → 0.1.16-experimental

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.
@@ -7,13 +7,13 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = generateCodegen;
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
  var _rootPath = require("../../utils/rootPath");
10
- var _spawnInheritChild = require("./spawnInheritChild");
10
+ var _runCommand = require("./runCommand");
11
11
  function generateCodegen() {
12
12
  const domainUrl = process.argv.slice(3);
13
13
  const playwrightPath = _path.default.resolve((0, _rootPath.getExecutableBinaryPath)('playwright'));
14
14
  const command = playwrightPath;
15
15
  const args = ['codegen'].concat(domainUrl);
16
- (0, _spawnInheritChild.spawnInheritChild)(command, args, {
16
+ (0, _runCommand.runCommand)(command, args, {
17
17
  exitOnSuccess: true,
18
18
  killOnParentExit: true
19
19
  });
@@ -15,7 +15,7 @@ var _fileUtils = require("../../../../utils/fileUtils");
15
15
  var _logger = require("../../../../utils/logger");
16
16
  /* eslint-disable no-console */
17
17
 
18
- const authCookieNameKeys = ['iamadt', 'iambdt'];
18
+ const authCookieNameKeys = ['iamadt', 'iambdt', 'iamsdt'];
19
19
  function getAuthFileDirectory() {
20
20
  const {
21
21
  uatDirectory
@@ -9,7 +9,7 @@ var _path = _interopRequireDefault(require("path"));
9
9
  var _rootPath = require("../../../utils/rootPath");
10
10
  var _readConfigFile = require("../readConfigFile");
11
11
  var _configConstants = _interopRequireDefault(require("../constants/configConstants"));
12
- var _spawnInheritChild = require("../spawnInheritChild");
12
+ var _runCommand = require("../runCommand");
13
13
  var _Reporter = _interopRequireDefault(require("./Reporter"));
14
14
  // The framework reporters live next to the playwright configs, they are resolved
15
15
  // from here because this module no longer sits in the same folder as them.
@@ -49,7 +49,7 @@ class PlaywrightReporter extends _Reporter.default {
49
49
  reportPath: htmlPath
50
50
  } = (0, _readConfigFile.generateConfigFromFile)();
51
51
  const args = ['show-report', htmlPath].concat(userArgs);
52
- (0, _spawnInheritChild.spawnInheritChild)(command, args, {
52
+ (0, _runCommand.runCommand)(command, args, {
53
53
  exitOnSuccess: true,
54
54
  killOnParentExit: true
55
55
  });
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
- var _path = _interopRequireDefault(require("path"));
9
- var _configConstants = _interopRequireDefault(require("../constants/configConstants"));
10
7
  // Playwright accepts the shard as `current/total`. Anything else (a bare `--shard`
11
8
  // flag, for instance) is not a shard run and must keep the default reporters.
12
9
  const SHARD_PATTERN = /^\d+\/\d+$/;
@@ -16,8 +13,9 @@ const REPORTER_TYPES = {
16
13
  };
17
14
 
18
15
  /**
19
- * Base of the report modes. Every mode exposes `getType()` and `getReporter(config)`,
20
- * `merge()` is implemented by the shard mode alone.
16
+ * Base of the report modes. Every mode exposes `getType()` and `getReporter(config)`.
17
+ * `merge()` dispatches through the reporter factory so the CLI does not import a
18
+ * concrete reporter.
21
19
  */
22
20
  class Reporter {
23
21
  static get TYPES() {
@@ -26,9 +24,6 @@ class Reporter {
26
24
  static isShardedRun(shard) {
27
25
  return typeof shard === 'string' && SHARD_PATTERN.test(shard);
28
26
  }
29
- static getBlobReportDir(stage) {
30
- return _path.default.join(process.cwd(), _configConstants.default.TEST_SLICE_FOLDER, stage, 'blob-report');
31
- }
32
27
 
33
28
  /**
34
29
  * Resolves the report mode to use for a run.
@@ -59,7 +54,7 @@ class Reporter {
59
54
  throw new Error('getType() has to be implemented by the reporter');
60
55
  }
61
56
  static merge() {
62
- throw new Error('merge() is supported by the shard reporter alone');
57
+ return Reporter.getReporterClass(Reporter.TYPES.SHARD).merge();
63
58
  }
64
59
  }
65
60
  exports.default = Reporter;
@@ -11,12 +11,16 @@ var _logger = require("../../../utils/logger");
11
11
  var _rootPath = require("../../../utils/rootPath");
12
12
  var _ConfigurationHelper = require("../configuration/ConfigurationHelper");
13
13
  var _UserArgs = _interopRequireDefault(require("../configuration/UserArgs"));
14
- var _spawnInheritChild = require("../spawnInheritChild");
14
+ var _configConstants = _interopRequireDefault(require("../constants/configConstants"));
15
+ var _runCommand = require("../runCommand");
15
16
  var _Reporter = _interopRequireDefault(require("./Reporter"));
16
17
  class ShardReporter extends _Reporter.default {
17
18
  static getType() {
18
19
  return _Reporter.default.TYPES.SHARD;
19
20
  }
21
+ static getBlobReportDir(stage) {
22
+ return _path.default.join(process.cwd(), _configConstants.default.TEST_SLICE_FOLDER, stage, 'blob-report');
23
+ }
20
24
 
21
25
  /**
22
26
  * A shard only records its results as a blob. The report files are written once
@@ -29,7 +33,7 @@ class ShardReporter extends _Reporter.default {
29
33
  shard
30
34
  }) {
31
35
  return [['blob', {
32
- outputDir: _Reporter.default.getBlobReportDir(stage),
36
+ outputDir: ShardReporter.getBlobReportDir(stage),
33
37
  fileName: `report-${shard.replace('/', '-')}.zip`
34
38
  }], ['list']];
35
39
  }
@@ -39,7 +43,7 @@ class ShardReporter extends _Reporter.default {
39
43
  // child reads it back through getRunStage() while loading merge-config.js.
40
44
  const stage = _UserArgs.default.parseToObject(process.argv.slice(2)).stage || (0, _ConfigurationHelper.getRunStage)();
41
45
  process.env.stage = stage;
42
- const blobReportDir = _Reporter.default.getBlobReportDir(stage);
46
+ const blobReportDir = ShardReporter.getBlobReportDir(stage);
43
47
  if (!(0, _fs.existsSync)(blobReportDir)) {
44
48
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `No blob reports found at ${blobReportDir} for stage "${stage}". Run the tests with --shard first (Usage: -- --shard=1/4)`);
45
49
  process.exit(1);
@@ -49,7 +53,7 @@ class ShardReporter extends _Reporter.default {
49
53
  const command = playwrightPath;
50
54
  const configPath = _path.default.resolve(__dirname, '../', 'setup', 'merge-config.js');
51
55
  const args = ['merge-reports', blobReportDir, '--config', require.resolve(configPath)];
52
- (0, _spawnInheritChild.spawnInheritChild)(command, args, {
56
+ (0, _runCommand.runCommand)(command, args, {
53
57
  successMessage: 'Blob Reports Merged Successfully',
54
58
  exitOnSuccess: true
55
59
  });
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.spawnInheritChild = spawnInheritChild;
6
+ exports.runCommand = runCommand;
7
7
  var _child_process = require("child_process");
8
8
  var _logger = require("../../utils/logger");
9
- function spawnInheritChild(command, args, options = {}) {
9
+ function runCommand(command, args, options = {}) {
10
10
  const {
11
11
  successMessage,
12
12
  failureMessage,
@@ -5,7 +5,7 @@ var _readConfigFile = require("../readConfigFile");
5
5
  var _rootPath = require("../../../utils/rootPath");
6
6
  var _path = _interopRequireDefault(require("path"));
7
7
  var _logger = require("../../../utils/logger");
8
- var _spawnInheritChild = require("../spawnInheritChild");
8
+ var _runCommand = require("../runCommand");
9
9
  var _RunnerHelper = _interopRequireDefault(require("./RunnerHelper"));
10
10
  var _Runner = _interopRequireDefault(require("./Runner"));
11
11
  var _commonUtils = require("../../../utils/commonUtils");
@@ -63,7 +63,7 @@ class SpawnRunner extends _Runner.default {
63
63
  beforeArgs.push('--tags');
64
64
  beforeArgs.push(tagArgs);
65
65
  }
66
- return (0, _spawnInheritChild.spawnInheritChild)(beforeCommand, beforeArgs, {
66
+ return (0, _runCommand.runCommand)(beforeCommand, beforeArgs, {
67
67
  successMessage: 'Feature Files Processed Successfully',
68
68
  failureMessage: code => `BddGen exited with code ${code}`
69
69
  });
@@ -84,7 +84,7 @@ class SpawnRunner extends _Runner.default {
84
84
  const command = playwrightPath;
85
85
  const configPath = (0, _readConfigFile.isUserConfigFileAvailable)() ? _path.default.resolve(__dirname, '../', 'setup', 'config-creator.js') : _path.default.resolve('../', '../', '../', '../', 'playwrightConfig.js');
86
86
  const args = ['test', '--config', require.resolve(configPath)].concat(playwrightArgs);
87
- return (0, _spawnInheritChild.spawnInheritChild)(command, args, {
87
+ return (0, _runCommand.runCommand)(command, args, {
88
88
  successMessage: 'Test Ran Successfully',
89
89
  killOnParentExit: true
90
90
  });
@@ -183,7 +183,7 @@ const extractMergedSteps = (rootDir, step) => ({
183
183
  ...(step.location && {
184
184
  snippet: formSnippet(rootDir, step.location)
185
185
  }),
186
- ...(step.steps && step.steps.length > 0 && {
186
+ ...(step.steps && step.steps.length > 0 && step.error && {
187
187
  steps: step.steps.map(subStep => extractMergedSteps(rootDir, subStep))
188
188
  })
189
189
  });
@@ -10,7 +10,7 @@ var _path = _interopRequireDefault(require("path"));
10
10
  var _envInitializer = require("./env-initializer");
11
11
  var _readConfigFile = require("./readConfigFile");
12
12
  var _rootPath = require("../../utils/rootPath");
13
- var _spawnInheritChild = require("./spawnInheritChild");
13
+ var _runCommand = require("./runCommand");
14
14
  var _tagProcessor = _interopRequireDefault(require("./tagProcessor"));
15
15
  var _ConfigurationHelper = require("./configuration/ConfigurationHelper");
16
16
  var _Configuration = _interopRequireDefault(require("./configuration/Configuration"));
@@ -25,7 +25,7 @@ function runPreprocessing(tagArgs, configPath) {
25
25
  beforeArgs.push('--tags');
26
26
  beforeArgs.push(tagArgs);
27
27
  }
28
- return (0, _spawnInheritChild.spawnInheritChild)(beforeCommand, beforeArgs, {
28
+ return (0, _runCommand.runCommand)(beforeCommand, beforeArgs, {
29
29
  successMessage: 'Feature Files Processed Successfully',
30
30
  failureMessage: code => `BddGen exited with code ${code}`
31
31
  });
package/build/lib/cli.js CHANGED
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  var _testRunner = _interopRequireDefault(require("../core/playwright/test-runner"));
5
5
  var _unitTestingFramework = require("@zohodesk/unit-testing-framework");
6
6
  var _PlaywrightReporter = _interopRequireDefault(require("../core/playwright/reporter/PlaywrightReporter"));
7
- var _ShardReporter = _interopRequireDefault(require("../core/playwright/reporter/ShardReporter"));
7
+ var _Reporter = _interopRequireDefault(require("../core/playwright/reporter/Reporter"));
8
8
  var _UnitReporter = _interopRequireDefault(require("../core/playwright/reporter/UnitReporter"));
9
9
  var _codegen = _interopRequireDefault(require("../core/playwright/codegen"));
10
10
  var _logger = require("../utils/logger");
@@ -59,7 +59,7 @@ switch (option) {
59
59
  case 'merge-reports':
60
60
  {
61
61
  _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Merging Shard Reports...');
62
- _ShardReporter.default.merge();
62
+ _Reporter.default.merge();
63
63
  break;
64
64
  }
65
65
  case 'ut-report':
@@ -3,7 +3,7 @@
3
3
  var _events = require("events");
4
4
  var _child_process = require("child_process");
5
5
  var _logger = require("../../../../utils/logger");
6
- var _spawnInheritChild = require("../../../../core/playwright/spawnInheritChild");
6
+ var _runCommand = require("../../../../core/playwright/runCommand");
7
7
  jest.mock('child_process');
8
8
  jest.mock('../../../../utils/logger', () => ({
9
9
  __esModule: true,
@@ -14,7 +14,7 @@ jest.mock('../../../../utils/logger', () => ({
14
14
  INFO_TYPE: 'info'
15
15
  }
16
16
  }));
17
- describe('spawnInheritChild', () => {
17
+ describe('runCommand', () => {
18
18
  let childProcess;
19
19
  let processHandlers;
20
20
  let processOnSpy;
@@ -35,7 +35,7 @@ describe('spawnInheritChild', () => {
35
35
  processExitSpy.mockRestore();
36
36
  });
37
37
  it('should spawn the child with the parent stdio and environment', () => {
38
- (0, _spawnInheritChild.spawnInheritChild)('playwright', ['test']);
38
+ (0, _runCommand.runCommand)('playwright', ['test']);
39
39
  expect(_child_process.spawn).toHaveBeenCalledWith('playwright', ['test'], {
40
40
  stdio: 'inherit',
41
41
  env: {
@@ -44,7 +44,7 @@ describe('spawnInheritChild', () => {
44
44
  });
45
45
  });
46
46
  it('should resolve and log the success message when the child exits cleanly', async () => {
47
- const promise = (0, _spawnInheritChild.spawnInheritChild)('playwright', ['test'], {
47
+ const promise = (0, _runCommand.runCommand)('playwright', ['test'], {
48
48
  successMessage: 'Test Ran Successfully'
49
49
  });
50
50
  childProcess.emit('exit', 0, null);
@@ -52,12 +52,12 @@ describe('spawnInheritChild', () => {
52
52
  expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.SUCCESS_TYPE, 'Test Ran Successfully');
53
53
  });
54
54
  it('should reject with the default message when the child exits with a failure', async () => {
55
- const promise = (0, _spawnInheritChild.spawnInheritChild)('playwright', ['test']);
55
+ const promise = (0, _runCommand.runCommand)('playwright', ['test']);
56
56
  childProcess.emit('exit', 1, 'SIGTERM');
57
57
  await expect(promise).rejects.toBe('Child Process Exited with Code 1 and Signal SIGTERM');
58
58
  });
59
59
  it('should reject with the caller message when bddgen exits with a failure', async () => {
60
- const promise = (0, _spawnInheritChild.spawnInheritChild)('node', ['bddgen'], {
60
+ const promise = (0, _runCommand.runCommand)('node', ['bddgen'], {
61
61
  failureMessage: code => `BddGen exited with code ${code}`
62
62
  });
63
63
  childProcess.emit('exit', 2, null);
@@ -65,18 +65,18 @@ describe('spawnInheritChild', () => {
65
65
  });
66
66
  it('should reject when the child fails to spawn', async () => {
67
67
  const error = new Error('spawn ENOENT');
68
- const promise = (0, _spawnInheritChild.spawnInheritChild)('playwright', ['test']);
68
+ const promise = (0, _runCommand.runCommand)('playwright', ['test']);
69
69
  childProcess.emit('error', error);
70
70
  await expect(promise).rejects.toBe(error);
71
71
  expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.FAILURE_TYPE, error);
72
72
  });
73
73
  it('should not listen on the parent process unless the caller asks for it', () => {
74
- (0, _spawnInheritChild.spawnInheritChild)('node', ['bddgen']);
74
+ (0, _runCommand.runCommand)('node', ['bddgen']);
75
75
  expect(processHandlers.exit).toBeUndefined();
76
76
  expect(processHandlers.SIGINT).toBeUndefined();
77
77
  });
78
78
  it('should kill the child and reject when the run is interrupted', async () => {
79
- const promise = (0, _spawnInheritChild.spawnInheritChild)('playwright', ['test'], {
79
+ const promise = (0, _runCommand.runCommand)('playwright', ['test'], {
80
80
  killOnParentExit: true
81
81
  });
82
82
  processHandlers.SIGINT();
@@ -84,7 +84,7 @@ describe('spawnInheritChild', () => {
84
84
  expect(childProcess.kill).toHaveBeenCalled();
85
85
  });
86
86
  it('should kill the child and reject when the parent exits', async () => {
87
- const promise = (0, _spawnInheritChild.spawnInheritChild)('playwright', ['test'], {
87
+ const promise = (0, _runCommand.runCommand)('playwright', ['test'], {
88
88
  killOnParentExit: true
89
89
  });
90
90
  processHandlers.exit();
@@ -92,7 +92,7 @@ describe('spawnInheritChild', () => {
92
92
  expect(childProcess.kill).toHaveBeenCalled();
93
93
  });
94
94
  it('should log the failure and exit when a CLI child exits with a failure', () => {
95
- (0, _spawnInheritChild.spawnInheritChild)('playwright', ['merge-reports'], {
95
+ (0, _runCommand.runCommand)('playwright', ['merge-reports'], {
96
96
  exitOnSuccess: true
97
97
  });
98
98
  childProcess.emit('exit', 1, 'SIGTERM');
@@ -100,7 +100,7 @@ describe('spawnInheritChild', () => {
100
100
  expect(processExitSpy).toHaveBeenCalledWith(1);
101
101
  });
102
102
  it('should not listen for SIGINT unless the caller owns the child lifetime', () => {
103
- (0, _spawnInheritChild.spawnInheritChild)('playwright', ['merge-reports'], {
103
+ (0, _runCommand.runCommand)('playwright', ['merge-reports'], {
104
104
  successMessage: 'Blob Reports Merged Successfully',
105
105
  exitOnSuccess: true
106
106
  });
@@ -108,14 +108,14 @@ describe('spawnInheritChild', () => {
108
108
  expect(processHandlers.exit).toBeUndefined();
109
109
  });
110
110
  it('should exit with the child when the caller owns the process lifetime', () => {
111
- (0, _spawnInheritChild.spawnInheritChild)('playwright', ['show-report'], {
111
+ (0, _runCommand.runCommand)('playwright', ['show-report'], {
112
112
  exitOnSuccess: true
113
113
  });
114
114
  childProcess.emit('exit', 0, null);
115
115
  expect(processExitSpy).toHaveBeenCalledWith(0);
116
116
  });
117
117
  it('should propagate the child exit code when merge-reports completes', () => {
118
- (0, _spawnInheritChild.spawnInheritChild)('playwright', ['merge-reports'], {
118
+ (0, _runCommand.runCommand)('playwright', ['merge-reports'], {
119
119
  successMessage: 'Blob Reports Merged Successfully',
120
120
  exitOnSuccess: true
121
121
  });
@@ -125,7 +125,7 @@ describe('spawnInheritChild', () => {
125
125
  });
126
126
  it('should log spawn errors without rejecting a CLI command', () => {
127
127
  const error = new Error('spawn ENOENT');
128
- (0, _spawnInheritChild.spawnInheritChild)('playwright', ['codegen'], {
128
+ (0, _runCommand.runCommand)('playwright', ['codegen'], {
129
129
  exitOnSuccess: true
130
130
  });
131
131
  childProcess.emit('error', error);
@@ -133,7 +133,7 @@ describe('spawnInheritChild', () => {
133
133
  expect(processExitSpy).not.toHaveBeenCalled();
134
134
  });
135
135
  it('should kill the child on SIGINT and on the parent exit', () => {
136
- (0, _spawnInheritChild.spawnInheritChild)('playwright', ['show-report'], {
136
+ (0, _runCommand.runCommand)('playwright', ['show-report'], {
137
137
  exitOnSuccess: true,
138
138
  killOnParentExit: true
139
139
  });
@@ -35,6 +35,22 @@ describe('storeFilteredStorageState', () => {
35
35
  await (0, _checkAuthCookies.storeFilteredStorageState)(pageWithCookies(cookies), authFile);
36
36
  expect(writtenCookies()).toEqual(cookies);
37
37
  });
38
+ it('keeps the "__Secure-iamsdt" cookie', async () => {
39
+ const cookies = [{
40
+ name: '__Secure-iamsdt',
41
+ value: 's'
42
+ }];
43
+ await (0, _checkAuthCookies.storeFilteredStorageState)(pageWithCookies(cookies), authFile);
44
+ expect(writtenCookies()).toEqual(cookies);
45
+ });
46
+ it('keeps the "__Secure-cseziamsdt" cookie', async () => {
47
+ const cookies = [{
48
+ name: '__Secure-cseziamsdt',
49
+ value: 'cs'
50
+ }];
51
+ await (0, _checkAuthCookies.storeFilteredStorageState)(pageWithCookies(cookies), authFile);
52
+ expect(writtenCookies()).toEqual(cookies);
53
+ });
38
54
  it('keeps a cookie whose name has the key as a substring, not just an exact match', async () => {
39
55
  const cookies = [{
40
56
  name: '_cseziamadt',
@@ -72,9 +88,15 @@ describe('storeFilteredStorageState', () => {
72
88
  }, {
73
89
  name: '_iambdt',
74
90
  value: 'b'
91
+ }, {
92
+ name: '__Secure-iamsdt',
93
+ value: 's'
75
94
  }, {
76
95
  name: 'JSESSIONID',
77
96
  value: 'y'
97
+ }, {
98
+ name: '__Secure-cseziamsdt',
99
+ value: 'cs'
78
100
  }];
79
101
  await (0, _checkAuthCookies.storeFilteredStorageState)(pageWithCookies(cookies), authFile);
80
102
  expect(writtenCookies()).toEqual([{
@@ -83,6 +105,12 @@ describe('storeFilteredStorageState', () => {
83
105
  }, {
84
106
  name: '_iambdt',
85
107
  value: 'b'
108
+ }, {
109
+ name: '__Secure-iamsdt',
110
+ value: 's'
111
+ }, {
112
+ name: '__Secure-cseziamsdt',
113
+ value: 'cs'
86
114
  }]);
87
115
  });
88
116
  it('writes to the given authFile path', async () => {