qa 0.0.1 → 0.0.3
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/LICENSE +201 -0
- package/README.md +36 -0
- package/assets/logo.png +0 -0
- package/bin/qa +5 -0
- package/dist/api.d.ts +8 -0
- package/dist/api.js +26 -0
- package/dist/auth.d.ts +2 -0
- package/dist/auth.js +21 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +3 -0
- package/dist/commands/login.d.ts +19 -0
- package/dist/commands/login.js +56 -0
- package/dist/commands/test.d.ts +41 -0
- package/dist/commands/test.js +83 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +9 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +22 -0
- package/package.json +31 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 CodelessQA
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<center>
|
|
2
|
+
<img src="./assets/logo.png">
|
|
3
|
+
</center>
|
|
4
|
+
|
|
5
|
+
<center>
|
|
6
|
+
<h1>CodelessQA CLI</h1>
|
|
7
|
+
</center>
|
|
8
|
+
|
|
9
|
+
<div align="center">
|
|
10
|
+
<a href="https://npmjs.com/package/qa"><img src="https://img.shields.io/npm/v/qa?style=flat&colorA=080f12&colorB=1fa669"></a>
|
|
11
|
+
<a href="https://npmjs.com/package/qa"><img src="https://img.shields.io/npm/dm/qa?style=flat&colorA=080f12&colorB=1fa669"></a>
|
|
12
|
+
<a href="https://bundlephobia.com/result?p=oat"><img src="https://img.shields.io/bundlephobia/minzip/qa?style=flat&colorA=080f12&colorB=1fa669&label=minzip"></a>
|
|
13
|
+
<!-- <a href="https://github.com/codeless-qa/qa/blob/main/LICENSE"><img src="https://img.shields.io/github/license/codeless-qa/qa.svg?style=flat&colorA=080f12&colorB=1fa669"></a> -->
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
CodelessQA is empowering businesses to achieve excellence through revolutionary testing solutions.
|
|
19
|
+
|
|
20
|
+
To install the latest version of CodelessQA CLI, run this command:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm i -g qa
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To quickly start a new project, run the following commands:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
qa login # login or register to the CodelessQA platform
|
|
30
|
+
qa init # initiate API or browser testing for your project
|
|
31
|
+
qa test <PROJECT> # run an API or browser test
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
For details on how to use Codeless CLI, check out our [documentation](https://docs.codeless.qa).
|
package/assets/logo.png
ADDED
|
Binary file
|
package/bin/qa
ADDED
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type TestSuite } from '@codeless.qa/contracts';
|
|
2
|
+
import { type Client } from '@codeless.qa/contracts/client';
|
|
3
|
+
import { type OpenAPIV3 } from 'openapi-types';
|
|
4
|
+
export declare function pullTestSuite(client: Client, project: string): Promise<{
|
|
5
|
+
testplan: TestSuite;
|
|
6
|
+
specification: OpenAPIV3.Document;
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export async function pullTestSuite(client, project) {
|
|
2
|
+
const apis = await client.specifications.get();
|
|
3
|
+
if (apis.status !== 200) {
|
|
4
|
+
const error = apis.status === 401 ? apis.body.error : 'unknown';
|
|
5
|
+
throw new Error(`Failed to fetch APIs: ${error}`);
|
|
6
|
+
}
|
|
7
|
+
const api = apis.body.data.find((api) => api.name === project);
|
|
8
|
+
if (!api) {
|
|
9
|
+
throw new Error(`API ${project} not found, please select one of the following: ${apis.body.data.map((api) => api.name).join(', ')}`);
|
|
10
|
+
}
|
|
11
|
+
const { body: specification, status } = await client.specification.get({ params: { id: api.id } });
|
|
12
|
+
if (status !== 200) {
|
|
13
|
+
throw new Error('Failed to fetch specification');
|
|
14
|
+
}
|
|
15
|
+
const testplan = await client.specification.test.get({ params: { id: api.id } });
|
|
16
|
+
if (testplan.status !== 200) {
|
|
17
|
+
throw new Error('Failed to fetch test plan');
|
|
18
|
+
}
|
|
19
|
+
if (!testplan.body.data) {
|
|
20
|
+
throw new Error(`No test plan found for API ${project}, create on at https://codeless.qa/api-testing/specifications/${api.id}/plan`);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
testplan: testplan.body.data,
|
|
24
|
+
specification: specification.data.specification
|
|
25
|
+
};
|
|
26
|
+
}
|
package/dist/auth.d.ts
ADDED
package/dist/auth.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { TOKEN_PATH } from './constants.js';
|
|
3
|
+
export async function getAccessToken(tokenParam) {
|
|
4
|
+
if (tokenParam) {
|
|
5
|
+
return tokenParam;
|
|
6
|
+
}
|
|
7
|
+
const envVar = process.env.CODELESS_TOKEN;
|
|
8
|
+
if (envVar) {
|
|
9
|
+
return envVar;
|
|
10
|
+
}
|
|
11
|
+
const hasAccess = await fs.access(TOKEN_PATH).then(() => true).catch(() => false);
|
|
12
|
+
if (!hasAccess) {
|
|
13
|
+
throw new Error('User is not authenticated');
|
|
14
|
+
}
|
|
15
|
+
const rc = await fs.readFile(TOKEN_PATH, 'utf-8');
|
|
16
|
+
const token = rc.split('\n').filter(Boolean).find((line) => line.startsWith('token='))?.split('=')[1];
|
|
17
|
+
if (!token) {
|
|
18
|
+
throw new Error('User is not authenticated');
|
|
19
|
+
}
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Argv } from 'yargs';
|
|
2
|
+
export declare const command = "login [option]";
|
|
3
|
+
export declare const desc = "Log in to the codeless.qa platform";
|
|
4
|
+
export declare const cmdArgs: {
|
|
5
|
+
readonly token: {
|
|
6
|
+
readonly alias: "t";
|
|
7
|
+
readonly desc: "Provide an access token if you don't want to log in via the UI";
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "token"> & import("yargs").InferredOptionTypes<{
|
|
12
|
+
readonly token: {
|
|
13
|
+
readonly alias: "t";
|
|
14
|
+
readonly desc: "Provide an access token if you don't want to log in via the UI";
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
};
|
|
17
|
+
}>>;
|
|
18
|
+
export declare const handler: (argv: typeof cmdArgs) => Promise<void>;
|
|
19
|
+
//# sourceMappingURL=login.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { client } from '@codeless.qa/contracts/client';
|
|
5
|
+
import { CLI_EPILOGUE, PLATFORM_URL, TOKEN_PATH } from '../constants.js';
|
|
6
|
+
const LOGIN_TIMEOUT = 1000 * 60; // 1 minute
|
|
7
|
+
const LOGIN_VERIFY_INTERVAL = 500;
|
|
8
|
+
export const command = 'login [option]';
|
|
9
|
+
export const desc = 'Log in to the codeless.qa platform';
|
|
10
|
+
export const cmdArgs = {
|
|
11
|
+
token: {
|
|
12
|
+
alias: 't',
|
|
13
|
+
desc: 'Provide an access token if you don\'t want to log in via the UI',
|
|
14
|
+
type: 'string',
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const builder = (yargs) => {
|
|
18
|
+
return yargs
|
|
19
|
+
.options(cmdArgs)
|
|
20
|
+
.example('qa login', 'Logs you into the platform')
|
|
21
|
+
.example('qa login --token XXX', 'Log in through access token')
|
|
22
|
+
.epilogue(CLI_EPILOGUE)
|
|
23
|
+
.help();
|
|
24
|
+
};
|
|
25
|
+
export const handler = async (argv) => {
|
|
26
|
+
if (argv.token) {
|
|
27
|
+
return console.log('Logging in via access token', argv.token);
|
|
28
|
+
}
|
|
29
|
+
const ticket = uuidv4();
|
|
30
|
+
const loginUrl = `${PLATFORM_URL}/login/${ticket}`;
|
|
31
|
+
console.log('🦄 Logging in via UI 🙌\n', `👉 Visit the following URL to log in: ${loginUrl}\n`, '\n', '...waiting for user to be authenticated...');
|
|
32
|
+
execSync(`open ${loginUrl}`);
|
|
33
|
+
try {
|
|
34
|
+
const token = await new Promise((resolve, reject) => {
|
|
35
|
+
const timeout = setTimeout(() => reject(new Error('timed out')), LOGIN_TIMEOUT);
|
|
36
|
+
const interval = setInterval(async () => {
|
|
37
|
+
const res = await client.auth.verifyTicket({ params: { ticket } });
|
|
38
|
+
if (res.status !== 200) {
|
|
39
|
+
if (res.status === 500) {
|
|
40
|
+
return reject(new Error('Internal server error'));
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
clearInterval(interval);
|
|
45
|
+
clearTimeout(timeout);
|
|
46
|
+
return resolve(res.body.token);
|
|
47
|
+
}, LOGIN_VERIFY_INTERVAL);
|
|
48
|
+
});
|
|
49
|
+
await fs.writeFile(TOKEN_PATH, `token=${token}\n`);
|
|
50
|
+
console.log('🎉 Successfully logged in!');
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.log(`🚨 Failed to log-in: ${err.message}`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Argv } from 'yargs';
|
|
2
|
+
export declare const command = "test <project> [option]";
|
|
3
|
+
export declare const desc = "Run a test on the codeless.qa platform";
|
|
4
|
+
export declare const cmdArgs: {
|
|
5
|
+
readonly token: {
|
|
6
|
+
readonly alias: "t";
|
|
7
|
+
readonly desc: "Provide an access token to authenticate with the platform";
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
};
|
|
10
|
+
readonly server: {
|
|
11
|
+
readonly desc: "Server URL to use for the API test";
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
};
|
|
14
|
+
readonly reporter: {
|
|
15
|
+
readonly desc: `Specify the reporter to use for the test (supported: ${string})`;
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
readonly default: "spec";
|
|
18
|
+
readonly alias: "r";
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "token" | "server" | "reporter"> & import("yargs").InferredOptionTypes<{
|
|
22
|
+
readonly token: {
|
|
23
|
+
readonly alias: "t";
|
|
24
|
+
readonly desc: "Provide an access token to authenticate with the platform";
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
};
|
|
27
|
+
readonly server: {
|
|
28
|
+
readonly desc: "Server URL to use for the API test";
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
};
|
|
31
|
+
readonly reporter: {
|
|
32
|
+
readonly desc: `Specify the reporter to use for the test (supported: ${string})`;
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly default: "spec";
|
|
35
|
+
readonly alias: "r";
|
|
36
|
+
};
|
|
37
|
+
}>>;
|
|
38
|
+
export declare const handler: (argv: typeof cmdArgs & {
|
|
39
|
+
project: string;
|
|
40
|
+
}) => Promise<never>;
|
|
41
|
+
//# sourceMappingURL=test.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import WebSocket from 'ws';
|
|
4
|
+
import { getAuthenticatedClient } from '@codeless.qa/contracts/client';
|
|
5
|
+
import { pullTestSuite } from '../api.js';
|
|
6
|
+
import { getAccessToken } from '../auth.js';
|
|
7
|
+
import { CLI_EPILOGUE, WORKER_HOSTNAME } from '../constants.js';
|
|
8
|
+
const SUPPORTED_REPORTER = [
|
|
9
|
+
'classic', 'doc', 'dot', 'dump', 'json', 'jsonstream', 'landing',
|
|
10
|
+
'list', 'markdown', 'min', 'nyan', 'progress', 'silent', 'spec',
|
|
11
|
+
'tap', 'xunit'
|
|
12
|
+
];
|
|
13
|
+
export const command = 'test <project> [option]';
|
|
14
|
+
export const desc = 'Run a test on the codeless.qa platform';
|
|
15
|
+
export const cmdArgs = {
|
|
16
|
+
token: {
|
|
17
|
+
alias: 't',
|
|
18
|
+
desc: 'Provide an access token to authenticate with the platform',
|
|
19
|
+
type: 'string',
|
|
20
|
+
},
|
|
21
|
+
server: {
|
|
22
|
+
desc: 'Server URL to use for the API test',
|
|
23
|
+
type: 'string',
|
|
24
|
+
},
|
|
25
|
+
reporter: {
|
|
26
|
+
desc: `Specify the reporter to use for the test (supported: ${SUPPORTED_REPORTER.join(', ')})`,
|
|
27
|
+
type: 'string',
|
|
28
|
+
default: 'spec',
|
|
29
|
+
alias: 'r',
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const require = createRequire(import.meta.url);
|
|
33
|
+
export const builder = (yargs) => {
|
|
34
|
+
return yargs
|
|
35
|
+
.options(cmdArgs)
|
|
36
|
+
.example('qa test myAPI', 'Runs test on API named "myAPI"')
|
|
37
|
+
.example('qa test myAPI -r nyan', 'Runs tests using the Nyan reporter')
|
|
38
|
+
.epilogue(CLI_EPILOGUE)
|
|
39
|
+
.help();
|
|
40
|
+
};
|
|
41
|
+
export const handler = async (argv) => {
|
|
42
|
+
const token = await getAccessToken(argv.token);
|
|
43
|
+
const client = getAuthenticatedClient(token);
|
|
44
|
+
// console.log('Running test on project', argv.project)
|
|
45
|
+
const reporter = argv.reporter;
|
|
46
|
+
if (!SUPPORTED_REPORTER.includes(reporter)) {
|
|
47
|
+
throw new Error(`Reporter ${argv.reporter} is not supported, please select one of the following: ${SUPPORTED_REPORTER.join(', ')}`);
|
|
48
|
+
}
|
|
49
|
+
const { testplan, specification } = await pullTestSuite(client, argv.project);
|
|
50
|
+
const workerUrl = `ws://${WORKER_HOSTNAME}/session`;
|
|
51
|
+
// console.log(`Connecting with worker at ${workerUrl}`)
|
|
52
|
+
const ws = new WebSocket(workerUrl);
|
|
53
|
+
ws.on('error', console.error);
|
|
54
|
+
ws.on('open', function open() {
|
|
55
|
+
// console.log(`Connected to worker at ${workerUrl}`)
|
|
56
|
+
const payload = {
|
|
57
|
+
type: 0,
|
|
58
|
+
value: {
|
|
59
|
+
testplan,
|
|
60
|
+
specification
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
ws.send(JSON.stringify(payload));
|
|
64
|
+
});
|
|
65
|
+
const success = await new Promise((resolve, reject) => {
|
|
66
|
+
const reporterProcess = spawn('node', [require.resolve('tap-mocha-reporter'), reporter], {
|
|
67
|
+
stdio: ['pipe', 'inherit', 'inherit']
|
|
68
|
+
});
|
|
69
|
+
ws.on('message', function message(data) {
|
|
70
|
+
const msg = JSON.parse(data.toString());
|
|
71
|
+
if (msg.type === 3) {
|
|
72
|
+
return reporterProcess.stdin.write(msg.value.log);
|
|
73
|
+
}
|
|
74
|
+
if (msg.type === 2) {
|
|
75
|
+
return resolve(msg.value.success);
|
|
76
|
+
}
|
|
77
|
+
if (msg.type === 4) {
|
|
78
|
+
return reject(new Error(msg.value.error));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
process.exit(success ? 0 : 1);
|
|
83
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
export const pkg = require('../package.json');
|
|
6
|
+
export const CLI_EPILOGUE = `Documentation: https://codeless.qa/docs/cli\n@wdio/cli (v${pkg.version})`;
|
|
7
|
+
export const PLATFORM_URL = 'https://codeless.qa' || 'http://localhost:4000';
|
|
8
|
+
export const WORKER_HOSTNAME = 'runner.codeless.qa' || 'localhost:8080';
|
|
9
|
+
export const TOKEN_PATH = path.join(homedir(), '/.codeless-qa');
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import { hideBin } from 'yargs/helpers';
|
|
3
|
+
import { pkg, CLI_EPILOGUE } from './constants.js';
|
|
4
|
+
import { commands } from './commands/index.js';
|
|
5
|
+
const DESCRIPTION = [
|
|
6
|
+
'The `qa` command allows you to ...',
|
|
7
|
+
'',
|
|
8
|
+
'$ qa test my-test-project',
|
|
9
|
+
'',
|
|
10
|
+
'For more information, visit: https://codeless.qa/docs/cli'
|
|
11
|
+
];
|
|
12
|
+
export async function run() {
|
|
13
|
+
const argv = yargs(hideBin(process.argv))
|
|
14
|
+
.command(commands)
|
|
15
|
+
.example('qa login', 'Logs you into the platform')
|
|
16
|
+
.example('qa test myAPI', 'Runs test on API named "myAPI"')
|
|
17
|
+
.updateStrings({ 'Commands:': `${DESCRIPTION.join('\n')}\n\nCommands:` })
|
|
18
|
+
.version(pkg.version)
|
|
19
|
+
.demandCommand()
|
|
20
|
+
.epilogue(CLI_EPILOGUE);
|
|
21
|
+
return argv.parse();
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qa",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"author": "Christian Bromann <christian@codeless.qa>",
|
|
5
|
+
"description": "Codeless QA CLI",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"qa": "./dist/index.js"
|
|
8
10
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@types/uuid": "^9.0.8",
|
|
14
|
+
"@types/ws": "^8.5.10",
|
|
15
|
+
"@types/yargs": "^17.0.32",
|
|
16
|
+
"openapi-types": "^12.1.3",
|
|
17
|
+
"replace-in-files-cli": "^3.0.0",
|
|
18
|
+
"tap-mocha-reporter": "^5.0.4",
|
|
19
|
+
"uuid": "^9.0.1",
|
|
20
|
+
"ws": "^8.17.0",
|
|
21
|
+
"yargs": "^17.7.2",
|
|
22
|
+
"@codeless.qa/contracts": "0.0.1",
|
|
23
|
+
"@codeless.qa/generator": "0.0.0"
|
|
12
24
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"command",
|
|
16
|
-
"answer",
|
|
17
|
-
"interation"
|
|
18
|
-
],
|
|
19
|
-
"author": "Boom Lee <boom11235.gg@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"bugs": {
|
|
22
|
-
"url": "https://github.com/jsenjoy/qa/issues"
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "5.6.2"
|
|
23
27
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "run-s build:*",
|
|
30
|
+
"build:ts": "tsc",
|
|
31
|
+
"build:replace": "run-s build:replace:*",
|
|
32
|
+
"build:replace:platform": "replace-in-files --string='process.env.PLATFORM_URL' --replacement=\"''$PLATFORM_URL''\" ./dist/constants.js",
|
|
33
|
+
"build:replace:worker": "replace-in-files --string='process.env.WORKER_URL' --replacement=\"''$WORKER_URL''\" ./dist/constants.js",
|
|
34
|
+
"start": "tsc --watch --preserveWatchOutput"
|
|
35
|
+
}
|
|
36
|
+
}
|