Skip to content

Commit

Permalink
feat: Support archive files and folders (#253)
Browse files Browse the repository at this point in the history
* feat: Support archive files and folders

* make artifacts optional
  • Loading branch information
tianfeng92 committed Mar 22, 2024
1 parent 537c4d9 commit 58fea6f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
19 changes: 19 additions & 0 deletions src/playwright-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
loadRunConfig,
escapeXML,
preExec,
zip,
} from 'sauce-testrunner-utils';
import * as convert from 'xml-js';

Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down
10 changes: 9 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +31,7 @@ export interface RunnerConfig {
suite: Suite;

args: Record<string, unknown>;
artifacts: Artifacts;
}

export interface Suite {
Expand Down Expand Up @@ -75,6 +76,7 @@ export interface CucumberRunnerConfig {
path: string;
preExecTimeout: number;
projectPath: string;
artifacts?: Artifacts;
}

export interface CucumberSuite {
Expand All @@ -99,3 +101,9 @@ export interface CucumberSuite {
};
timeout?: number;
}

export interface Artifacts {
retain?: {
[key: string]: string;
};
}

0 comments on commit 58fea6f

Please sign in to comment.