@zohodesk/testinglibrary 0.0.1 → 0.0.2
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.
- package/README.md +17 -17
- package/bin/cli.js +1 -1
- package/bin/postinstall.js +15 -15
- package/changelog.md +11 -0
- package/jest.config.js +63 -63
- package/npm-shrinkwrap.json +5772 -0
- package/package.json +31 -31
- package/playwright.config.js +112 -112
- package/src/core/jest/preprocessor/jsPreprocessor.js +9 -9
- package/src/core/jest/runner/jest-runner.js +44 -45
- package/src/core/jest/setup/index.js +165 -165
- package/src/core/playwright/codegen.js +60 -61
- package/src/core/playwright/custom-commands.js +2 -2
- package/src/core/playwright/env-initializer.js +23 -23
- package/src/core/playwright/index.js +81 -80
- package/src/core/playwright/readConfigFile.js +17 -17
- package/src/core/playwright/report-generator.js +42 -43
- package/src/core/playwright/test-runner.js +64 -64
- package/src/index.js +8 -8
- package/src/lib/cli.js +34 -34
- package/src/utils/cliArgsToObject.js +34 -34
- package/src/utils/getFilePath.js +8 -8
- package/src/utils/logger.js +27 -27
- package/src/utils/rootPath.js +50 -18
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
//$Id$//
|
|
2
|
-
import TestUtils from 'react-dom/test-utils';
|
|
3
|
-
import { expect } from '@jest/globals'
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import ReactDOM from 'react-dom';
|
|
7
|
-
import '@testing-library/jest-dom/extend-expect';
|
|
8
|
-
// let mockDomain = 'htt' + 'p://zoho.com';
|
|
9
|
-
// const { document } = new JSDOM('').window;
|
|
10
|
-
// global.document = document;
|
|
11
|
-
// global.window = document.defaultView;
|
|
12
|
-
// global.navigator = global.window.navigator;
|
|
13
|
-
// global.localStorage = global.sessionStorage = {
|
|
14
|
-
// getItem(key) {
|
|
15
|
-
// return this[key];
|
|
16
|
-
// },
|
|
17
|
-
// setItem(key, value) {
|
|
18
|
-
// if (value.length > 100) {
|
|
19
|
-
// throw new Error('Data size is too exceeded');
|
|
20
|
-
// }
|
|
21
|
-
// this[key] = value;
|
|
22
|
-
// },
|
|
23
|
-
// removeItem(key) {
|
|
24
|
-
// delete this[key];
|
|
25
|
-
// },
|
|
26
|
-
// clear() {
|
|
27
|
-
// let keys = ['getItem', 'setItem', 'removeItem', 'clear'];
|
|
28
|
-
// for (let key in this) {
|
|
29
|
-
// if (keys.indexOf(key) === -1) {
|
|
30
|
-
// delete this[key];
|
|
31
|
-
// }
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
|
-
// };
|
|
35
|
-
// global.ZE_Init = {};
|
|
36
|
-
// global.String.prototype.contains = function (text) {
|
|
37
|
-
// return this.indexOf(text) != -1;
|
|
38
|
-
// };
|
|
39
|
-
// global.TestUtils = TestUtils;
|
|
40
|
-
// // let xmlReq = XMLHttpRequest;
|
|
41
|
-
// // window.XMLHttpRequest = function () {
|
|
42
|
-
// // let xmlReqCopy = new xmlReq();
|
|
43
|
-
// // let originalOpen = xmlReqCopy.open;
|
|
44
|
-
// // xmlReqCopy.open = function () {
|
|
45
|
-
// // if (arguments[1].indexOf('http') != 0) {
|
|
46
|
-
// // arguments[1] = mockDomain + arguments[1];
|
|
47
|
-
// // }
|
|
48
|
-
// // return originalOpen.apply(this, arguments);
|
|
49
|
-
// // };
|
|
50
|
-
// // return xmlReqCopy;
|
|
51
|
-
// // };
|
|
52
|
-
|
|
53
|
-
// TestUtils.scryRenderedComponentsWithTestid = function (dom, name) {
|
|
54
|
-
// let componentList = TestUtils.findAllInRenderedTree(dom, (i, j) => {
|
|
55
|
-
// if (TestUtils.isDOMComponent(i)) {
|
|
56
|
-
// let val = i.getAttribute('data-id');
|
|
57
|
-
// if (typeof val !== 'undefined' && val == name) {
|
|
58
|
-
// return true;
|
|
59
|
-
// }
|
|
60
|
-
// return false;
|
|
61
|
-
// }
|
|
62
|
-
// });
|
|
63
|
-
// return componentList;
|
|
64
|
-
// };
|
|
65
|
-
|
|
66
|
-
// TestUtils.findRenderedComponentsWithTestid = function (dom, name) {
|
|
67
|
-
// let list = TestUtils.scryRenderedComponentsWithTestid(dom, name);
|
|
68
|
-
// if (list.length !== 1) {
|
|
69
|
-
// throw new Error(
|
|
70
|
-
// `Did not find exactly one match (found: ${list.length}) ` +
|
|
71
|
-
// `for data-id:${name}`
|
|
72
|
-
// );
|
|
73
|
-
// }
|
|
74
|
-
// return list[0];
|
|
75
|
-
// };
|
|
76
|
-
|
|
77
|
-
// global.render = function (Component, props) {
|
|
78
|
-
// const renderedDOM = TestUtils.renderIntoDocument(<Component {...props} />);
|
|
79
|
-
// return {
|
|
80
|
-
// props,
|
|
81
|
-
// renderedDOM
|
|
82
|
-
// };
|
|
83
|
-
// };
|
|
84
|
-
|
|
85
|
-
// global.setup = function (Component, props, state) {
|
|
86
|
-
// let router = {
|
|
87
|
-
// router: {
|
|
88
|
-
// push() { },
|
|
89
|
-
// createHref(ob) {
|
|
90
|
-
// return ob.pathname;
|
|
91
|
-
// },
|
|
92
|
-
// isActive() {
|
|
93
|
-
// return true;
|
|
94
|
-
// },
|
|
95
|
-
// replace() { },
|
|
96
|
-
// go() { },
|
|
97
|
-
// goBack() { },
|
|
98
|
-
// goForward() { },
|
|
99
|
-
// setRouteLeaveHook() { },
|
|
100
|
-
// getState() { }
|
|
101
|
-
// },
|
|
102
|
-
// store: {
|
|
103
|
-
// getState() {
|
|
104
|
-
// return state;
|
|
105
|
-
// }
|
|
106
|
-
// }
|
|
107
|
-
// };
|
|
108
|
-
// // var store = {
|
|
109
|
-
// // store:{
|
|
110
|
-
// // getState:function(){return state;}
|
|
111
|
-
// // }
|
|
112
|
-
// // }
|
|
113
|
-
// var Component = higherComponent(Component, router);
|
|
114
|
-
// const renderedDOM = TestUtils.renderIntoDocument(
|
|
115
|
-
// <Component {...props} />,
|
|
116
|
-
// router
|
|
117
|
-
// );
|
|
118
|
-
// return {
|
|
119
|
-
// props,
|
|
120
|
-
// renderedDOM
|
|
121
|
-
// };
|
|
122
|
-
// };
|
|
123
|
-
|
|
124
|
-
// function higherComponent(ActualComponent, context) {
|
|
125
|
-
// if (context) {
|
|
126
|
-
// class HigherComponent extends React.Component {
|
|
127
|
-
// constructor() {
|
|
128
|
-
// super();
|
|
129
|
-
// }
|
|
130
|
-
|
|
131
|
-
// getChildContext() {
|
|
132
|
-
// return context;
|
|
133
|
-
// }
|
|
134
|
-
|
|
135
|
-
// render() {
|
|
136
|
-
// return <ActualComponent {...this.props} />;
|
|
137
|
-
// }
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
|
-
// HigherComponent.childContextTypes = {
|
|
141
|
-
// router: PropTypes.any,
|
|
142
|
-
// store: PropTypes.any
|
|
143
|
-
// };
|
|
144
|
-
|
|
145
|
-
// return HigherComponent;
|
|
146
|
-
// }
|
|
147
|
-
// return ActualComponent;
|
|
148
|
-
// }
|
|
149
|
-
// global.window.matchMedia =
|
|
150
|
-
// window.matchMedia ||
|
|
151
|
-
// function () {
|
|
152
|
-
// return {
|
|
153
|
-
// matches: false,
|
|
154
|
-
// addListener() { },
|
|
155
|
-
// removeListener() { }
|
|
156
|
-
// };
|
|
157
|
-
// };
|
|
158
|
-
// // global.renderHTML = function(comp) {
|
|
159
|
-
// // return ReactDOM.findDOMNode(comp);
|
|
160
|
-
// // };
|
|
161
|
-
|
|
162
|
-
// global.TestUtils = TestUtils;
|
|
163
|
-
// global.getI18NValue = function (inp) {
|
|
164
|
-
// return inp;
|
|
165
|
-
// };
|
|
1
|
+
//$Id$//
|
|
2
|
+
import TestUtils from 'react-dom/test-utils';
|
|
3
|
+
import { expect } from '@jest/globals'
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import ReactDOM from 'react-dom';
|
|
7
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
8
|
+
// let mockDomain = 'htt' + 'p://zoho.com';
|
|
9
|
+
// const { document } = new JSDOM('').window;
|
|
10
|
+
// global.document = document;
|
|
11
|
+
// global.window = document.defaultView;
|
|
12
|
+
// global.navigator = global.window.navigator;
|
|
13
|
+
// global.localStorage = global.sessionStorage = {
|
|
14
|
+
// getItem(key) {
|
|
15
|
+
// return this[key];
|
|
16
|
+
// },
|
|
17
|
+
// setItem(key, value) {
|
|
18
|
+
// if (value.length > 100) {
|
|
19
|
+
// throw new Error('Data size is too exceeded');
|
|
20
|
+
// }
|
|
21
|
+
// this[key] = value;
|
|
22
|
+
// },
|
|
23
|
+
// removeItem(key) {
|
|
24
|
+
// delete this[key];
|
|
25
|
+
// },
|
|
26
|
+
// clear() {
|
|
27
|
+
// let keys = ['getItem', 'setItem', 'removeItem', 'clear'];
|
|
28
|
+
// for (let key in this) {
|
|
29
|
+
// if (keys.indexOf(key) === -1) {
|
|
30
|
+
// delete this[key];
|
|
31
|
+
// }
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
// };
|
|
35
|
+
// global.ZE_Init = {};
|
|
36
|
+
// global.String.prototype.contains = function (text) {
|
|
37
|
+
// return this.indexOf(text) != -1;
|
|
38
|
+
// };
|
|
39
|
+
// global.TestUtils = TestUtils;
|
|
40
|
+
// // let xmlReq = XMLHttpRequest;
|
|
41
|
+
// // window.XMLHttpRequest = function () {
|
|
42
|
+
// // let xmlReqCopy = new xmlReq();
|
|
43
|
+
// // let originalOpen = xmlReqCopy.open;
|
|
44
|
+
// // xmlReqCopy.open = function () {
|
|
45
|
+
// // if (arguments[1].indexOf('http') != 0) {
|
|
46
|
+
// // arguments[1] = mockDomain + arguments[1];
|
|
47
|
+
// // }
|
|
48
|
+
// // return originalOpen.apply(this, arguments);
|
|
49
|
+
// // };
|
|
50
|
+
// // return xmlReqCopy;
|
|
51
|
+
// // };
|
|
52
|
+
|
|
53
|
+
// TestUtils.scryRenderedComponentsWithTestid = function (dom, name) {
|
|
54
|
+
// let componentList = TestUtils.findAllInRenderedTree(dom, (i, j) => {
|
|
55
|
+
// if (TestUtils.isDOMComponent(i)) {
|
|
56
|
+
// let val = i.getAttribute('data-id');
|
|
57
|
+
// if (typeof val !== 'undefined' && val == name) {
|
|
58
|
+
// return true;
|
|
59
|
+
// }
|
|
60
|
+
// return false;
|
|
61
|
+
// }
|
|
62
|
+
// });
|
|
63
|
+
// return componentList;
|
|
64
|
+
// };
|
|
65
|
+
|
|
66
|
+
// TestUtils.findRenderedComponentsWithTestid = function (dom, name) {
|
|
67
|
+
// let list = TestUtils.scryRenderedComponentsWithTestid(dom, name);
|
|
68
|
+
// if (list.length !== 1) {
|
|
69
|
+
// throw new Error(
|
|
70
|
+
// `Did not find exactly one match (found: ${list.length}) ` +
|
|
71
|
+
// `for data-id:${name}`
|
|
72
|
+
// );
|
|
73
|
+
// }
|
|
74
|
+
// return list[0];
|
|
75
|
+
// };
|
|
76
|
+
|
|
77
|
+
// global.render = function (Component, props) {
|
|
78
|
+
// const renderedDOM = TestUtils.renderIntoDocument(<Component {...props} />);
|
|
79
|
+
// return {
|
|
80
|
+
// props,
|
|
81
|
+
// renderedDOM
|
|
82
|
+
// };
|
|
83
|
+
// };
|
|
84
|
+
|
|
85
|
+
// global.setup = function (Component, props, state) {
|
|
86
|
+
// let router = {
|
|
87
|
+
// router: {
|
|
88
|
+
// push() { },
|
|
89
|
+
// createHref(ob) {
|
|
90
|
+
// return ob.pathname;
|
|
91
|
+
// },
|
|
92
|
+
// isActive() {
|
|
93
|
+
// return true;
|
|
94
|
+
// },
|
|
95
|
+
// replace() { },
|
|
96
|
+
// go() { },
|
|
97
|
+
// goBack() { },
|
|
98
|
+
// goForward() { },
|
|
99
|
+
// setRouteLeaveHook() { },
|
|
100
|
+
// getState() { }
|
|
101
|
+
// },
|
|
102
|
+
// store: {
|
|
103
|
+
// getState() {
|
|
104
|
+
// return state;
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
// };
|
|
108
|
+
// // var store = {
|
|
109
|
+
// // store:{
|
|
110
|
+
// // getState:function(){return state;}
|
|
111
|
+
// // }
|
|
112
|
+
// // }
|
|
113
|
+
// var Component = higherComponent(Component, router);
|
|
114
|
+
// const renderedDOM = TestUtils.renderIntoDocument(
|
|
115
|
+
// <Component {...props} />,
|
|
116
|
+
// router
|
|
117
|
+
// );
|
|
118
|
+
// return {
|
|
119
|
+
// props,
|
|
120
|
+
// renderedDOM
|
|
121
|
+
// };
|
|
122
|
+
// };
|
|
123
|
+
|
|
124
|
+
// function higherComponent(ActualComponent, context) {
|
|
125
|
+
// if (context) {
|
|
126
|
+
// class HigherComponent extends React.Component {
|
|
127
|
+
// constructor() {
|
|
128
|
+
// super();
|
|
129
|
+
// }
|
|
130
|
+
|
|
131
|
+
// getChildContext() {
|
|
132
|
+
// return context;
|
|
133
|
+
// }
|
|
134
|
+
|
|
135
|
+
// render() {
|
|
136
|
+
// return <ActualComponent {...this.props} />;
|
|
137
|
+
// }
|
|
138
|
+
// }
|
|
139
|
+
|
|
140
|
+
// HigherComponent.childContextTypes = {
|
|
141
|
+
// router: PropTypes.any,
|
|
142
|
+
// store: PropTypes.any
|
|
143
|
+
// };
|
|
144
|
+
|
|
145
|
+
// return HigherComponent;
|
|
146
|
+
// }
|
|
147
|
+
// return ActualComponent;
|
|
148
|
+
// }
|
|
149
|
+
// global.window.matchMedia =
|
|
150
|
+
// window.matchMedia ||
|
|
151
|
+
// function () {
|
|
152
|
+
// return {
|
|
153
|
+
// matches: false,
|
|
154
|
+
// addListener() { },
|
|
155
|
+
// removeListener() { }
|
|
156
|
+
// };
|
|
157
|
+
// };
|
|
158
|
+
// // global.renderHTML = function(comp) {
|
|
159
|
+
// // return ReactDOM.findDOMNode(comp);
|
|
160
|
+
// // };
|
|
161
|
+
|
|
162
|
+
// global.TestUtils = TestUtils;
|
|
163
|
+
// global.getI18NValue = function (inp) {
|
|
164
|
+
// return inp;
|
|
165
|
+
// };
|
|
@@ -1,61 +1,60 @@
|
|
|
1
|
-
const { spawn } = require('child_process')
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
// await page.
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
module.exports = generateCodegen;
|
|
1
|
+
const { spawn } = require('child_process')
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { chromium } = require('@playwright/test');
|
|
4
|
+
const { Logger } = require('../../utils/logger');
|
|
5
|
+
const { getExecutableBinaryPath } = require('../../utils/rootPath');
|
|
6
|
+
|
|
7
|
+
const userArgs = process.argv.slice(3);
|
|
8
|
+
|
|
9
|
+
const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));
|
|
10
|
+
const command = playwrightPath;
|
|
11
|
+
|
|
12
|
+
const args = ['codegen'].concat(userArgs);
|
|
13
|
+
|
|
14
|
+
function generateCodegen() {
|
|
15
|
+
const childProcess = spawn(command, args, { stdio: 'inherit' });
|
|
16
|
+
|
|
17
|
+
childProcess.on('error', (error) => {
|
|
18
|
+
Logger.log(Logger.FAILURE_TYPE, error);
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
childProcess.on('exit', (code, signal) => {
|
|
22
|
+
Logger.log(Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
|
|
23
|
+
|
|
24
|
+
process.exit();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
process.on('exit', () => {
|
|
28
|
+
Logger.log(Logger.INFO_TYPE, 'Terminating Playwright Process...');
|
|
29
|
+
//childProcess.kill();
|
|
30
|
+
return;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
process.on('SIGINT', () => {
|
|
34
|
+
Logger.log(Logger.INFO_TYPE, 'Cleaning up...');
|
|
35
|
+
//childProcess.kill();
|
|
36
|
+
process.exit();
|
|
37
|
+
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// Another way to record. Below way will load the url in autheticated state if present
|
|
43
|
+
// function generateCodegen() {
|
|
44
|
+
// (async () => {
|
|
45
|
+
// // Make sure to run headed.
|
|
46
|
+
// const browser = await chromium.launch({ headless: false });
|
|
47
|
+
|
|
48
|
+
// // Setup context however you like.
|
|
49
|
+
// const context = await browser.newContext({ storageState: path.resolve(process.cwd(), 'playwright/.auth/user.json') });
|
|
50
|
+
// await context.route('**/*', route => route.continue());
|
|
51
|
+
|
|
52
|
+
// // Pause the page, and start recording manually.
|
|
53
|
+
// const page = await context.newPage();
|
|
54
|
+
// console.log(userArgs.join(''));
|
|
55
|
+
// await page.goto(`https://${userArgs.join('')}`);
|
|
56
|
+
// await page.pause();
|
|
57
|
+
// })();
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
module.exports = generateCodegen;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
CUSTOM_COMMANDS: ['mode']
|
|
1
|
+
module.exports = {
|
|
2
|
+
CUSTOM_COMMANDS: ['mode']
|
|
3
3
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const { readFileSync } = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function initializeEnvConfig(mode = 'dev') {
|
|
7
|
-
try {
|
|
8
|
-
const configFile = readFileSync(path.resolve(process.cwd(), './uat/config.json'));
|
|
9
|
-
|
|
10
|
-
const configJSON = JSON.parse(configFile);
|
|
11
|
-
process.env.mode = mode;
|
|
12
|
-
for (const key in configJSON[mode]) {
|
|
13
|
-
process.env[key] = configJSON[mode][key];
|
|
14
|
-
}
|
|
15
|
-
} catch (err) {
|
|
16
|
-
throw new Error('Config File Not Exists. Please provide a config file to intiailize the environment variables')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
module.exports = {
|
|
23
|
-
initializeEnvConfig
|
|
1
|
+
const { readFileSync } = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function initializeEnvConfig(mode = 'dev') {
|
|
7
|
+
try {
|
|
8
|
+
const configFile = readFileSync(path.resolve(process.cwd(), './uat/config.json'));
|
|
9
|
+
|
|
10
|
+
const configJSON = JSON.parse(configFile);
|
|
11
|
+
process.env.mode = mode;
|
|
12
|
+
for (const key in configJSON[mode]) {
|
|
13
|
+
process.env[key] = configJSON[mode][key];
|
|
14
|
+
}
|
|
15
|
+
} catch (err) {
|
|
16
|
+
throw new Error('Config File Not Exists. Please provide a config file to intiailize the environment variables')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
initializeEnvConfig
|
|
24
24
|
};
|