Skip to content

Commit

Permalink
refactor: refactor disableConcurrency from function to getter (#8068)
Browse files Browse the repository at this point in the history
## Pre-Merge TODO
- [x] Write tests for your proposed changes
- [x] Make sure that existing tests do not fail

---------

Co-authored-by: aleks-pro <alexander.prokhorov@hotmail.com>
Co-authored-by: Natalia Kazakova <17986517+natakazakova@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 9, 2023
1 parent b3831dc commit e141279
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/api/structure/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class Fixture extends TestingUnit {
return this.apiOrigin;
}

private _disableConcurrency$ (): Function {
private _disableConcurrency$getter (): Function {
this.disableConcurrency = true;

return this.apiOrigin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fixture `no concurrent fixture`
await t.expect(Object.keys(connectionsFixture).length).eql(1);
})
.page `http://localhost:3000/fixtures/regression/gh-2011/pages/index.html`
.disableConcurrency();
.disableConcurrency;

test('long concurrent test 1', async t => {
await t.wait(5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fixture `fixture 1`
.after(() => {
assertSingleConnection(connectionsFixture1);
})
.disableConcurrency();
.disableConcurrency;

for (let i = 0; i < TEST_COUNT; i++) {
test(`fixture 1 - test ${i}`, async () => {
Expand All @@ -50,7 +50,7 @@ fixture `fixture 2`
.after(() => {
assertSingleConnection(connectionsFixture2);
})
.disableConcurrency();
.disableConcurrency;

for (let i = 0; i < TEST_COUNT; i++) {
test(`fixture 2 - test ${i}`, async () => {
Expand All @@ -67,7 +67,7 @@ fixture `fixture 3`
.after(() => {
assertSingleConnection(connectionsFixture3);
})
.disableConcurrency();
.disableConcurrency;

for (let i = 0; i < TEST_COUNT; i++) {
test(`fixture 3 - test ${i}`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fixture `no concurrent fixture`
await t.expect(Object.keys(connectionsFixture2).length).eql(1);
})
.page `http://localhost:3000/fixtures/regression/gh-2011/pages/index.html`
.disableConcurrency();
.disableConcurrency;

test('long concurrent test 1', async t => {
await t.wait(5000);
Expand Down
23 changes: 23 additions & 0 deletions test/server/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const compile = require('./helpers/compile');
const OPTION_NAMES = require('../../lib/configuration/option-names');
const Compiler = require('../../lib/compiler');
const { RUNTIME_ERRORS } = require('../../lib/errors/types');
const Fixture = require('../../lib/api/structure/fixture');


describe('API', function () {
Expand Down Expand Up @@ -1862,4 +1863,26 @@ describe('API', function () {
expect(configuration.getOption(OPTION_NAMES.disableHttp2)).be.true;
});
});

describe('API Methods Validation', () => {
it('Should checks all methods', async () => {
const GETTER_API_METHODS = ['only', 'skip', 'disablePageReloads', 'enablePageReloads', 'disablePageCaching', 'disableConcurrency'];
const FUNCTIONS_API_METHODS = ['page', 'skipJsErrors', 'httpAuth', 'meta', 'before', 'after', 'beforeEach', 'afterEach', 'requestHooks', 'clientScripts'];

for (const apiMethod of Fixture.API_LIST) {
if (!GETTER_API_METHODS.includes(apiMethod.apiProp) && !FUNCTIONS_API_METHODS.includes(apiMethod.apiProp)) {
throw new Error(`Please, check the "${apiMethod.srcProp}" method.
If the method doesn't accept any arguments, ensure that the method is implemented as a 'getter' and add the method name to GETTER_API_METHODS.
If the method accepts arguments, ensure that the method is implemented as a 'function' and add the method name to FUNCTIONS_API_METHODS.
`);
}

if (GETTER_API_METHODS.includes(apiMethod.apiProp) && apiMethod.accessor !== 'getter')
throw new Error(`Make sure that the method "${apiMethod.srcProp}" is implemented as a "getter"`);

if (FUNCTIONS_API_METHODS.includes(apiMethod.apiProp) && apiMethod.accessor)
throw new Error(`Make sure that the method "${apiMethod.srcProp}" is implemented as a "function"`);
}
});
});
});
4 changes: 4 additions & 0 deletions ts-defs-src/test-api/structure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ interface FixtureFn {
* Disables page reloading which would happen right before each test in this fixture.
*/
disablePageReloads: this;
/**
* Disables the global concurrency setting for this fixture.
*/
disableConcurrency: this;
/**
* Specifies the additional information for all tests in the fixture. This information can be used in reports.
*
Expand Down

0 comments on commit e141279

Please sign in to comment.