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
When enableExtendedCollector and logToFilesOnAfterRun are set, the file write preprocessor is called twice, resulting in only the after-all hook being logged #185
Comments
This seems strange. I have tried to reproduce the issue but could not. I think I know where the issue might be and will apply a theoretical fix, but would like you to help me reproduce it so I can write a test for it. Ran cypress with only one spec and your settings, using this test: describe('All hooks.', function () {
before(function () {
cy.log('from before');
});
beforeEach(function () {
cy.log('from beforeEach');
});
it('passed it', function () {
cy.log('from it');
});
it('passed it 2', function () {
cy.log('from it 2');
});
afterEach(function () {
cy.log('from afterEach');
});
after(function () {
// cy.get('from after', {timeout: 0});
cy.log('from after');
});
after(function () {
cy.log('from after 2');
});
}); This works correctly all the time. The weird thing is that |
Thanks for response. Your example works fine for me. I ran: describe('All hooks.', function () {
before(function () {
cy.log('from before');
});
beforeEach(function () {
cy.log('from beforeEach');
});
it('passed it', function () {
cy.log('from it');
});
it('passed it 2', function () {
cy.log('from it 2');
});
afterEach(function () {
cy.log('from afterEach');
});
after(function () {
// cy.get('from after', {timeout: 0});
cy.log('from after');
});
after(function () {
cy.log('from after 2');
});
}); And got following as expected.
But if I add global afterAll like this: describe('All hooks.', function () {
before(function () {
cy.log('from before');
});
beforeEach(function () {
cy.log('from beforeEach');
});
it('passed it', function () {
cy.log('from it');
});
it('passed it 2', function () {
cy.log('from it 2');
});
afterEach(function () {
cy.log('from afterEach');
});
after(function () {
cy.log('from after');
});
after(function () {
cy.log('from after 2');
});
});
+ after(function() {
+ cy.log('Global after hook')
+ }); I will get only global hook if
And everything else except global hook if
I expect to see both suite and global hooks to be logged:
|
Released fix in 5.2.0. Custom processor is not needed. However there is a cavet, you will need to register your after hook before the plugin support install. See README note, in the last part of the section. |
Besides this be careful with that custom output processor as it accumulates memory usage, so in a sens it has memory leaks. |
I need to log both
beforeAll
andafterAll
hooks.Because of this I am using enableExtendedCollector option.
My support file looks like this:
This allows me to log
beforeAll
andafterAll
hook if it's not lastafter
hook.To log last
afterAll
hook I have to use logToFilesOnAfterRun option like this:But if you use
logToFilesOnAfterRun
option it will remove file, create it again and log onlyafterAll
because this line is called twice https://github.com/archfz/cypress-terminal-report/blob/master/src/outputProcessor/BaseOutputProcessor.js#L27.First time from
afterAll
hook and second time fromafter:run
.I was able to solve this problem by writing custom output log processor that almost same as TextOutputProcessor https://github.com/archfz/cypress-terminal-report/blob/master/src/outputProcessor/TextOutputProcessor.js
The only difference is that it tracks what specs were written by itself instead of relying on specChunksWritten from BaseOutputProcessor that will be flushed.
This custom logger solves my problem but it looks kinda hacky.
I guess that's a bug because I think that nobody would expect to get only afterAll hook when he uses
logToFilesOnAfterRun
option.That's an edge case to log the very last afterAll but It would be cool if it worked reliably out of the box.
Thanks for attention in advance :)
The text was updated successfully, but these errors were encountered: