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

Implement test and fixture modifiers #1107

Merged
merged 15 commits into from
Jan 10, 2017

Conversation

inikulin
Copy link
Contributor

@inikulin inikulin commented Jan 2, 2017

Features summary

test.only, test.skip, fixture.only, fixture.skip (closes #246)

You can now skip specific fixtures or tests using .skip modifier. In contrast, you can run only specified tests or fixtures using .only directive.

.skip example:

fixture.skip `Fixture1`; // All tests in this fixture will be skipped

test('Fixture1Test1', () => {});
test('Fixture1Test2', () => {});

fixture `Fixture2`;

test('Fixture2Test1', () => {});
test.skip('Fixture2Test2', () => {}); // This test will be skipped
test('Fixture2Test3', () => {});

.only example:

fixture.only `Fixture1`; 
test('Fixture1Test1', () => {});
test('Fixture1Test2', () => {});

fixture `Fixture2`;

test('Fixture2Test1', () => {});
test.only('Fixture2Test2', () => {}); 
test('Fixture2Test3', () => {});

// Only tests in Fixture1 and Fixture2Test2 will run

Note that reporter plugin now accepts additional skipped field in testRunInfo object, thus plugin now can decorate skipped tests in the distinct manner. All built-in reporters and plugin generator were updated to support this feature.

test.before and test.after hooks (closes #1108)

Test now supports test.before and test.after hooks that behave the same way as fixture.beforeEach and fixture.afterEach hooks with the exception that hook will run only for the specified test. If fixture.beforeEach and fixture.afterEach hooks are specified as well, test-specific hook will override them.

Example:

fixture `Fixture1`
    .beforeEach(async t  => {...})   
    .afterEach(async t  => {...});

test
    .before(async t => {...}) // Overrides fixture.beforeEach    
   ('Test1', async t => {...});

fixture `Fixture2`;

test
    .after(async t => {...})
    .before(async t => {...})
    ('Test2', async t => {...});

Note for tech writers: Current fixture.beforeEach and fixture.afterEach hooks section in documentation is not quite accurate. It's worth mentioning that hooks are run for each test run of the given test. So e.g., if we have 3 browsers set for the test run, each hook will be executed in each browser right before and after the test.

t.ctx object (closes #841)

t.ctx is an object that is shared between fixture.beforeEach, fixture.afterEach, test.before, test.after hooks and test itself. Each test run has it's own t.ctx object. This object can be used to share variables and other test-specific stuff between test functions without introducing global variables (it's even more complicated in TestCafe since single test can be run in several browsers).

Example:

fixture `Fixture1`
    .beforeEach(async t  => {
          t.ctx.someVar = 123;
     })   
    .afterEach(async t  => {
          console.log(t.ctx.someVar); // > 123
    });

test
    .before(async t => {
         console.log(t.ctx.someVar); // > 123
    })  
   ('Test1', async t => {
        console.log(t.ctx.someVar); // > 123
   });

By default t.ctx is initialized to empty object without prototype (so it's safe to iterate its keys without hasOwnProperty check). However, you can assign anything to t.ctx and assigned value will be shared, e.g.:

t.ctx = 123;

test.page directive (closes #501)

You can now specify startup page for the particular test that will override page specified for the fixture. It was possible previously to navigate to the specific page in the test by calling t.navigateTo, but it had a drawback that test first navigated to the page specified for the fixture. Additional navigation now avoidable with test.page directive.

Example:

fixture `Some fixture`
    .page `http://page1`;

test('Test1', () => {}); // Will navigate to http://page1
test
    .page `http://page2` 
   ('Test2', () => {}); // Will navigate to http://page2

test.httpAuth directive (closes #1109)

In addition to newly introduced HTTP authentication feature (#955) it's now possible to specify authentication credentials for particular test. If credentials are specified for fixture as well, they will be overridden by test-specific credentials.

Example:

test
    .httpAuth({ username: 'hey', password: 'yo' })
    ('Some test', async t => {});

Note that you can specify fixture and test directives before and after declarations, so all this cases are valid:

fixture.skip `Fixture name` .beforeEach(() => {});

fixture
    .page `http://page`
    `Fixture name`;

test
   .before(() => {})  
   ('Test name', () => {})
   .after(() => {});

test('Some test', () => {}).skip;

\cc @helen-dikareva @AlexanderMoskovkin @churkin @AndreyBelym @lexkazakov @VasilyStrelyaev

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit cea63e1 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 3ebb00c have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit acc4799 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 4545474 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 1c44154 have passed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 84c88a2 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 42969f8 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 0303e8d have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit f62d05e have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit f62d05e have passed. See details:

@inikulin inikulin changed the title [WIP] Implement test and fixture modifiers Implement test and fixture modifiers Jan 9, 2017
@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 874487a have passed. See details:

Copy link
Contributor

@AlexanderMoskovkin AlexanderMoskovkin left a comment

Choose a reason for hiding this comment

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

lgtm

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 0565d2d have passed. See details:

Copy link
Collaborator

@helen-dikareva helen-dikareva left a comment

Choose a reason for hiding this comment

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

lgtm
Let's add in documentation example for skip and only in different style of fixture implementations:

fixture( fixtureName )
fixture `fixtureName`

@inikulin inikulin merged commit 540c5a6 into DevExpress:master Jan 10, 2017
@inikulin inikulin deleted the test-modifiers branch January 10, 2017 08:59
@VasilyStrelyaev
Copy link
Collaborator

Note for tech writers: Current fixture.beforeEach and fixture.afterEach hooks section in documentation is not quite accurate. It's worth mentioning that hooks are run for each test run of the given test. So e.g., if we have 3 browsers set for the test run, each hook will be executed in each browser right before and after the test.

I feel like it can be excessive. Test runs are our internal stuff. We should just say: "Your test needs some initialization code? Put it here!", And it is our job to ensure that it runs in every browser. Users shouldn't bother.

kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this pull request Dec 18, 2019
* Implement test.only and fixture.only

* Move logic for test.only filtering to bootstrapper.

* Implement test.skip and fixture.skip

* Add tests for test.skip

* Fix test error. Implement test.page. Refactor.

* Fix raw API.

* Add test for test.page

* Implement test.before and test.after hooks

* Fix tests

* Tests for test.before and test.after

* Implement test.httpAuth. Add tests for test.before and test.after args

* Test test.httpAuth. Fix compiler test file heuristics

* Implement t.ctx

* Make t.ctx assignable

* Fix compiler filter RegExps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants