Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support archive files and folders #253

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
loadRunConfig,
escapeXML,
preExec,
zip,
} from 'sauce-testrunner-utils';
import * as convert from 'xml-js';

Expand Down Expand Up @@ -45,7 +46,7 @@
);
return;
}
let result: any = convert.xml2js(xmlData, { compact: true });

Check warning on line 49 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 49 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
if (!result.testsuites || !result.testsuites.testsuite) {
console.warn('JUnit file generation skipped: no test suites detected.');
return;
Expand All @@ -62,7 +63,7 @@
let totalSkipped = 0;
let totalTime = 0;
for (let i = 0; i < result.testsuites.testsuite.length; i++) {
const testsuite = result.testsuites.testsuite[i] as any;

Check warning on line 66 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 66 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
if (testsuite._attributes) {
totalTests += +testsuite._attributes.tests || 0;
totalFailures += +testsuite._attributes.failures || 0;
Expand Down Expand Up @@ -179,10 +180,27 @@
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);

const packageInfo = require(path.join(__dirname, '..', 'package.json'));

Check warning on line 203 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Require statement not part of import statement

Check warning on line 203 in src/playwright-runner.ts

View workflow job for this annotation

GitHub Actions / test

Require statement not part of import statement
console.log(`Sauce Playwright Runner ${packageInfo.version}`);
console.log(
`Running Playwright ${packageInfo.dependencies?.playwright || ''}`,
Expand All @@ -203,6 +221,7 @@
} 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;
};
}
Loading