Skip to content

Commit

Permalink
feat: Support archive files and folders
Browse files Browse the repository at this point in the history
  • Loading branch information
tianfeng92 committed Mar 19, 2024
1 parent ed51db3 commit 23e7ec6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 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 @@ -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",
Expand Down
23 changes: 21 additions & 2 deletions src/testcafe-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getAbsolutePath,
prepareNpmEnv,
preExec,
zip,
} from 'sauce-testrunner-utils';

import { TestCafeConfig, Suite, CompilerOptions, second } from './type';
Expand All @@ -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}'`);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -318,10 +320,26 @@ async function runTestCafe(
return false;
}

function zipArtifacts(runCfg: TestCafeConfig) {
if (!runCfg.artifacts || !runCfg.artifacts.retain) {
return;
}
Object.keys(runCfg.artifacts.retain).forEach((source) => {
const dest = path.join(runCfg.assetsPath, 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 preExecTimeout = 300;

const { projectPath, assetsPath, suite } = await prepareConfiguration(
const { runCfg, projectPath, assetsPath, suite } = await prepareConfiguration(
nodeBin,
runCfgPath,
suiteName,
Expand Down Expand Up @@ -377,6 +395,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
7 changes: 7 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,11 @@ export type TestCafeConfig = {
version: string;
configFile?: string;
};
artifacts: Artifacts;
};

export type Artifacts = {
retain: {
[key: string]: string;
};
};

0 comments on commit 23e7ec6

Please sign in to comment.