@browsermation/test 0.0.3 → 0.0.5
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/dist/bin/cli.js +26 -59
- package/dist/index.js +78 -2
- package/dist/src/bin/cli.d.ts +2 -0
- package/dist/src/core.d.ts +9 -0
- package/dist/src/defineConfig.d.ts +2 -0
- package/dist/src/esbuild.d.ts +1 -0
- package/dist/src/http.d.ts +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/playwright.d.ts +3 -0
- package/dist/src/test.d.ts +1 -0
- package/dist/src/tunnel.d.ts +5 -0
- package/dist/src/zip.d.ts +6 -0
- package/package.json +13 -7
package/dist/bin/cli.js
CHANGED
|
@@ -42626,6 +42626,9 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
|
42626
42626
|
if (env.TERM === "xterm-ghostty") {
|
|
42627
42627
|
return 3;
|
|
42628
42628
|
}
|
|
42629
|
+
if (env.TERM === "wezterm") {
|
|
42630
|
+
return 3;
|
|
42631
|
+
}
|
|
42629
42632
|
if ("TERM_PROGRAM" in env) {
|
|
42630
42633
|
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
42631
42634
|
switch (env.TERM_PROGRAM) {
|
|
@@ -42869,12 +42872,15 @@ var {
|
|
|
42869
42872
|
// package.json
|
|
42870
42873
|
var package_default = {
|
|
42871
42874
|
name: "@browsermation/test",
|
|
42872
|
-
version: "0.0.
|
|
42875
|
+
version: "0.0.5",
|
|
42873
42876
|
description: "The testing platform for Playwright by Browsermation.",
|
|
42874
42877
|
main: "dist/index.js",
|
|
42878
|
+
types: "dist/index.d.ts",
|
|
42875
42879
|
exports: {
|
|
42876
|
-
".":
|
|
42877
|
-
|
|
42880
|
+
".": {
|
|
42881
|
+
import: "./dist/index.js",
|
|
42882
|
+
types: "./dist/index.d.ts"
|
|
42883
|
+
}
|
|
42878
42884
|
},
|
|
42879
42885
|
bin: {
|
|
42880
42886
|
browsermation: "dist/bin/cli.js"
|
|
@@ -42882,11 +42888,11 @@ var package_default = {
|
|
|
42882
42888
|
files: [
|
|
42883
42889
|
"dist"
|
|
42884
42890
|
],
|
|
42885
|
-
publisher: "@browsermation",
|
|
42886
42891
|
scripts: {
|
|
42887
|
-
"build:cli": "esbuild src/bin/cli.ts --bundle --platform=node --target=node22 --outfile=dist/bin/cli.js
|
|
42888
|
-
"build:index": "esbuild src/index.ts --bundle --platform=node --target=node22 --outfile=dist/index.js
|
|
42889
|
-
build:
|
|
42892
|
+
"build:cli": "esbuild src/bin/cli.ts --bundle --platform=node --external:playwright --target=node22 --outfile=dist/bin/cli.js",
|
|
42893
|
+
"build:index": "esbuild src/index.ts --bundle --platform=node --external:playwright --target=node22 --outfile=dist/index.js",
|
|
42894
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
42895
|
+
build: "npm run build:cli && npm run build:index && npm run build:types",
|
|
42890
42896
|
start: "node dist/bin/cli.js",
|
|
42891
42897
|
"build:start": "npm run build && npm start",
|
|
42892
42898
|
publish: "npm run build && npm publish --access public"
|
|
@@ -42914,6 +42920,9 @@ var package_default = {
|
|
|
42914
42920
|
ora: "^8.2.0",
|
|
42915
42921
|
"ts-morph": "^26.0.0",
|
|
42916
42922
|
"ts-node": "^10.9.2"
|
|
42923
|
+
},
|
|
42924
|
+
peerDependencies: {
|
|
42925
|
+
playwright: "^1.40.0"
|
|
42917
42926
|
}
|
|
42918
42927
|
};
|
|
42919
42928
|
|
|
@@ -48121,13 +48130,13 @@ async function zipFolderToBuffer(folder, testFiles) {
|
|
|
48121
48130
|
|
|
48122
48131
|
// src/core.ts
|
|
48123
48132
|
var import_promises = require("node:fs/promises");
|
|
48124
|
-
async function uploadZip(zipBuffer, shardNumber, totalShards,
|
|
48133
|
+
async function uploadZip(zipBuffer, shardNumber, totalShards, playwrightConfig, options = {}, eventStream) {
|
|
48125
48134
|
if (!process.env.API_URL) {
|
|
48126
48135
|
console.error(source_default.red("Error: API_URL environment variable is not set."));
|
|
48127
48136
|
process.exit();
|
|
48128
48137
|
}
|
|
48129
48138
|
const formData = new FormData();
|
|
48130
|
-
formData.append("playwright_config", JSON.stringify(
|
|
48139
|
+
formData.append("playwright_config", JSON.stringify(playwrightConfig));
|
|
48131
48140
|
formData.append("zip_file", new Blob([zipBuffer]), "project.zip");
|
|
48132
48141
|
formData.append("shard", `${shardNumber || "1"}/${totalShards || "1"}`);
|
|
48133
48142
|
if (options?.proxy) {
|
|
@@ -48189,13 +48198,13 @@ async function zip(folder, testFiles) {
|
|
|
48189
48198
|
console.log(`Zipped project folder to ${tmpZipPath}`);
|
|
48190
48199
|
return zipBuffer;
|
|
48191
48200
|
}
|
|
48192
|
-
async function upload(zipBuffer, shardNumber, totalShards,
|
|
48201
|
+
async function upload(zipBuffer, shardNumber, totalShards, playwrightConfig, options = {}, eventStream) {
|
|
48193
48202
|
try {
|
|
48194
48203
|
await uploadZip(
|
|
48195
48204
|
zipBuffer,
|
|
48196
48205
|
shardNumber,
|
|
48197
48206
|
totalShards,
|
|
48198
|
-
|
|
48207
|
+
playwrightConfig,
|
|
48199
48208
|
options,
|
|
48200
48209
|
eventStream
|
|
48201
48210
|
);
|
|
@@ -48300,32 +48309,13 @@ async function downloadFile(fileUrl, outputLocationPath) {
|
|
|
48300
48309
|
});
|
|
48301
48310
|
});
|
|
48302
48311
|
} catch (err) {
|
|
48303
|
-
console.error(
|
|
48312
|
+
console.error(
|
|
48313
|
+
`Error downloading the file: ${err instanceof Error ? err.message : String(err)}`
|
|
48314
|
+
);
|
|
48304
48315
|
throw err;
|
|
48305
48316
|
}
|
|
48306
48317
|
}
|
|
48307
48318
|
|
|
48308
|
-
// src/playwright.ts
|
|
48309
|
-
function getUniqueFilesFromJson(data, key = "file") {
|
|
48310
|
-
const results = /* @__PURE__ */ new Set();
|
|
48311
|
-
function recurse(value) {
|
|
48312
|
-
if (Array.isArray(value)) {
|
|
48313
|
-
for (const item of value) {
|
|
48314
|
-
recurse(item);
|
|
48315
|
-
}
|
|
48316
|
-
} else if (value && typeof value === "object") {
|
|
48317
|
-
for (const k in value) {
|
|
48318
|
-
if (k === key) {
|
|
48319
|
-
results.add(value[k]);
|
|
48320
|
-
}
|
|
48321
|
-
recurse(value[k]);
|
|
48322
|
-
}
|
|
48323
|
-
}
|
|
48324
|
-
}
|
|
48325
|
-
recurse(data);
|
|
48326
|
-
return Array.from(results);
|
|
48327
|
-
}
|
|
48328
|
-
|
|
48329
48319
|
// src/bin/cli.ts
|
|
48330
48320
|
var program2 = new Command().name("browsermation").version(package_default.version).description(package_default.description);
|
|
48331
48321
|
program2.command("test").argument("<folder>", "The path to the folder to zip and upload").argument("<totalShards>", "Total number of shards").option("-t, --tunnel <port>").option("-p, --proxy").option("--project <project>", "Run a specific project").option(
|
|
@@ -48347,27 +48337,6 @@ program2.command("test").argument("<folder>", "The path to the folder to zip and
|
|
|
48347
48337
|
formOptions.proxy = true;
|
|
48348
48338
|
}
|
|
48349
48339
|
await new Promise((resolve) => setTimeout(resolve, 3e7));
|
|
48350
|
-
delete playwrightConfig.webServer;
|
|
48351
|
-
delete playwrightConfig.globalSetup;
|
|
48352
|
-
delete playwrightConfig.globalTeardown;
|
|
48353
|
-
delete playwrightConfig.grep;
|
|
48354
|
-
delete playwrightConfig.grepInvert;
|
|
48355
|
-
delete playwrightConfig.configFile;
|
|
48356
|
-
delete playwrightConfig.rootDir;
|
|
48357
|
-
delete playwrightConfig.version;
|
|
48358
|
-
playwrightConfig.projects = playwrightConfig.projects?.map((project) => {
|
|
48359
|
-
const fullconfig = playwrightConfigTypescript?.projects?.find(
|
|
48360
|
-
(p) => p.name === project.name
|
|
48361
|
-
);
|
|
48362
|
-
if (fullconfig) {
|
|
48363
|
-
project.use = fullconfig.use;
|
|
48364
|
-
project.outputDir = fullconfig.outputDir;
|
|
48365
|
-
project.testDir = fullconfig.testDir;
|
|
48366
|
-
}
|
|
48367
|
-
return project;
|
|
48368
|
-
});
|
|
48369
|
-
playwrightConfig.use = playwrightConfigTypescript.use;
|
|
48370
|
-
let testFiles = getUniqueFilesFromJson(suites);
|
|
48371
48340
|
let blobReports = [];
|
|
48372
48341
|
let sharedsDone = 0;
|
|
48373
48342
|
const uploadSpinner = ora(
|
|
@@ -48392,7 +48361,7 @@ program2.command("test").argument("<folder>", "The path to the folder to zip and
|
|
|
48392
48361
|
});
|
|
48393
48362
|
}
|
|
48394
48363
|
});
|
|
48395
|
-
const zipBuffer = await zip(folder,
|
|
48364
|
+
const zipBuffer = await zip(folder, []);
|
|
48396
48365
|
if (totalShards) {
|
|
48397
48366
|
const shardPromises = [];
|
|
48398
48367
|
for (let i = 0; i < totalShards; i++) {
|
|
@@ -48401,7 +48370,7 @@ program2.command("test").argument("<folder>", "The path to the folder to zip and
|
|
|
48401
48370
|
zipBuffer,
|
|
48402
48371
|
i + 1,
|
|
48403
48372
|
totalShards,
|
|
48404
|
-
|
|
48373
|
+
{},
|
|
48405
48374
|
{ proxy: options.proxy, project: options.project },
|
|
48406
48375
|
eventStream
|
|
48407
48376
|
)
|
|
@@ -48415,14 +48384,12 @@ program2.command("test").argument("<folder>", "The path to the folder to zip and
|
|
|
48415
48384
|
);
|
|
48416
48385
|
const downloadedReports = await Promise.all(downloadPromises);
|
|
48417
48386
|
} else {
|
|
48418
|
-
await upload(zipBuffer, 1, 1, {},
|
|
48387
|
+
await upload(zipBuffer, 1, 1, {}, {}, eventStream);
|
|
48419
48388
|
}
|
|
48420
|
-
webserverProcess?.kill();
|
|
48421
48389
|
tunnelProcess?.kill();
|
|
48422
48390
|
uploadSpinner.succeed(source_default.green("Upload complete."));
|
|
48423
48391
|
console.log(source_default.green.bold("\n\u2705 Success!"));
|
|
48424
48392
|
} catch (error) {
|
|
48425
|
-
webserverProcess?.kill();
|
|
48426
48393
|
tunnelProcess?.kill();
|
|
48427
48394
|
console.error(source_default.red.bold("\u274C An error occurred during the process."));
|
|
48428
48395
|
console.log(error);
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
22
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
23
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -30,7 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
31
|
// src/index.ts
|
|
31
32
|
var index_exports = {};
|
|
32
33
|
__export(index_exports, {
|
|
33
|
-
defineConfig: () => defineConfig
|
|
34
|
+
defineConfig: () => defineConfig,
|
|
35
|
+
test: () => test
|
|
34
36
|
});
|
|
35
37
|
module.exports = __toCommonJS(index_exports);
|
|
36
38
|
|
|
@@ -66,7 +68,81 @@ async function defineConfig(config) {
|
|
|
66
68
|
}
|
|
67
69
|
};
|
|
68
70
|
}
|
|
71
|
+
|
|
72
|
+
// ../../node_modules/@playwright/test/index.mjs
|
|
73
|
+
var test_exports = {};
|
|
74
|
+
__export(test_exports, {
|
|
75
|
+
default: () => import_test.default
|
|
76
|
+
});
|
|
77
|
+
__reExport(test_exports, require("playwright/test"));
|
|
78
|
+
var import_test = __toESM(require("playwright/test"), 1);
|
|
79
|
+
|
|
80
|
+
// src/test.ts
|
|
81
|
+
var import_node_https2 = __toESM(require("node:https"));
|
|
82
|
+
async function fetchEndpoint2() {
|
|
83
|
+
console.log("fetching endpoint");
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
import_node_https2.default.get(process.env.SERVER_URL || "https://localhost:3000", (res) => {
|
|
86
|
+
res.on("data", (chunk) => {
|
|
87
|
+
const parsedData = JSON.parse(chunk.toString());
|
|
88
|
+
if (parsedData.type === "tunnel-domain") {
|
|
89
|
+
console.log(`Tunnel domain found: ${parsedData.tunnelDomain}`);
|
|
90
|
+
resolve(`https://${parsedData.tunnelDomain}`);
|
|
91
|
+
res.destroy();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}).on("error", (err) => {
|
|
95
|
+
console.log("err", err);
|
|
96
|
+
reject(err);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
var test = test_exports.test.extend({
|
|
101
|
+
page: async ({ page }, use) => {
|
|
102
|
+
const endpointUrl = await fetchEndpoint2();
|
|
103
|
+
let isConnected = false;
|
|
104
|
+
while (!isConnected) {
|
|
105
|
+
try {
|
|
106
|
+
const response = await fetch(endpointUrl);
|
|
107
|
+
if (response.ok && response.status === 200) {
|
|
108
|
+
isConnected = true;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
console.log("Waiting for browser to be ready...");
|
|
112
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error("Error connecting to browser:", error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
console.log("Connected to browser:", endpointUrl);
|
|
118
|
+
const browser = await test_exports.chromium.connectOverCDP(endpointUrl, {});
|
|
119
|
+
const context = await browser.newContext(test.info().project.use);
|
|
120
|
+
const newPage = await context.newPage();
|
|
121
|
+
await use(newPage);
|
|
122
|
+
await newPage.close();
|
|
123
|
+
await browser.close();
|
|
124
|
+
},
|
|
125
|
+
browser: async ({}, use) => {
|
|
126
|
+
const endpointUrl = await fetchEndpoint2();
|
|
127
|
+
let isConnected = false;
|
|
128
|
+
while (!isConnected) {
|
|
129
|
+
try {
|
|
130
|
+
const response = await fetch(endpointUrl);
|
|
131
|
+
if (response.ok && response.status === 200) {
|
|
132
|
+
isConnected = true;
|
|
133
|
+
}
|
|
134
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error("Error connecting to browser:", error);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const browser = await test_exports.chromium.connectOverCDP(endpointUrl);
|
|
140
|
+
await use(browser);
|
|
141
|
+
await browser.close();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
69
144
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
145
|
0 && (module.exports = {
|
|
71
|
-
defineConfig
|
|
146
|
+
defineConfig,
|
|
147
|
+
test
|
|
72
148
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
/**
|
|
4
|
+
* The main function that orchestrates zipping and uploading.
|
|
5
|
+
* @param folderPath The path to the folder to process.
|
|
6
|
+
* @param testFiles The list of test files to include in the upload.
|
|
7
|
+
*/
|
|
8
|
+
export declare function zip(folder: string, testFiles: string[]): Promise<Buffer>;
|
|
9
|
+
export declare function upload(zipBuffer: Buffer, shardNumber: number, totalShards: number, playwrightConfig: object, options: object | undefined, eventStream: Readable): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compileFileUsingEsbuild(folder: string, filepath: string): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function downloadFile(fileUrl: string, outputLocationPath: string): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zips a folder to a Buffer. it keeps the folder structure intact.
|
|
3
|
+
* @param folder the folder where the testFiles are located
|
|
4
|
+
* @param testFiles Array of file paths to include in the zip.
|
|
5
|
+
*/
|
|
6
|
+
export declare function zipFolderToBuffer(folder: string, testFiles: string[]): Promise<Buffer>;
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browsermation/test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "The testing platform for Playwright by Browsermation.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"exports": {
|
|
7
|
-
".":
|
|
8
|
-
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
9
12
|
},
|
|
10
13
|
"bin": {
|
|
11
14
|
"browsermation": "dist/bin/cli.js"
|
|
@@ -13,11 +16,11 @@
|
|
|
13
16
|
"files": [
|
|
14
17
|
"dist"
|
|
15
18
|
],
|
|
16
|
-
"publisher": "@browsermation",
|
|
17
19
|
"scripts": {
|
|
18
|
-
"build:cli": "esbuild src/bin/cli.ts --bundle --platform=node --target=node22 --outfile=dist/bin/cli.js
|
|
19
|
-
"build:index": "esbuild src/index.ts --bundle --platform=node --target=node22 --outfile=dist/index.js
|
|
20
|
-
"build": "
|
|
20
|
+
"build:cli": "esbuild src/bin/cli.ts --bundle --platform=node --external:playwright --target=node22 --outfile=dist/bin/cli.js",
|
|
21
|
+
"build:index": "esbuild src/index.ts --bundle --platform=node --external:playwright --target=node22 --outfile=dist/index.js",
|
|
22
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
23
|
+
"build": "npm run build:cli && npm run build:index && npm run build:types",
|
|
21
24
|
"start": "node dist/bin/cli.js",
|
|
22
25
|
"build:start": "npm run build && npm start",
|
|
23
26
|
"publish": "npm run build && npm publish --access public"
|
|
@@ -45,5 +48,8 @@
|
|
|
45
48
|
"ora": "^8.2.0",
|
|
46
49
|
"ts-morph": "^26.0.0",
|
|
47
50
|
"ts-node": "^10.9.2"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"playwright": "^1.40.0"
|
|
48
54
|
}
|
|
49
55
|
}
|