@thinkwise/testwise 0.1.97 → 0.2.0-beta.22

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 (202) hide show
  1. package/Testwise.ts +7 -9
  2. package/artifact-builder/ArtifactManager.ts +33 -0
  3. package/artifact-builder/InterfaceGenerator.ts +165 -0
  4. package/artifact-builder/ModelDataBuilder.ts +194 -0
  5. package/artifact-builder/ModelDataRefiner.ts +39 -0
  6. package/artifact-builder/SchemaGenerator.ts +131 -0
  7. package/artifact-builder/ScreenInterfaceRefiner.ts +154 -0
  8. package/artifact-builder/SelectorBuilder.ts +82 -0
  9. package/artifact-builder/SubjectComponentGenerator.ts +186 -0
  10. package/artifact-builder/SubjectGenerator.ts +332 -0
  11. package/artifact-builder/SubjectRegistration.ts +131 -0
  12. package/artifact-builder/helpers/DataRetriever.ts +64 -0
  13. package/artifact-builder/helpers/NamingHandler.ts +182 -0
  14. package/artifact-builder/helpers/Stopwatch.ts +13 -0
  15. package/artifact-builder/helpers/index.ts +3 -0
  16. package/artifact-builder/index.ts +9 -0
  17. package/components/{actionbar/Actionbar.ts → action-bar/ActionBar.ts} +12 -12
  18. package/components/{actionbar/ActionbarObjects.ts → action-bar/ActionBarObjects.ts} +4 -4
  19. package/components/{actionbar → action-bar}/CustomActionBar.ts +2 -2
  20. package/components/index.ts +3 -4
  21. package/components/tab/DetailTabPage.ts +20 -0
  22. package/components/tab/{DetailTabObjects.ts → DetailTabPageObjects.ts} +1 -1
  23. package/components/tab/Tab.ts +31 -5
  24. package/components/tab/TabObjects.ts +15 -3
  25. package/dist/Testwise.js +5 -1
  26. package/dist/Testwise.js.map +1 -1
  27. package/dist/artifact-builder/ArtifactManager.d.ts +8 -0
  28. package/dist/artifact-builder/ArtifactManager.js +27 -0
  29. package/dist/artifact-builder/ArtifactManager.js.map +1 -0
  30. package/dist/artifact-builder/InterfaceGenerator.d.ts +15 -0
  31. package/dist/artifact-builder/InterfaceGenerator.js +122 -0
  32. package/dist/artifact-builder/InterfaceGenerator.js.map +1 -0
  33. package/dist/artifact-builder/ModelDataBuilder.d.ts +2 -0
  34. package/dist/artifact-builder/ModelDataBuilder.js +141 -0
  35. package/dist/artifact-builder/ModelDataBuilder.js.map +1 -0
  36. package/dist/artifact-builder/ModelDataRefiner.d.ts +4 -0
  37. package/dist/artifact-builder/ModelDataRefiner.js +28 -0
  38. package/dist/artifact-builder/ModelDataRefiner.js.map +1 -0
  39. package/dist/artifact-builder/SchemaGenerator.d.ts +12 -0
  40. package/dist/artifact-builder/SchemaGenerator.js +102 -0
  41. package/dist/artifact-builder/SchemaGenerator.js.map +1 -0
  42. package/dist/artifact-builder/ScreenInterfaceRefiner.d.ts +15 -0
  43. package/dist/artifact-builder/ScreenInterfaceRefiner.js +120 -0
  44. package/dist/artifact-builder/ScreenInterfaceRefiner.js.map +1 -0
  45. package/dist/artifact-builder/SelectorBuilder.d.ts +13 -0
  46. package/dist/artifact-builder/SelectorBuilder.js +69 -0
  47. package/dist/artifact-builder/SelectorBuilder.js.map +1 -0
  48. package/dist/artifact-builder/SubjectComponentGenerator.d.ts +23 -0
  49. package/dist/artifact-builder/SubjectComponentGenerator.js +136 -0
  50. package/dist/artifact-builder/SubjectComponentGenerator.js.map +1 -0
  51. package/dist/artifact-builder/SubjectGenerator.d.ts +27 -0
  52. package/dist/artifact-builder/SubjectGenerator.js +235 -0
  53. package/dist/artifact-builder/SubjectGenerator.js.map +1 -0
  54. package/dist/artifact-builder/SubjectRegistration.d.ts +21 -0
  55. package/dist/artifact-builder/SubjectRegistration.js +95 -0
  56. package/dist/artifact-builder/SubjectRegistration.js.map +1 -0
  57. package/dist/artifact-builder/helpers/DataRetriever.d.ts +12 -0
  58. package/dist/artifact-builder/helpers/DataRetriever.js +52 -0
  59. package/dist/artifact-builder/helpers/DataRetriever.js.map +1 -0
  60. package/dist/artifact-builder/helpers/NamingHandler.d.ts +24 -0
  61. package/dist/artifact-builder/helpers/NamingHandler.js +147 -0
  62. package/dist/artifact-builder/helpers/NamingHandler.js.map +1 -0
  63. package/dist/artifact-builder/helpers/Stopwatch.d.ts +5 -0
  64. package/dist/artifact-builder/helpers/Stopwatch.js +13 -0
  65. package/dist/artifact-builder/helpers/Stopwatch.js.map +1 -0
  66. package/dist/artifact-builder/helpers/index.d.ts +3 -0
  67. package/dist/artifact-builder/helpers/index.js +4 -0
  68. package/dist/artifact-builder/helpers/index.js.map +1 -0
  69. package/dist/artifact-builder/index.d.ts +9 -0
  70. package/dist/artifact-builder/index.js +10 -0
  71. package/dist/artifact-builder/index.js.map +1 -0
  72. package/dist/components/{actionbar/Actionbar.d.ts → action-bar/ActionBar.d.ts} +4 -4
  73. package/dist/components/{actionbar/Actionbar.js → action-bar/ActionBar.js} +9 -9
  74. package/dist/components/action-bar/ActionBar.js.map +1 -0
  75. package/dist/components/{actionbar/ActionbarObjects.d.ts → action-bar/ActionBarObjects.d.ts} +2 -2
  76. package/dist/components/{actionbar/ActionbarObjects.js → action-bar/ActionBarObjects.js} +5 -5
  77. package/dist/components/action-bar/ActionBarObjects.js.map +1 -0
  78. package/dist/components/{actionbar → action-bar}/CustomActionBar.d.ts +2 -2
  79. package/dist/components/action-bar/CustomActionBar.js +7 -0
  80. package/dist/components/action-bar/CustomActionBar.js.map +1 -0
  81. package/dist/components/index.d.ts +3 -4
  82. package/dist/components/index.js +3 -4
  83. package/dist/components/index.js.map +1 -1
  84. package/dist/components/tab/DetailTabPage.d.ts +9 -0
  85. package/dist/components/tab/DetailTabPage.js +15 -0
  86. package/dist/components/tab/DetailTabPage.js.map +1 -0
  87. package/dist/components/tab/{DetailTabObjects.d.ts → DetailTabPageObjects.d.ts} +1 -1
  88. package/dist/components/tab/{DetailTabObjects.js → DetailTabPageObjects.js} +2 -2
  89. package/dist/components/tab/DetailTabPageObjects.js.map +1 -0
  90. package/dist/components/tab/Tab.d.ts +8 -3
  91. package/dist/components/tab/Tab.js +25 -4
  92. package/dist/components/tab/Tab.js.map +1 -1
  93. package/dist/components/tab/TabObjects.d.ts +7 -2
  94. package/dist/components/tab/TabObjects.js +9 -2
  95. package/dist/components/tab/TabObjects.js.map +1 -1
  96. package/dist/enums/ElementTypes.d.ts +8 -0
  97. package/dist/enums/ElementTypes.js +10 -0
  98. package/dist/enums/ElementTypes.js.map +1 -0
  99. package/dist/helpers/PathResolver.d.ts +3 -0
  100. package/dist/helpers/PathResolver.js +26 -0
  101. package/dist/helpers/PathResolver.js.map +1 -0
  102. package/dist/helpers/index.d.ts +1 -0
  103. package/dist/helpers/index.js +1 -0
  104. package/dist/helpers/index.js.map +1 -1
  105. package/dist/index.d.ts +1 -0
  106. package/dist/index.js +1 -0
  107. package/dist/index.js.map +1 -1
  108. package/dist/interfaces/IProperty.d.ts +4 -0
  109. package/dist/interfaces/IProperty.js +2 -0
  110. package/dist/interfaces/IProperty.js.map +1 -0
  111. package/dist/interfaces/IRegisteredSubjects.d.ts +5 -0
  112. package/dist/interfaces/IRegisteredSubjects.js +2 -0
  113. package/dist/interfaces/IRegisteredSubjects.js.map +1 -0
  114. package/dist/interfaces/ISubject.d.ts +8 -0
  115. package/dist/interfaces/ISubject.js +2 -0
  116. package/dist/interfaces/ISubject.js.map +1 -0
  117. package/dist/page-extensions/SubjectProvider.d.ts +11 -0
  118. package/dist/page-extensions/SubjectProvider.js +24 -0
  119. package/dist/page-extensions/SubjectProvider.js.map +1 -0
  120. package/dist/page-extensions/SubjectRegistry.d.ts +14 -0
  121. package/dist/page-extensions/SubjectRegistry.js +14 -0
  122. package/dist/page-extensions/SubjectRegistry.js.map +1 -0
  123. package/dist/page-extensions/index.d.ts +3 -0
  124. package/dist/page-extensions/index.js +3 -0
  125. package/dist/page-extensions/index.js.map +1 -1
  126. package/dist/services/ConfigBuilder.d.ts +1 -0
  127. package/dist/services/ConfigBuilder.js +20 -1
  128. package/dist/services/ConfigBuilder.js.map +1 -1
  129. package/dist/test-artifacts/SubjectPageBase.d.ts +5 -0
  130. package/dist/test-artifacts/SubjectPageBase.js +6 -0
  131. package/dist/test-artifacts/SubjectPageBase.js.map +1 -0
  132. package/dist/test-artifacts/index.d.ts +3 -0
  133. package/dist/test-artifacts/index.js +4 -0
  134. package/dist/test-artifacts/index.js.map +1 -0
  135. package/dist/test-artifacts/screens/index.d.ts +1 -0
  136. package/dist/test-artifacts/screens/index.js +2 -0
  137. package/dist/test-artifacts/screens/index.js.map +1 -0
  138. package/dist/test-artifacts/subjects/index.d.ts +1 -0
  139. package/dist/test-artifacts/subjects/index.js +2 -0
  140. package/dist/test-artifacts/subjects/index.js.map +1 -0
  141. package/dist/types/Components.d.ts +7 -0
  142. package/dist/types/Components.js +28 -0
  143. package/dist/types/Components.js.map +1 -0
  144. package/enums/ElementTypes.ts +8 -0
  145. package/helpers/PathResolver.ts +30 -0
  146. package/helpers/index.ts +1 -0
  147. package/index.ts +1 -0
  148. package/interfaces/IProperty.ts +4 -0
  149. package/interfaces/IRegisteredSubjects.ts +5 -0
  150. package/interfaces/ISubject.ts +9 -0
  151. package/package.json +26 -8
  152. package/page-extensions/SubjectProvider.ts +41 -0
  153. package/page-extensions/SubjectRegistry.ts +30 -0
  154. package/page-extensions/index.ts +3 -0
  155. package/promptCredentials.js +124 -124
  156. package/scripts/Testwise.template.json +4 -1
  157. package/scripts/main.js +84 -11
  158. package/scripts/postinstall.js +39 -0
  159. package/scripts/setup.js +37 -34
  160. package/scripts/sync.js +102 -0
  161. package/scripts/tsconfig.template.json +1 -1
  162. package/services/ConfigBuilder.ts +25 -2
  163. package/test-artifacts/SubjectPageBase.ts +9 -0
  164. package/test-artifacts/index.ts +3 -0
  165. package/test-artifacts/screens/index.ts +0 -0
  166. package/test-artifacts/subjects/index.ts +0 -0
  167. package/tsconfig.json +1 -1
  168. package/types/Components.ts +55 -0
  169. package/components/tab/ComponentTab.ts +0 -40
  170. package/components/tab/ComponentTabObjects.ts +0 -17
  171. package/components/tab/DetailTab.ts +0 -20
  172. package/dist/Testwise.json +0 -25
  173. package/dist/bdd.d.ts +0 -6
  174. package/dist/bdd.js +0 -9
  175. package/dist/bdd.js.map +0 -1
  176. package/dist/biome.json +0 -52
  177. package/dist/components/actionbar/Actionbar.js.map +0 -1
  178. package/dist/components/actionbar/ActionbarObjects.js.map +0 -1
  179. package/dist/components/actionbar/CustomActionBar.js +0 -7
  180. package/dist/components/actionbar/CustomActionBar.js.map +0 -1
  181. package/dist/components/tab/ComponentTab.d.ts +0 -12
  182. package/dist/components/tab/ComponentTab.js +0 -31
  183. package/dist/components/tab/ComponentTab.js.map +0 -1
  184. package/dist/components/tab/ComponentTabObjects.d.ts +0 -8
  185. package/dist/components/tab/ComponentTabObjects.js +0 -11
  186. package/dist/components/tab/ComponentTabObjects.js.map +0 -1
  187. package/dist/components/tab/DetailTab.d.ts +0 -9
  188. package/dist/components/tab/DetailTab.js +0 -15
  189. package/dist/components/tab/DetailTab.js.map +0 -1
  190. package/dist/components/tab/DetailTabObjects.js.map +0 -1
  191. package/dist/helpers/TestExtensions.d.ts +0 -8
  192. package/dist/helpers/TestExtensions.js +0 -21
  193. package/dist/helpers/TestExtensions.js.map +0 -1
  194. package/dist/package-lock.json +0 -3852
  195. package/dist/package.json +0 -59
  196. package/dist/scripts/Testwise.template.json +0 -25
  197. package/dist/scripts/tsconfig.template.json +0 -12
  198. package/dist/services/ReportingService.d.ts +0 -8
  199. package/dist/services/ReportingService.js +0 -29
  200. package/dist/services/ReportingService.js.map +0 -1
  201. package/dist/tsconfig.json +0 -20
  202. package/services/ReportingService.ts +0 -37
