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: enable use of global node context #270

Merged
merged 2 commits into from
Aug 1, 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
61 changes: 46 additions & 15 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.45.2",
"sauce-testrunner-utils": "3.0.0",
"sauce-testrunner-utils": "3.1.0",
"xml-js": "1.6.11"
},
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion src/cucumber-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { prepareNpmEnv, preExec } from 'sauce-testrunner-utils';

import type { CucumberRunnerConfig } from './types';
import * as utils from './utils';
import { NodeContext } from 'sauce-testrunner-utils/lib/types';

function buildArgs(runCfg: CucumberRunnerConfig, cucumberBin: string) {
const paths: string[] = [];
Expand Down Expand Up @@ -88,7 +89,11 @@ export async function runCucumber(
'bin',
'npm-cli.js',
);
const nodeCtx = { nodePath: nodeBin, npmPath: npmBin };
const nodeCtx: NodeContext = {
nodePath: nodeBin,
npmPath: npmBin,
useGlobals: !!runCfg.nodeVersion,
};

// Install NPM dependencies
await prepareNpmEnv(runCfg, nodeCtx);
Expand Down
7 changes: 6 additions & 1 deletion src/playwright-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { runCucumber } from './cucumber-runner';
import type { CucumberRunnerConfig, RunnerConfig } from './types';
import * as utils from './utils';
import { NodeContext } from 'sauce-testrunner-utils/lib/types';

function getPlatformName(platformName: string) {
if (process.platform.toLowerCase() === 'linux') {
Expand Down Expand Up @@ -47,7 +48,7 @@
);
return;
}
let result: any = convert.xml2js(xmlData, { compact: true });

Check warning on line 51 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 @@ -64,7 +65,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 68 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 @@ -359,7 +360,11 @@
'bin',
'npm-cli.js',
);
const nodeCtx = { nodePath: nodeBin, npmPath: npmBin };
const nodeCtx: NodeContext = {
nodePath: nodeBin,
npmPath: npmBin,
useGlobals: !!runCfg.nodeVersion,
};

// runCfg.path must be set for prepareNpmEnv to find node_modules. :(
await prepareNpmEnv(runCfg, nodeCtx);
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface RunnerConfig {
version: string;
};

nodeVersion?: string;

// 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.
Expand Down Expand Up @@ -72,6 +74,7 @@ export interface CucumberRunnerConfig {
configFile?: string;
version: string;
};
nodeVersion?: string;
suite: CucumberSuite;
assetsDir: string;
sauceReportFile: string;
Expand Down