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

Support patterns in outPath for NestedOutputProcessorDecorator #243

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JohannesMunk
Copy link

Hey there! I tried to minimize changes to implement patterns in output filenames for custom output:

outputTarget: { '*|[relpath]/[basename]/[yyyy][mm][dd]/[basename].[HH][MM][SS].txt': function (allMessages) {..} }
outputTarget: { '*|[relpath]/[basename].txt': function () {..} }

Supported are these tokens:

Token Example Description
[relpath] /cy/e2e relative path of spec to spec root
[basename] spec1.cy part of spec filename before extension
[H] "0" Hour of day
[HH] "00" Hour of day - with leading zero
[M] "0" Minute of hour
[MM] "00" Minute of hour - with leading zero
[S] "0" Second of minute
[SS] "00" Second of minute - with leading zero
[d] "1" day of month
[dd] "01" day of month - with leading zero
[m] "1" month of year
[mm] "01" month of year - with leading zero
[yy] "70" last 2 digits of current year
[yyyy] "1970" current year

The legacy format given as 'path-prefix|extension'
outputTarget: { 'cypress-logs|txt': function () {..} }
is translated to pattern:
parts[0]+"/[relpath]/[basename]."+parts[1]

Hope this helps someone!

…elpath] [basename]

outputTarget: {
     '*|[relpath]/[basename].txt': function () {..}
}
…me tokens (e.g. [yy][mm][dd], ...)

example:
[relpath]/[basename]/[yyyy][mm][dd]/[basename].[HH][MM][SS].txt
or
[yyyy][mm][dd]_[HH][MM][SS]/[relpath]/[basename].txt
constructor(filePattern, specRoot, decoratedFactory) {
const parts = filePattern.split('|');
// for pattern matching: first part of filePattern has to start with '*|'
if (parts[0] === "*") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please modify the spacing to use two spaces instead of tabs ?

@@ -21,7 +29,58 @@ module.exports = class NestedOutputProcessorDecorator {
}

const relativeSpec = path.relative(this.specRoot, spec);
const outPath = path.join(this.root, relativeSpec.replace(new RegExp(path.extname(relativeSpec) + '$'), `.${this.ext}`));

const parsed = path.parse(relativeSpec);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big chunk of code that can get its own method.

@archfz
Copy link
Owner

archfz commented Jun 6, 2024

Hi @JohannesMunk . This looks nice. Sorry for feedback only after 2 weeks.

I wonder if we should apply this to both nested and non nested output path generation? It would make sense to keep consistency.

Besides that this PR needs some test updates, +one case that is actually testing this new feature. Let me know if you need help / direction.

@archfz
Copy link
Owner

archfz commented Jun 6, 2024

Fyi I have implemented some changes and did some maintenance on certain tests that were broken. You should pull changes from origin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants