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..cee84147 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,23 @@ async function getCfg( return runCfg; } +function zipArtifacts(runCfg: RunnerConfig | CucumberRunnerConfig) { + if (!runCfg.artifacts || !runCfg.artifacts.retain) { + return; + } + 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) { + 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 +221,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..460982d2 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; + }; +}