@@ -0,0 +1,30 @@
1
+ // import type { Page } from '@playwright/test';
2
+ import type { Test } from '../types/Test.js';
3
+
4
+ export type SubjectType = {
5
+ none: unknown;
6
+ };
7
+
8
+ declare module '@playwright/test' {
9
+ interface Page {
10
+ subject: SubjectType;
11
+ }
12
+ }
13
+
14
+ export class SubjectRegistry {
15
+ private _test: Test;
16
+
17
+ constructor(test: Test) {
18
+ this._test = test.extend({
19
+ page: async ({ page }, use) => {
20
+ page.subject = {} as SubjectType;
21
+
22
+ await use(page);
23
+ }
24
+ });
25
+ }
26
+
27
+ get test() {
28
+ return this._test;
29
+ }
30
+ }
@@ -1,4 +1,7 @@
1
1
  export * from './GlobalComponents.js';
2
2
  export * from './GoToDeepLink.js';
3
3
  export * from './LoginFeatures.js';
4
+ export * from './SubjectProvider.js';
5
+ export * from './SubjectRegistry.js';
4
6
  export * from './UserSimulation.js';
7
+ export * from './WaitEventHandler.js';
@@ -1,124 +1,124 @@
1
- #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process';
3
- import { readFileSync } from 'node:fs';
4
- import process from 'node:process';
5
- import chalk from 'chalk';
6
- import prompts from 'prompts';
7
-
8
- const packageScripts = JSON.parse(readFileSync('./package.json')).scripts;
9
-
10
- function exitWithError(error) {
11
- console.log(chalk.red(error));
12
- process.exit(1);
13
- }
14
-
15
- function startTestSolution() {
16
- console.log('Now starting test solution...');
17
- spawnSync(`yarn --cwd ../ ${args.join(' ')}`, {
18
- shell: true,
19
- stdio: 'inherit'
20
- });
21
- process.exit();
22
- }
23
-
24
- const args = process.argv.slice(2);
25
-
26
- if (!args.length) {
27
- exitWithError('Error: Got too few parameters. Usage: yarn test:credentials test');
28
- }
29
-
30
- const yarnScriptToExec = args[0];
31
-
32
- if (!packageScripts[yarnScriptToExec]) {
33
- exitWithError(`Error: Given script "${yarnScriptToExec}" doesn't exist in package.json.`);
34
- }
35
-
36
- // INCOMING HACK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37
- // temp fix to be reworked when converting this file to TS
38
- import fs from 'node:fs';
39
- import path from 'node:path';
40
-
41
- const indiciumURL = (() => {
42
- try {
43
- const configPath = path.resolve(process.cwd(), './Testwise.json');
44
- const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
45
- return config.environmentSettings?.serviceUrl || '';
46
- } catch (error) {
47
- console.error('Error reading Testwise.json:', error);
48
- return '';
49
- }
50
- })();
51
-
52
- // END OF HACK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53
-
54
- if (process.env.SF_TEST_USERNAME && process.env.SF_TEST_PASSWORD) {
55
- console.log('Using SF_TEST_USERNAME and SF_TEST_PASSWORD environment variables.');
56
- startTestSolution();
57
- }
58
-
59
- const questions = [
60
- {
61
- type: 'text',
62
- name: 'username',
63
- message: 'Username:',
64
- validate: (value) => {
65
- if (!value?.length) {
66
- return 'Username is required';
67
- }
68
-
69
- if (value.toLowerCase() === 'demo') {
70
- return 'Running tests locally with demo is forbidden as it results in dataset concurrency problems';
71
- }
72
-
73
- return true;
74
- }
75
- },
76
- {
77
- type: 'invisible',
78
- name: 'password',
79
- message: 'Password:',
80
- validate: (value) => (!value?.length ? 'Password is required' : true)
81
- }
82
- ];
83
-
84
- (async () => {
85
- const credentialsResponse = await prompts(questions);
86
-
87
- if (!credentialsResponse || !credentialsResponse.username || !credentialsResponse.password) {
88
- exitWithError('Username or password was not given');
89
- }
90
-
91
- const { password, username } = credentialsResponse;
92
- const params = new URLSearchParams();
93
-
94
- params.append('UserName', username);
95
- params.append('Password', password);
96
-
97
- const fetch = (await import('node-fetch')).default;
98
- const authResponse = await fetch(`${indiciumURL}/account/api/login`, {
99
- method: 'POST',
100
- body: params
101
- });
102
-
103
- if (authResponse.status === 204) {
104
- console.log('Confirmed credentials work @', indiciumURL);
105
- } else {
106
- const confirmResponse = await prompts([
107
- {
108
- type: 'confirm',
109
- name: 'value',
110
- message: `Can't login to ${indiciumURL} with the given credentials. Continue anyways?`,
111
- initial: true
112
- }
113
- ]);
114
-
115
- if (!confirmResponse.value) {
116
- return;
117
- }
118
- }
119
-
120
- process.env.SF_TEST_USERNAME = username;
121
- process.env.SF_TEST_PASSWORD = password;
122
-
123
- startTestSolution();
124
- })();
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { readFileSync } from 'node:fs';
4
+ import process from 'node:process';
5
+ import chalk from 'chalk';
6
+ import prompts from 'prompts';
7
+
8
+ const packageScripts = JSON.parse(readFileSync('./package.json')).scripts;
9
+
10
+ function exitWithError(error) {
11
+ console.log(chalk.red(error));
12
+ process.exit(1);
13
+ }
14
+
15
+ function startTestSolution() {
16
+ console.log('Now starting test solution...');
17
+ spawnSync(`yarn --cwd ../ ${args.join(' ')}`, {
18
+ shell: true,
19
+ stdio: 'inherit'
20
+ });
21
+ process.exit();
22
+ }
23
+
24
+ const args = process.argv.slice(2);
25
+
26
+ if (!args.length) {
27
+ exitWithError('Error: Got too few parameters. Usage: yarn test:credentials test');
28
+ }
29
+
30
+ const yarnScriptToExec = args[0];
31
+
32
+ if (!packageScripts[yarnScriptToExec]) {
33
+ exitWithError(`Error: Given script "${yarnScriptToExec}" doesn't exist in package.json.`);
34
+ }
35
+
36
+ // INCOMING HACK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37
+ // temp fix to be reworked when converting this file to TS
38
+ import fs from 'node:fs';
39
+ import path from 'node:path';
40
+
41
+ const indiciumURL = (() => {
42
+ try {
43
+ const configPath = path.resolve(process.cwd(), './Testwise.json');
44
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
45
+ return config.environmentSettings?.serviceUrl || '';
46
+ } catch (error) {
47
+ console.error('Error reading Testwise.json:', error);
48
+ return '';
49
+ }
50
+ })();
51
+
52
+ // END OF HACK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53
+
54
+ if (process.env.SF_TEST_USERNAME && process.env.SF_TEST_PASSWORD) {
55
+ console.log('Using SF_TEST_USERNAME and SF_TEST_PASSWORD environment variables.');
56
+ startTestSolution();
57
+ }
58
+
59
+ const questions = [
60
+ {
61
+ type: 'text',
62
+ name: 'username',
63
+ message: 'Username:',
64
+ validate: (value) => {
65
+ if (!value?.length) {
66
+ return 'Username is required';
67
+ }
68
+
69
+ if (value.toLowerCase() === 'demo') {
70
+ return 'Running tests locally with demo is forbidden as it results in dataset concurrency problems';
71
+ }
72
+
73
+ return true;
74
+ }
75
+ },
76
+ {
77
+ type: 'invisible',
78
+ name: 'password',
79
+ message: 'Password:',
80
+ validate: (value) => (!value?.length ? 'Password is required' : true)
81
+ }
82
+ ];
83
+
84
+ (async () => {
85
+ const credentialsResponse = await prompts(questions);
86
+
87
+ if (!credentialsResponse || !credentialsResponse.username || !credentialsResponse.password) {
88
+ exitWithError('Username or password was not given');
89
+ }
90
+
91
+ const { password, username } = credentialsResponse;
92
+ const params = new URLSearchParams();
93
+
94
+ params.append('UserName', username);
95
+ params.append('Password', password);
96
+
97
+ const fetch = (await import('node-fetch')).default;
98
+ const authResponse = await fetch(`${indiciumURL}/account/api/login`, {
99
+ method: 'POST',
100
+ body: params
101
+ });
102
+
103
+ if (authResponse.status === 204) {
104
+ console.log('Confirmed credentials work @', indiciumURL);
105
+ } else {
106
+ const confirmResponse = await prompts([
107
+ {
108
+ type: 'confirm',
109
+ name: 'value',
110
+ message: `Can't login to ${indiciumURL} with the given credentials. Continue anyways?`,
111
+ initial: true
112
+ }
113
+ ]);
114
+
115
+ if (!confirmResponse.value) {
116
+ return;
117
+ }
118
+ }
119
+
120
+ process.env.SF_TEST_USERNAME = username;
121
+ process.env.SF_TEST_PASSWORD = password;
122
+
123
+ startTestSolution();
124
+ })();
@@ -2,7 +2,10 @@
2
2
  "environmentSettings" :{
3
3
  "baseUrl" : "https://develop.example.app",
4
4
  "serviceUrl" : "https://develop.example.app/service",
5
- "metaEndpoint" : "iam"
5
+ "metaEndpoint" : "iam",
6
+ "authUser" : "ExampleUser",
7
+ "authUserPassword" : "ExamplePassword@1",
8
+ "guiApplAlias" : "ExampleName"
6
9
  },
