From bee56d2b1c0845ba95ba164842f98292449842f8 Mon Sep 17 00:00:00 2001 From: Adil Rakhaliyev <67043367+Bayheck@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:20:41 +0500 Subject: [PATCH] fix: skip request hooks initialization for skiped tests (#8260) ## Purpose Request hooks are initialized even though the test is skipped ## Approach check if test is skipped before initialization ## References closes https://github.com/DevExpress/testcafe/issues/8229 ## Pre-Merge TODO - [ ] Write tests for your proposed changes - [ ] Make sure that existing tests do not fail --------- Co-authored-by: Bayheck --- src/test-run/index.ts | 6 ++++-- .../api/es-next/request-hooks/test.js | 4 ++++ .../testcafe-fixtures/api/8229.js | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/functional/fixtures/api/es-next/request-hooks/testcafe-fixtures/api/8229.js diff --git a/src/test-run/index.ts b/src/test-run/index.ts index 0063bceef20..fd15e72b895 100644 --- a/src/test-run/index.ts +++ b/src/test-run/index.ts @@ -1443,8 +1443,10 @@ export default class TestRun extends AsyncEventEmitter { } public async initialize (): Promise { - await this._clearCookiesAndStorages(); - await this._initRequestHooks(); + if (!this.test.skip) { + await this._clearCookiesAndStorages(); + await this._initRequestHooks(); + } } private async _clearCookiesAndStorages (): Promise { diff --git a/test/functional/fixtures/api/es-next/request-hooks/test.js b/test/functional/fixtures/api/es-next/request-hooks/test.js index 86f680a67da..425df76e65b 100644 --- a/test/functional/fixtures/api/es-next/request-hooks/test.js +++ b/test/functional/fixtures/api/es-next/request-hooks/test.js @@ -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' }); + }); }); }); diff --git a/test/functional/fixtures/api/es-next/request-hooks/testcafe-fixtures/api/8229.js b/test/functional/fixtures/api/es-next/request-hooks/testcafe-fixtures/api/8229.js new file mode 100644 index 00000000000..3de85284fac --- /dev/null +++ b/test/functional/fixtures/api/es-next/request-hooks/testcafe-fixtures/api/8229.js @@ -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(); +});