From db6dbaa86bc50d2cda065849ef4b6bb7104b79d6 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Fri, 22 Mar 2024 14:01:22 -0700 Subject: [PATCH] feat: Support archive files and folders (#223) * feat: Support archive files and folders * make artifacts optional --- package-lock.json | 8 ++++---- package.json | 2 +- src/testcafe-runner.ts | 24 ++++++++++++++++++++++-- src/type.ts | 7 +++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5a73449f..6ff3dbfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "dotenv": "16.3.1", "lodash": "^4.17.21", "mocha-junit-reporter": "^2.2.1", - "sauce-testrunner-utils": "2.0.0", + "sauce-testrunner-utils": "2.1.1", "shelljs": "^0.8.5", "testcafe": "3.5.0", "testcafe-browser-provider-ios": "0.5.0", @@ -15990,9 +15990,9 @@ } }, "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 0ea2af3a..d1e3a629 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "dotenv": "16.3.1", "lodash": "^4.17.21", "mocha-junit-reporter": "^2.2.1", - "sauce-testrunner-utils": "2.0.0", + "sauce-testrunner-utils": "2.1.1", "shelljs": "^0.8.5", "testcafe": "3.5.0", "testcafe-browser-provider-ios": "0.5.0", diff --git a/src/testcafe-runner.ts b/src/testcafe-runner.ts index abf9269b..67d645b3 100644 --- a/src/testcafe-runner.ts +++ b/src/testcafe-runner.ts @@ -8,6 +8,7 @@ import { getAbsolutePath, prepareNpmEnv, preExec, + zip, } from 'sauce-testrunner-utils'; import { TestCafeConfig, Suite, CompilerOptions, second } from './type'; @@ -27,6 +28,7 @@ async function prepareConfiguration( runCfg.projectPath || '.', ); const assetsPath = path.join(path.dirname(runCfgPath), '__assets__'); + runCfg.assetsPath = assetsPath; const suite = getSuite(runCfg, suiteName) as Suite | undefined; if (!suite) { throw new Error(`Could not find suite '${suiteName}'`); @@ -66,7 +68,7 @@ async function prepareConfiguration( // Install NPM dependencies await prepareNpmEnv(runCfg, nodeCtx); - return { projectPath, assetsPath, suite }; + return { runCfg, projectPath, assetsPath, suite }; } // Build --compiler-options argument @@ -318,10 +320,27 @@ async function runTestCafe( return false; } +function zipArtifacts(runCfg: TestCafeConfig) { + if (!runCfg.artifacts || !runCfg.artifacts.retain) { + return; + } + const archivesMap = runCfg.artifacts.retain; + Object.keys(archivesMap).forEach((source) => { + const dest = path.join(runCfg.assetsPath, 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 preExecTimeout = 300; - const { projectPath, assetsPath, suite } = await prepareConfiguration( + const { runCfg, projectPath, assetsPath, suite } = await prepareConfiguration( nodeBin, runCfgPath, suiteName, @@ -377,6 +396,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/type.ts b/src/type.ts index 59b0835d..ba377143 100644 --- a/src/type.ts +++ b/src/type.ts @@ -103,4 +103,11 @@ export type TestCafeConfig = { version: string; configFile?: string; }; + artifacts?: Artifacts; +}; + +export type Artifacts = { + retain?: { + [key: string]: string; + }; };