qa 0.0.24 → 0.0.26

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.
@@ -3,9 +3,8 @@ import { IDE } from '../ide/index.js';
3
3
  import { getAccessToken } from '../auth.js';
4
4
  import { CLI_EPILOGUE } from '../constants.js';
5
5
  let app;
6
- const onShutdown = () => {
7
- app?.handleShutdown();
8
- process.exit(1);
6
+ const onShutdown = async () => {
7
+ await app?.handleShutdown();
9
8
  };
10
9
  process.on('SIGINT', onShutdown);
11
10
  process.on('SIGTERM', onShutdown);
package/dist/ide/index.js CHANGED
@@ -1,18 +1,23 @@
1
1
  import url from 'node:url';
2
2
  import path from 'node:path';
3
+ import logger from '@wdio/logger';
3
4
  import getPort from 'get-port';
4
5
  import Fastify from 'fastify';
5
6
  import staticServer from '@fastify/static';
6
7
  import websocket from '@fastify/websocket';
7
- import LocalDriver from 'localdriver';
8
8
  import { v4 as uuidv4 } from 'uuid';
9
9
  import { NeuralSpec } from 'neuralspec';
10
- import { remote } from 'webdriverio';
11
10
  import { WebSocketClient } from '@codeless.qa/contracts';
12
- import { getCapabilities, attachTokenToWindow } from './utils.js';
11
+ import { spinner, log } from '@clack/prompts';
12
+ import { setupBrowserEnvironment, attachTokenToWindow, getCacheDir } from './utils.js';
13
13
  import { login } from '../commands/login.js';
14
+ const cacheDir = await getCacheDir();
15
+ logger.setLevel('@wdio/utils', 'error');
16
+ logger.setLevel('webdriver', 'error');
14
17
  export class IDE {
18
+ #spinner = spinner();
15
19
  #isShuttingDown = false;
20
+ #cacheDir = cacheDir;
16
21
  #token;
17
22
  #messager;
18
23
  #fastify;
@@ -24,17 +29,33 @@ export class IDE {
24
29
  }
25
30
  constructor(token) {
26
31
  this.#token = token;
27
- this.#fastify = Fastify({ logger: true });
32
+ this.#fastify = Fastify({
33
+ logger: {
34
+ file: path.resolve(cacheDir, 'ide.log'),
35
+ level: 'info'
36
+ }
37
+ });
28
38
  }
29
39
  async start() {
30
- const url = await this.#startApplication();
40
+ this.#spinner.start('Starting VollQ IDE...');
41
+ const [url] = await Promise.all([
42
+ this.#startApplication(),
43
+ setupBrowserEnvironment(this.#cacheDir).then(({ ide, workbench }) => {
44
+ this.#ideSession = ide;
45
+ this.#workbenchSession = workbench;
46
+ })
47
+ ]);
31
48
  await this.#startSessions(url);
49
+ this.#spinner.stop(`VollQ IDE is running on ${url}.`);
50
+ log.message('Welcome 😊👐!');
51
+ log.message('Press CTRL+C to shutdown the application');
32
52
  return this;
33
53
  }
34
54
  async handleShutdown() {
35
55
  if (this.#isShuttingDown) {
36
56
  return;
37
57
  }
58
+ this.#spinner.start('Shutting down the VollQ IDE...');
38
59
  this.#isShuttingDown = true;
39
60
  try {
40
61
  this.#messager = undefined;
@@ -46,6 +67,7 @@ export class IDE {
46
67
  ]).catch((err) => {
47
68
  this.#fastify.log.error('Failed to close the application', err);
48
69
  });
70
+ this.#spinner.stop('See you next time 👋');
49
71
  process.exit(0);
50
72
  }
51
73
  catch (error) {
@@ -55,20 +77,23 @@ export class IDE {
55
77
  }
56
78
  async #startApplication() {
57
79
  try {
58
- const port = await getPort({
80
+ const appPath = path.dirname(url.fileURLToPath(import.meta.resolve('@codeless.qa/ide')));
81
+ /**
82
+ * do all this async work in parallel
83
+ */
84
+ const [port] = await Promise.all([
59
85
  /**
60
86
  * pick between 6000 and 6005 which are whitelisted ports to access the API without CORS
61
87
  */
62
- port: [...Array(5)].map((_, i) => i + 8000)
63
- });
64
- const appPath = path.dirname(url.fileURLToPath(import.meta.resolve('@codeless.qa/ide')));
88
+ getPort({ port: [...Array(5)].map((_, i) => i + 8000) }),
89
+ this.#fastify.register(websocket),
90
+ this.#fastify.register(staticServer, {
91
+ root: appPath,
92
+ prefix: '/',
93
+ index: 'index.html'
94
+ })
95
+ ]);
65
96
  this.#fastify.log.info(`Serve IDE from ${appPath}`);
66
- await this.#fastify.register(websocket);
67
- await this.#fastify.register(staticServer, {
68
- root: appPath,
69
- prefix: '/',
70
- index: 'index.html'
71
- });
72
97
  this.#fastify.get('/ws', { websocket: true }, (socket) => {
