Skip to content

Commit

Permalink
fix: skip request hooks initialization for skiped tests (#8260)
Browse files Browse the repository at this point in the history
<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->

## Purpose
Request hooks are initialized even though the test is skipped

## Approach
check if test is skipped before initialization

## References
closes #8229

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail

---------

Co-authored-by: Bayheck <[email protected]>
  • Loading branch information
Bayheck and Bayheck authored Aug 26, 2024
1 parent 23f9c40 commit bee56d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/test-run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,8 +1443,10 @@ export default class TestRun extends AsyncEventEmitter {
}

public async initialize (): Promise<void> {
await this._clearCookiesAndStorages();
await this._initRequestHooks();
if (!this.test.skip) {
await this._clearCookiesAndStorages();
await this._initRequestHooks();
}
}

private async _clearCookiesAndStorages (): Promise<void> {
Expand Down
4 changes: 4 additions & 0 deletions test/functional/fixtures/api/es-next/request-hooks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,9 @@ describe('Request Hooks', () => {
it('Set custom header on "onRequest" method (GH-7846)', () => {
return runTests('./testcafe-fixtures/api/7846.js', null, { only: 'chrome' });
});

it('Request hook on skipped test should not affect next test (GH-8229)', () => {
return runTests('./testcafe-fixtures/api/8229.js', null, { only: 'chrome' });
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { RequestMock, Selector } from 'testcafe';

const PAGE_URL = 'http://localhost:3000/fixtures/api/es-next/request-hooks/pages/api/empty.html';

fixture('Fixture')
.page(PAGE_URL);

test('before the skipped', async t => {
await t.expect(Selector('h1').exists).ok();
});

test.skip.requestHooks(
RequestMock().onRequestTo(/.*empty*/).respond('', 404)
)('skipped', async t => {
await t.expect(Selector('h1').exists).ok();
});

test('after the skipped', async t => {
await t.expect(Selector('h1').exists).ok();
});

0 comments on commit bee56d2

Please sign in to comment.