Comments (5)
Hi Team,
can anyone help me with the above task?
from cypress-parallel.
Hi Team,
Please help me in resolving the above issue.
from cypress-parallel.
Hi Team,
Please have a look into the query.
from cypress-parallel.
Hey hi, if you goto node_module/cypress-parallel/test-suites.js you will find a method/function distributeTestsByWeight(testSuitePaths) which will guide you.
- It will sort the weights json as per weights in descending order
- Then it will initiate the threads object array with the size we've mentioned in the cmd
- Later, it will assign the threads with the spec with highest weight
- if threads are filled, it will sort the threads in ascending order according to total weight assigned to thread, now it will repeat the step 3, 4 iteratively.
For eg, if you have 7 specs with weights 14, 12, 10, 8, 6, 4, 2 and threads = 4
t1 = [14], t2 = [12], t3 =[10], t4 = [8]
in later stages...
t1 = [8, 6], t2 = [10], t3 =[12], t4=[14]
t1 = [10, 4], t2 = [8, 6], t3=[12], t4=[14]
t1=[12, 2], t2=[10, 4], t3=[8, 6], t4=[14]
The above will be the final thread list format.
So, play with it a bit, you will be able to understand.
from cypress-parallel.
I had the same issue. I made a node.js script that will combine tests in folders into files. I never managed to get the tests to pass when running in parallel due to complex state management, but running it this way did manage to get the folders to act like 'threads'.
My scripts looked like:
"combine": "rm -rf ./cypress/e2e/execution && node cypress/combine-threads.js",
"cy:parallel": "yarn run combine && cypress-parallel -s cypress:run:chrome -t 4 -m false -n ../../node_modules/cypress-multi-reporters -d './cypress/e2e/execution' -a '\"--config baseUrl=... --env REACT_API_URL=..."' && rm -rf ./cypress/e2e/execution"
Where -d is defining where my .cy.ts files are. The script compiles them into this location. Just make sure all of the contents of each test file are contained within describe()
as the files are simply pasted together.
var path = require('path');
var e2eDir = './cypress/e2e';
var executionDir = './cypress/e2e/execution';
// Helper function to adjust import paths
function adjustImportPaths(content, originalDirPath) {
const importRegex = /^import\s+{([^}]+)}\s+from\s+['"](.+?)['"];$/gm;
const importsMap = new Map();
content = content.replace(importRegex, (match, imports, from) => {
// Check if the import is from a package or a local file
const isPackageImport = from.startsWith('.') ? false : true;
let normalizedFrom = from;
if (!isPackageImport) {
// It's a local import, adjust the path
normalizedFrom = path.relative(executionDir, path.resolve(originalDirPath, from)).replace(/\\/g, '/');
}
const importItems = imports
.split(',')
.map((item) => item.trim())
.filter((item) => item);
if (importsMap.has(normalizedFrom)) {
const existingImports = importsMap.get(normalizedFrom);
importItems.forEach((item) => {
if (!existingImports.includes(item)) {
existingImports.push(item);
}
});
} else {
importsMap.set(normalizedFrom, importItems);
}
return ''; // Remove the original import statement
});
// Reconstruct combined import statements at the beginning of the content
const combinedImports = Array.from(
importsMap,
([from, imports]) => `import { ${imports.join(', ')} } from '${from}';`
).join('\n');
return combinedImports + '\n' + content;
}
// Function to combine files from a single directory
function combineFilesFromDirectory(dirPath, targetFileName) {
let combinedContent = '';
const importStatements = new Set();
const files = fs.readdirSync(dirPath);
files.forEach((file) => {
const filePath = path.join(dirPath, file);
const stat = fs.statSync(filePath);
if (stat.isFile() && filePath.endsWith('.cy.ts')) {
let content = fs.readFileSync(filePath, 'utf8');
// Adjust the import paths in the content
content = adjustImportPaths(content, dirPath);
// Extract and remove import statements from content
content = content.replace(/^import .+ from .+;$/gm, (importStatement) => {
importStatements.add(importStatement);
return '';
});
combinedContent += `\n${content}`;
}
});
// Prepend combined import statements to the top
combinedContent = Array.from(importStatements).join('\n') + combinedContent;
if (!fs.existsSync(executionDir)) {
fs.mkdirSync(executionDir, { recursive: true });
}
fs.writeFileSync(path.join(executionDir, targetFileName), combinedContent);
}
// Function to iterate through each subdirectory of e2e and combine files
function processDirectories(parentDirectory) {
const directories = fs
.readdirSync(parentDirectory, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
directories.forEach((dir) => {
const dirPath = path.join(parentDirectory, dir);
const targetFileName = `${dir}.cy.ts`;
combineFilesFromDirectory(dirPath, targetFileName);
console.log(`Combined file created for ${dirPath}: ${targetFileName}`);
});
}
processDirectories(e2eDir);
from cypress-parallel.
Related Issues (20)
- Support yargs "stop parsing" instead of args flag
- How do I pass environment variable as arguments in command line HOT 4
- Is colors.js still an issue for this repo for anyone else? HOT 2
- There is not enough documentation on how to generate and combine reports with multireporters HOT 1
- TypeError: glob is not a function HOT 1
- Update `mocha` to v10.1.0
- Can we pass unique arguments to each thread? HOT 1
- Retries do not work when using cypress-paralllel HOT 2
- When we have cy-grep implemented to select specific tests, running it via cypress-parallel leads to failure while building report (causing buildkite build to fail)
- Unable to see complete spec name in result table HOT 1
- Is it possible to only regenerate parallel-weights.json when the weights have changed?
- Issue: on successful run of one thread execution jenkins stops complete execution for cypress-parallel. HOT 8
- Cypress retries dont happen with cypress-parallel HOT 1
- Cypress parallel makes output come out in random orders and in a way that makes debugging tests unusable, can this be configured?
- Multi-cores HOT 1
- how to pass environment variables HOT 1
- how to use multiple-cucumber-html-reporter with parallel run
- parallel weights file is not generated when the feature files are under a sub folder HOT 1
- cypress parallel doesn't work with config via command --config-file HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cypress-parallel.