From e8d4fcb25754d6013b9faae725c8ef3b2779729a Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Tue, 19 Mar 2024 13:08:08 -0700 Subject: [PATCH 1/2] feat: Support archive files and folders --- package-lock.json | 8 ++++---- package.json | 2 +- src/playwright-runner.ts | 18 ++++++++++++++++++ src/types.ts | 10 +++++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 06ce426c..3daac421 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "dotenv": "16.4.5", "lodash": "4.17.21", "playwright": "1.41.2", - "sauce-testrunner-utils": "2.0.0", + "sauce-testrunner-utils": "2.1.1", "xml-js": "1.6.11" }, "devDependencies": { @@ -13824,9 +13824,9 @@ "dev": true }, "node_modules/sauce-testrunner-utils": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/sauce-testrunner-utils/-/sauce-testrunner-utils-2.0.0.tgz", - "integrity": "sha512-vg43AUpsmFsxW5TCmgcBo0fgeHX+FrEvacvJjXSr+mggivrGgYHNZaxftBhWhG1eSdV92DuJt8cU6P4Ldp3Zvg==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/sauce-testrunner-utils/-/sauce-testrunner-utils-2.1.1.tgz", + "integrity": "sha512-2ZME0GUv4sUWTW8Ome61aqupVvF5LH5ue08ml+2XGD8lawE4R2+pjySnErvtyRQPEXsrVgQEq6czNdIVNg/FpQ==", "dependencies": { "lodash": "^4.17.21", "npm": "^10.2.0", diff --git a/package.json b/package.json index 95df64b2..80b01765 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "dotenv": "16.4.5", "lodash": "4.17.21", "playwright": "1.41.2", - "sauce-testrunner-utils": "2.0.0", + "sauce-testrunner-utils": "2.1.1", "xml-js": "1.6.11" }, "devDependencies": { diff --git a/src/playwright-runner.ts b/src/playwright-runner.ts index eba464bd..95a1fad3 100644 --- a/src/playwright-runner.ts +++ b/src/playwright-runner.ts @@ -10,6 +10,7 @@ import { loadRunConfig, escapeXML, preExec, + zip, } from 'sauce-testrunner-utils'; import * as convert from 'xml-js'; @@ -179,6 +180,22 @@ async function getCfg( return runCfg; } +function zipArtifacts(runCfg: RunnerConfig | CucumberRunnerConfig) { + if (!runCfg.artifacts || !runCfg.artifacts.retain) { + return; + } + Object.keys(runCfg.artifacts.retain).forEach((source) => { + const dest = path.join(runCfg.assetsDir, runCfg.artifacts.retain[source]); + try { + zip(path.dirname(runCfg.path), source, dest); + } catch (err) { + console.error( + `Zip file creation failed for destination: "${dest}", source: "${source}". Error: ${err}.`, + ); + } + }); +} + async function run(nodeBin: string, runCfgPath: string, suiteName: string) { const runCfg = await getCfg(runCfgPath, suiteName); @@ -203,6 +220,7 @@ async function run(nodeBin: string, runCfgPath: string, suiteName: string) { } catch (e) { console.warn('Skipping JUnit file generation:', e); } + zipArtifacts(runCfg); return passed; } diff --git a/src/types.ts b/src/types.ts index b6bd34a7..a0f41b4a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,7 +18,7 @@ export interface RunnerConfig { version: string; }; - // WARN: The following properties are set dynamcially by the runner and are not + // WARN: The following properties are set dynamically by the runner and are not // deserialized from the runner config json. They should technically be marked // as optional, but the runners treat them as required so type them as such. assetsDir: string; @@ -31,6 +31,7 @@ export interface RunnerConfig { suite: Suite; args: Record; + artifacts: Artifacts; } export interface Suite { @@ -75,6 +76,7 @@ export interface CucumberRunnerConfig { path: string; preExecTimeout: number; projectPath: string; + artifacts: Artifacts; } export interface CucumberSuite { @@ -99,3 +101,9 @@ export interface CucumberSuite { }; timeout?: number; } + +export interface Artifacts { + retain: { + [key: string]: string; + }; +} From 040d02c3ab9f71fb55a53fad9ed38a660dd10d18 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Tue, 19 Mar 2024 15:48:26 -0700 Subject: [PATCH 2/2] make artifacts optional --- src/playwright-runner.ts | 5 +++-- src/types.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/playwright-runner.ts b/src/playwright-runner.ts index 95a1fad3..cee84147 100644 --- a/src/playwright-runner.ts +++ b/src/playwright-runner.ts @@ -184,8 +184,9 @@ function zipArtifacts(runCfg: RunnerConfig | CucumberRunnerConfig) { if (!runCfg.artifacts || !runCfg.artifacts.retain) { return; } - Object.keys(runCfg.artifacts.retain).forEach((source) => { - const dest = path.join(runCfg.assetsDir, runCfg.artifacts.retain[source]); + const archivesMap = runCfg.artifacts.retain; + Object.keys(archivesMap).forEach((source) => { + const dest = path.join(runCfg.assetsDir, archivesMap[source]); try { zip(path.dirname(runCfg.path), source, dest); } catch (err) { diff --git a/src/types.ts b/src/types.ts index a0f41b4a..460982d2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -76,7 +76,7 @@ export interface CucumberRunnerConfig { path: string; preExecTimeout: number; projectPath: string; - artifacts: Artifacts; + artifacts?: Artifacts; } export interface CucumberSuite { @@ -103,7 +103,7 @@ export interface CucumberSuite { } export interface Artifacts { - retain: { + retain?: { [key: string]: string; }; }