7
10
  "featureSettings" :{
8
11
  "logger" : {
package/scripts/main.js CHANGED
@@ -1,11 +1,84 @@
1
- #!/usr/bin/env node
2
- import process from 'node:process';
3
- import { setup } from './setup.js';
4
-
5
- if (process.argv[2] === 'install') {
6
- setup();
7
- } else if (process.argv[2] === 'sync') {
8
- console.log('This feature is coming soon!');
9
- } else {
10
- console.warn('Command unknown. Use "install" or "sync".');
11
- }
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import process from 'node:process';
5
+ import { PathResolver } from '../dist/helpers/index.js';
6
+ import { postinstall } from './postinstall.js';
7
+ import { setup } from './setup.js';
8
+ import { sync } from './sync.js';
9
+
10
+ await setup();
11
+ const { testwiseConfig } = await import('../dist/services/index.js');
12
+ const config = testwiseConfig();
13
+ const configBuilder = await config.load();
14
+
15
+ if (process.argv[2] === 'postinstall') {
16
+ if (!(await verifiedSeedData())) process.exit(0);
17
+
18
+ postinstall();
19
+ } else if (process.argv[2] === 'sync') {
20
+ if (!(await verifiedSeedData())) process.exit(0);
21
+
22
+ sync();
23
+ } else {
24
+ console.warn('Command unknown.');
25
+ }
26
+
27
+ async function verifiedSeedData() {
28
+ const consumerRoot = new PathResolver().getConsumerRootDirectory();
29
+ const seedDataDir = path.join(consumerRoot, 'seed-data');
30
+ const subjectsJson = path.join(seedDataDir, 'subjects.json');
31
+ const screensDir = path.join(seedDataDir, 'screen-schemas');
32
+ const projectIsConfigured = await isConfigured();
33
+
34
+ if (!fs.existsSync(seedDataDir)) {
35
+ if (projectIsConfigured) {
36
+ fs.mkdirSync(seedDataDir);
37
+ fs.mkdirSync(screensDir);
38
+
39
+ console.log('Created seed-data directory structure.');
40
+ return true;
41
+ }
42
+
43
+ console.info('No seed-data directory found.');
44
+ return false;
45
+ }
46
+
47
+ if (!fs.existsSync(subjectsJson) && !projectIsConfigured) {
48
+ console.info('No subjects.json');
49
+ return false;
50
+ }
51
+
52
+ if (!fs.existsSync(screensDir)) {
53
+ if (projectIsConfigured) {
54
+ fs.mkdirSync(screensDir);
55
+ console.log('Created screen-schemas directory.');
56
+ return true;
57
+ }
58
+
59
+ console.info('No screen-schemas directory found.');
60
+ return false;
61
+ }
62
+
63
+ const screenFiles = fs.readdirSync(screensDir).filter((f) => f.endsWith('.json'));
64
+ if (screenFiles.length === 0 && !projectIsConfigured) {
65
+ console.info('No screen JSON files found in seed-data/screen-schemas');
66
+ return false;
67
+ }
68
+ return true;
69
+ }
70
+
71
+ async function isConfigured() {
72
+ const user = configBuilder.get('environmentSettings.authUser');
73
+ const password = configBuilder.get('environmentSettings.authUserPassword');
74
+ const guiApplAlias = configBuilder.get('environmentSettings.guiApplAlias');
75
+
76
+ return Boolean(
77
+ user &&
78
+ user !== 'ExampleUser' &&
79
+ password &&
80
+ password !== 'ExamplePassword@1' &&
81
+ guiApplAlias &&
82
+ guiApplAlias !== 'ExampleName'
83
+ );
84
+ }
@@ -0,0 +1,39 @@
1
+ import { execSync } from 'node:child_process';
2
+ import path from 'node:path';
3
+ import process from 'node:process';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { ArtifactManager } from '../dist/artifact-builder/index.js';
6
+ import { testwiseConfig } from '../dist/services/ConfigBuilder.js';
7
+ import { sync } from './sync.js';
8
+
9
+ const _filename = fileURLToPath(import.meta.url);
10
+ const _dirname = path.dirname(_filename);
11
+
12
+ export async function postinstall() {
13
+ try {
14
+ const autoSync = testwiseConfig().get('featureSettings.other.autoSync') ?? true;
15
+ if (!autoSync) return;
16
+
17
+ const rootDir = path.resolve(_dirname, '..');
18
+ const artifactManager = new ArtifactManager();
19
+
20
+ if (artifactManager.backupExists()) {
21
+ artifactManager.restoreBackup();
22
+ console.info('Restored artifacts from backup.');
23
+
24
+ // const { SubjectRegistration } = await import('../dist/artifact-builder/index.js');
25
+ // new SubjectRegistration().run();
26
+
27
+ execSync('npx tsc', { cwd: rootDir, stdio: 'inherit' });
28
+
29
+ console.info('Postinstall restore process completed successfully.');
30
+
31
+ return;
32
+ }
33
+
34
+ await sync();
35
+ } catch (error) {
36
+ console.error('Postinstall process failed:', error.message);
37
+ process.exit(1);
38
+ }
39
+ }
package/scripts/setup.js CHANGED
@@ -1,34 +1,37 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import process from 'node:process';
5
- import { fileURLToPath } from 'node:url';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
-
10
- export function setup() {
11
- try {
12
- const testwiseConfigFile = path.resolve(process.cwd(), 'Testwise.json');
13
- const testwiseConfigTemplateFile = path.join(__dirname, 'Testwise.template.json');
14
- const tsConfigFile = path.resolve(process.cwd(), 'tsconfig.json');
15
- const tsConfigTemplateFile = path.join(__dirname, 'tsconfig.template.json');
16
-
17
- if (!fs.existsSync(testwiseConfigFile)) {
18
- fs.copyFileSync(testwiseConfigTemplateFile, testwiseConfigFile);
19
- console.info('Testwise.json config file created.');
20
- } else {
21
- console.info('Testwise.json already exists, skipping creation.');
22
- }
23
-
24
- if (!fs.existsSync(tsConfigFile)) {
25
- fs.copyFileSync(tsConfigTemplateFile, tsConfigFile);
26
- console.info('tsconfig.json config file created.');
27
- } else {
28
- console.info('tsconfig.json already exists, skipping creation.');
29
- }
30
- } catch (error) {
31
- console.error('Error during installation:', error.message);
32
- process.exit(1); // Exit with an error code if something goes wrong
33
- }
34
- }
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { PathResolver } from '../dist/helpers/index.js';
5
+
6
+ const _filename = fileURLToPath(import.meta.url);
7
+ const _dirname = path.dirname(_filename);
8
+
9
+ export async function setup() {
10
+ try {
11
+ const consumerRoot = new PathResolver().getConsumerRootDirectory();
12
+ const testwiseConfigFile = path.resolve(consumerRoot, 'Testwise.json');
13
+ const testwiseConfigTemplateFile = path.join(_dirname, 'Testwise.template.json');
14
+ const tsConfigFile = path.resolve(consumerRoot, 'tsconfig.json');
15
+ const tsConfigTemplateFile = path.join(_dirname, 'tsconfig.template.json');
16
+
17
+ let filesCreated = false;
18
+
19
+ if (!fs.existsSync(testwiseConfigFile)) {
20
+ fs.copyFileSync(testwiseConfigTemplateFile, testwiseConfigFile);
21
+ console.info('Testwise.json config file created.');
22
+ filesCreated = true;
23
+ }
24
+
25
+ if (!fs.existsSync(tsConfigFile)) {
26
+ fs.copyFileSync(tsConfigTemplateFile, tsConfigFile);
27
+ console.info('tsconfig.json config file created.');
28
+ filesCreated = true;
29
+ }
30
+
31
+ if (!filesCreated) {
32
+ await new Promise((resolve) => setTimeout(resolve, 1000));
33
+ }
34
+ } catch (error) {
35
+ console.error('Error during installation:', error.message);
36
+ }
37
+ }
@@ -0,0 +1,102 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { execSync } from 'node:child_process';
3
+ import path from 'node:path';
4
+ import process from 'node:process';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { Stopwatch } from '../dist/artifact-builder/helpers/index.js';
7
+ import { ArtifactManager } from '../dist/artifact-builder/index.js';
8
+
9
+ const _filename = fileURLToPath(import.meta.url);
10
+ const _dirname = path.dirname(_filename);
11
+ const stopwatch = new Stopwatch();
12
+ const timerTotal = stopwatch.start('Sync process start to end');
13
+
14
+ export async function sync() {
15
+ try {
16
+ const rootDir = path.resolve(_dirname, '..');
17
+ let timer;
18
+
19
+ // 1. Cleanup
20
+ timer = stopwatch.start('Clear distribution directory');
21
+ const { rimrafSync } = await import('rimraf');
22
+ rimrafSync(path.join(rootDir, 'dist'));
23
+ timer.stop();
24
+
25
+ // 2. Initial Compilation
26
+ timer = stopwatch.start('Recompile TypeScript sources');
27
+ execSync('npx tsc', { cwd: rootDir, stdio: 'inherit' });
28
+ timer.stop();
29
+
30
+ // Lazy imports...
31
+ const {
32
+ InterfaceGenerator,
33
+ ScreenInterfaceRefiner,
34
+ SchemaGenerator,
35
+ SubjectComponentGenerator,
36
+ SubjectGenerator,
37
+ // SubjectRegistration,
38
+ ModelDataRefiner
39
+ } = await import('../dist/artifact-builder/index.js');
40
+ const { buildSubjects, buildScreens } = await import('../dist/artifact-builder/ModelDataBuilder.js');
41
+
42
+ // 3. Data Building
43
+ timer = stopwatch.start('Build subjects from model data');
44
+ await buildSubjects();
45
+ timer.stop();
46
+
47
+ timer = stopwatch.start('Build screens from model data');
48
+ await buildScreens();
49
+ timer.stop();
50
+
51
+ // 4. Refinement
52
+ timer = stopwatch.start('Refine model data');
53
+ await new ModelDataRefiner().run();
54
+ timer.stop();
55
+
56
+ // 5. Artifact Generation
57
+ const interfaceGenerator = new InterfaceGenerator();
58
+
59
+ timer = stopwatch.start('Generate screen interfaces from screen schemas');
60
+ await interfaceGenerator.generateScreenInterfacesFromSchemas();
61
+ timer.stop();
62
+
63
+ timer = stopwatch.start('Refine interfaces');
64
+ new ScreenInterfaceRefiner().refine();
65
+ timer.stop();
66
+
67
+ timer = stopwatch.start('Generate subject component schemas');
68
+ new SchemaGenerator().generateSchema();
69
+ timer.stop();
70
+
71
+ timer = stopwatch.start('Generate subject component interfaces from schemas');
72
+ await interfaceGenerator.generateSubjectInterfacesFromSchemas();
73
+ timer.stop();
74
+
75
+ timer = stopwatch.start('Build components that implement interfaces');
76
+ new SubjectComponentGenerator().run();
77
+ timer.stop();
78
+
79
+ timer = stopwatch.start('Generate subjects classes');
80
+ new SubjectGenerator().run();
81
+ timer.stop();
82
+
83
+ // timer = stopwatch.start('Add subjects to registry');
84
+ // new SubjectRegistration().run();
85
+ // timer.stop();
86
+
87
+ // 6. Final Compilation
88
+ timer = stopwatch.start('Compile generated artifacts');
89
+ execSync('npx tsc', { cwd: rootDir, stdio: 'inherit' });
90
+ timer.stop();
91
+
92
+ console.info('Sync process completed successfully.');
93
+ } catch (error) {
94
+ console.error('Sync process failed:', error.message);
95
+ process.exit(1);
96
+ } finally {
97
+ const timerBackup = stopwatch.start('Perform Backup');
98
+ new ArtifactManager().performBackup();
99
+ timerBackup.stop();
100
+ timerTotal.stop();
101
+ }
102
+ }
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2016",
4
4
  "module": "ESNext",
5
- "moduleResolution": "node",
5
+ "moduleResolution": "bundler",
6
6
  "typeRoots": ["./node_modules/@types", "./types"],
7
7
  "resolveJsonModule": true,
8
8
  "esModuleInterop": true,
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import dotenv from 'dotenv';
4
4
 
5
5
  class ConfigBuilder {
6
- private config: Record<string, unknown>;
6
+ private config: Record<string, unknown> | null = null;
7
7
 
8
8
  constructor() {
9
9
  const baseDir = process.env.INIT_CWD || process.cwd();
@@ -18,19 +18,42 @@ class ConfigBuilder {
18
18
  }
19
19
 
20
20
  if (!fs.existsSync(configFilePath)) {
21
- throw new Error(`Config file not found at path: ${configFilePath}`);
21
+ console.warn(`Config file not found at path: ${configFilePath}`);
22
+ return;
22
23
  }
23
24
 
24
25
  const fileContent = fs.readFileSync(configFilePath, 'utf-8');
25
26
  this.config = JSON.parse(fileContent);
26
27
  }
27
28
 
29
+ public async load() {
30
+ const baseDir = process.env.INIT_CWD || process.cwd();
31
+ const configFilePath = path.resolve(baseDir, 'Testwise.json');
32
+
33
+ if (!fs.existsSync(configFilePath)) {
34
+ console.warn(`Config file not found at path: ${configFilePath}`);
35
+ return this;
36
+ }
37
+
38
+ const fileContent = fs.readFileSync(configFilePath, 'utf-8');
39
+ this.config = JSON.parse(fileContent);
40
+ return this;
41
+ }
42
+
28
43
  /**
29
44
  * Retrieves a value from the config using a dot-separated key.
30
45
  * @param key - The dot-separated key to retrieve the value.
31
46
  * @returns The value associated with the key, or undefined if not found.
32
47
  */
33
48
  public get<T>(key: string): T | undefined {
49
+ if (!key || typeof key !== 'string') {
50
+ return undefined;
51
+ }
52
+
53
+ if (!this.config) {
54
+ return undefined;
55
+ }
56
+
34
57
  const result = key
35
58
  .split('.')
36
59
  .reduce(