Skip to content

Commit

Permalink
feat: Sync attachments to assets directory (#254)
Browse files Browse the repository at this point in the history
* feat: Sync attachments to assets directory

* refine

* rename env vars

* bump reporter

* global env vars actually are applied to suites

* works?

* null?

* at least this works

* refine

* refine

* Update src/playwright-runner.ts

Co-authored-by: Alex Plischke <alex.plischke@saucelabs.com>

* relocate directory setting

* fix type

* do not use empty string

* skip null or undefined when passing args

* add args check condition back

* make check clear

---------

Co-authored-by: Alex Plischke <alex.plischke@saucelabs.com>
  • Loading branch information
tianfeng92 and alexplischke authored Apr 10, 2024
1 parent 4e7f79c commit b49f447
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
21 changes: 12 additions & 9 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 @@ -32,7 +32,7 @@
"homepage": "https://github.com/saucelabs/sauce-playwright-runner",
"dependencies": {
"@playwright/test": "1.41.2",
"@saucelabs/playwright-reporter": "1.0.0",
"@saucelabs/playwright-reporter": "1.1.0",
"@saucelabs/testcomposer": "2.0.0",
"dotenv": "16.4.5",
"lodash": "4.17.21",
Expand Down
18 changes: 16 additions & 2 deletions src/playwright-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,15 @@ async function getCfg(
runCfg.sauce = {};
}
runCfg.sauce.region = runCfg.sauce.region || 'us-west-1';
runCfg.playwrightOutputFolder = path.join(runCfg.assetsDir, 'test-results');
runCfg.playwrightOutputFolder =
suite.env?.SAUCE_SYNC_WEB_ASSETS?.toLowerCase() === 'true'
? undefined
: path.join(runCfg.assetsDir, 'test-results');

runCfg.webAssetsDir =
suite.env?.SAUCE_SYNC_WEB_ASSETS?.toLowerCase() === 'true'
? runCfg.assetsDir
: '';

return runCfg;
}
Expand Down Expand Up @@ -303,7 +311,12 @@ async function runPlaywright(
// eslint-disable-next-line prefer-const
for (let [key, value] of Object.entries(args)) {
key = utils.toHyphenated(key);
if (excludeParams.includes(key.toLowerCase()) || value === false) {
if (
excludeParams.includes(key.toLowerCase()) ||
value === false ||
value === undefined ||
value === null
) {
continue;
}
procArgs.push(`--${key}`);
Expand Down Expand Up @@ -332,6 +345,7 @@ async function runPlaywright(
PLAYWRIGHT_JUNIT_OUTPUT_NAME: runCfg.junitFile,
SAUCE_REPORT_OUTPUT_NAME: runCfg.sauceReportFile,
FORCE_COLOR: '0',
SAUCE_WEB_ASSETS_DIR: runCfg.webAssetsDir,
};

utils.setEnvironmentVariables(env);
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export interface RunnerConfig {
preExecTimeout: number;
path: string;
projectPath: string;
playwrightOutputFolder: string;
playwrightOutputFolder?: string;
// webAssetsDir contains assets compatible with the Sauce Labs web UI.
webAssetsDir?: string;
suite: Suite;

args: Record<string, unknown>;
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export function replaceLegacyKeys(config: SuiteConfig) {
return args;
}

export function setEnvironmentVariables(envVars: Record<string, string> = {}) {
export function setEnvironmentVariables(
envVars: Record<string, string | undefined> = {},
) {
if (!envVars) {
return;
}
Expand Down

0 comments on commit b49f447

Please sign in to comment.