73
98
  this.#messager = new WebSocketClient(socket);
74
99
  this.#messager.onCommand('runWorkflow', this.#runSuggestion.bind(this));
@@ -86,24 +111,10 @@ export class IDE {
86
111
  }
87
112
  }
88
113
  async #startSessions(url) {
114
+ if (!this.#ideSession || !this.#workbenchSession) {
115
+ throw new Error('IDE session is not available');
116
+ }
89
117
  try {
90
- const [workbench, ide] = await Promise.all([
91
- remote({
92
- /**
93
- * run workbench with `localdriver` package so we can request tests to
94
- * execute from the cloud
95
- */
96
- automationProtocol: LocalDriver.protocolPath,
97
- logLevel: 'error',
98
- capabilities: getCapabilities('workbench'),
99
- }),
100
- remote({
101
- logLevel: 'error',
102
- capabilities: getCapabilities('ide')
103
- })
104
- ]);
105
- this.#ideSession = ide;
106
- this.#workbenchSession = workbench;
107
118
  /**
108
119
  * Inject the token into the IDE session
109
120
  */
@@ -9,6 +9,11 @@ declare const appSettings: {
9
9
  };
10
10
  };
11
11
  export declare function getCapabilities(appName: keyof typeof appSettings): WebdriverIO.Capabilities;
12
+ export declare function getCacheDir(): Promise<string>;
12
13
  export declare function attachTokenToWindow(token: string): void;
14
+ export declare function setupBrowserEnvironment(cacheDir: string): Promise<{
15
+ workbench: WebdriverIO.Browser;
16
+ ide: WebdriverIO.Browser;
17
+ }>;
13
18
  export {};
14
19
  //# sourceMappingURL=utils.d.ts.map
package/dist/ide/utils.js CHANGED
@@ -1,4 +1,10 @@
1
- /// <reference types="webdriverio" />
1
+ import os from 'node:os';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs/promises';
4
+ import LocalDriver from 'localdriver';
5
+ import { remote } from 'webdriverio';
6
+ // @ts-expect-error types are missing
7
+ import { setupDriver, setupBrowser } from '@wdio/utils/node';
2
8
  const appSettings = {
3
9
  ide: {
4
10
  size: '500,900',
@@ -47,7 +53,40 @@ export function getCapabilities(appName) {
47
53
  }
48
54
  };
49
55
  }
56
+ export async function getCacheDir() {
57
+ const cacheDir = path.join(os.tmpdir(), '.vollq');
58
+ await fs.mkdir(cacheDir, { recursive: true });
59
+ return cacheDir;
60
+ }
50
61
  export function attachTokenToWindow(token) {
51
62
  // @ts-expect-error missing window types
52
63
  globalThis.window.__VOLLQ_TOKEN = token;
53
64
  }
65
+ export async function setupBrowserEnvironment(cacheDir) {
66
+ const workbenchConfig = {
67
+ /**
68
+ * run workbench with `localdriver` package so we can request tests to
69
+ * execute from the cloud
70
+ */
71
+ automationProtocol: LocalDriver.protocolPath,
72
+ logLevel: 'info',
73
+ outputDir: cacheDir,
74
+ cacheDir,
75
+ capabilities: getCapabilities('workbench'),
76
+ };
77
+ const ideConfig = {
78
+ logLevel: 'info',
79
+ outputDir: cacheDir,
80
+ cacheDir,
81
+ capabilities: getCapabilities('ide')
82
+ };
83
+ await Promise.all([
84
+ setupDriver(workbenchConfig, [workbenchConfig.capabilities]),
85
+ setupBrowser(workbenchConfig, [workbenchConfig.capabilities]),
86
+ ]);
87
+ const [workbench, ide] = await Promise.all([
88
+ remote(workbenchConfig),
89
+ remote(ideConfig)
90
+ ]);
91
+ return { workbench, ide };
92
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qa",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "author": "Christian Bromann <christian@codeless.qa>",
5
5
  "description": "Codeless QA CLI",
6
6
  "license": "Apache-2.0",
@@ -13,6 +13,9 @@
13
13
  "@clack/prompts": "^0.8.1",
14
14
  "@fastify/static": "^8.0.4",
15
15
  "@fastify/websocket": "^11.0.2",
16
+ "@wdio/logger": "^9.4.4",
17
+ "@wdio/types": "^9.6.3",
18
+ "@wdio/utils": "^9.6.4",
16
19
  "fastify": "^5.2.1",
17
20
  "get-port": "^7.1.0",
18
21
  "openapi-types": "^12.1.3",
@@ -24,8 +27,8 @@
24
27
  "webdriverio": "^9.6.4",
25
28
  "@codeless.qa/contracts": "0.0.11",
26
29
  "@codeless.qa/ide": "0.0.6",
27
- "localdriver": "0.0.2",
28
- "neuralspec": "0.0.4"
30
+ "localdriver": "0.0.3",
31
+ "neuralspec": "0.0.5"
29
32
  },
30
33
  "devDependencies": {
31
34
  "@types/uuid": "^9.0.8",