Cocedeption with Laravel 5 exception when running functional and acceptance tests - laravel-5

I have a really simple test:
public function tryToGetJsonDataForAnItem(FunctionalTester $I)
{
$I->wantTo('Test if correct JSON is returned');
$I->sendPOST('/series/series', ['itemId' => 1]);
}
When I run the functional or acceptance tests with code coverage like this:
./vendor/bin/codecept run functional tests/functional/frontend/SeriesCest.php:tryToGetJsonDataForAnItem --env testing --coverage-html
I get the following error:
file_get_contents(http://domain.dev/c3/report/clear): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
After some googling I found out, that this is because remote coverage is set to true. I set it to false. This is how my coverage part of the codeception.yml looks like:
coverage:
enabled: true
remote: false
whitelist:
include:
- app/*
exclude:
- app/Events/*
- app/Exceptions/*
- app/Providers/*
And this is my functional.suite.yml
class_name: FunctionalTester
modules:
enabled: [Laravel5, Db, \Helper\Functional, REST]
config:
Laravel5:
url: http://domain.dev
cleanup: false
REST:
depends: PhpBrowser
url: http://domain.dev
Note: If I run the tests without test coverage, they pass.

Related

Cypress error Cypress.moment.duration (moment is not defined)

I'm using Cypress and upgraded to version to v8.3.1 and a new error keeps showing up.
Cannot read property 'duration' of undefined
Because this error occurred during a after all hook we are skipping all of the remaining tests.
Location: node_modules/#cypress/code-coverage/support.jsat line210
cy.task('coverageReport', null, {
timeout: Cypress.moment.duration(3, 'minutes').asMilliseconds(),
^
log: false
})
It says that duration cannot be found since Cypress.moment doesn't exist.
I checked the changelog and they removed it:
Cypress.moment() has been removed. Please migrate to a different datetime formatter. See our recipe for example replacements. Addresses #8714.
But since I'm not directly using it, it's in the code coverage included in Cypress, I don't know how to fix it.
Somehow you've obtained an old version of #cypress/code-coverage.
Perhaps you upgraded Cypress and not the code-coverage package?
#cypress/code-coverage#3.2.0 - support.js
after(function generateReport() {
// when all tests finish, lets generate the coverage report
cy.task('coverageReport', {
timeout: Cypress.moment.duration(3, 'minutes').asMilliseconds()
})
})
#cypress/code-coverage#3.9.10 - support.js
after(function generateReport() {
...
cy.task('coverageReport', null, {
timeout: dayjs.duration(3, 'minutes').asMilliseconds(),
log: false
}).then((coverageReportFolder) => {
...
})
npm update #cypress/code-coverage should fix it

Jenkins: Run Serenity acceptance tests without failure

I'm trying to achieve the following:
Run a set of Serenity (plus Cucumber) tests as part of a build pipeline
Collect the reports regardless of whether all tests passed or not (they are especially useful in failures obviously)
In the case of test failures only, then email the contributors
Never fail the build because of a failed acceptance test as this pipeline is for the commit CI. Only want to fail if there are broken acceptance tests in the Nightly.
So with all that in mind I set off attempting to configure the build:
stage ('Serenity') {
steps {
// For the Delivery CI build don't fail on regression failure
sh 'mvn clean verify -pl regression -DskipCuke=false'
}
post {
always {
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true,
keepAll: true, reportDir: 'regression/target/site/serenity',
reportFiles: 'index.html', reportName: 'Serenity',
reportTitles: ''])
}
failure{
echo 'There are regression suite failures.'
script {
currentBuild.result = 'SUCCESS'
}
emailext attachLog: true, body: 'Find Attached',
compressLog: true, recipientProviders: [[$class:
'CulpritsRecipientProvider']], subject: 'Broken Regression Tests',
to: 'dennis#dennis.ru'
}
}
}
However it does not work as I cannot reset the value of currentBuild.result to 'SUCCESS'. So I could all || true to the mvncommand, but that would mean that I can't email about the broken regression tests.
So I am wondering if anyone else out their has dealt with this in some clever way. Do I need to assign an exit code or something, and would that involve overriding the default shell parameters in Jenkins?
Any help much appreciated.
I think you would need to put a try/catch around the shell (so run it in a script{} block), and do your email in the catch. Then you can keep the build set to SUCCESS.
I actually solved this in a slightly different manner to #Rob's suggestion, but the key to it was understanding that what I wanted to do needed to use the script block with the returnStatus flag. I prefer this to a try-catch, as I am actually expecting (unfortunately) this to fail from time to time, and so would prefer to branch this below.
stage ('Serenity') {
steps {
script{
// For the Delivery CI build don't fail on regression failure
def bddPassed = ( sh ( returnStatus:true, script:'mvn clean verify -pl regression -DskipCuke=false') == 0 )
if( !bddPassed ){
echo 'There are regression suite failures.'
def mySubject = "Regression Test Failure: ${env.JOB_NAME} - Build# ${env.BUILD_NUMBER}"
def myBody = "Hi<br/>Please go to <a href='${env.BUILD_URL}Serenity'>the Serenity Report</a> to see more<br/>";
emailext attachLog: true,
mimeType: 'text/html',
body: myBody,
compressLog: true,
recipientProviders: [[$class: 'CulpritsRecipientProvider']],
subject: mySubject,
to: 'xxxxxxx'
}
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true,
keepAll: true, reportDir: 'regression/target/site/serenity', reportFiles: 'index.html',
reportName: 'Serenity', reportTitles: ''])
}
}
}

Test Database and Codeception

I'm working With Laravel 5 / Codeception.
I'm working with a test database.
Here is my config:
acceptance.suite.yml:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
- Db
- Asserts
config:
WebDriver:
url: 'http://laravel.dev'
browser: 'phantomjs'
window_size: 1024x768
Db:
dsn: 'mysql:host=laravel.dev;dbname=kendo_test'
user: 'homestead'
password: 'secret'
So, here I define my db being my Test db.
Then, in my bootstrap.php I have:
$app->loadEnvironmentFrom('.env.testing');
And .env.testing:
DB_HOST=127.0.0.1
DB_DATABASE=kendo_test
DB_USERNAME=homestead
DB_PASSWORD=secret
As a test, I changed kendo_test to kendo_test2, and it failed, it is using this db.
Now, When I execute an acceptance test, my test fails because row is inserted in main db, not test, And I don't know why....
Here is my test:
public function it_create_user(\AcceptanceTester $I, $scenario)
{
App::setLocale('en');
$user = factory(User::class)->make();
$I = new SimpleUser($scenario);
$I->logAsUser();
$I->dontSee(trans_choice('core.user', 2) . ' </a></li>');
$I->logout();
$I = new SuperAdmin($scenario);
$I->logAsSuperAdmin();
$I->click('#dropdown-user');
$I->click(trans_choice('core.user', 2));
$I->click(trans('core.addModel', ['currentModelName' => trans_choice('core.user', 1)]));
$I->fillField('name',$user->name );
$I->fillField('email',$user->email);
$I->fillField('firstname',$user->firstname);
$I->fillField('lastname',$user->lastname);
$I->fillField('password','111111');
$I->fillField('password_confirmation','111111');
$I->click(trans('core.save')); // <-- Here is should save it
$I->seeInCurrentUrl('/users');
$I->seeInSource(trans('msg.user_create_successful'));
$I->seeInDatabase('ken_users', ['name' => $user->name]);
}
Any Idea why???
When you click $I->click(trans('core.save')); it will be used the .env from your app and not the one from $app->loadEnvironmentFrom.
This is because when running acceptance tests you are interacting with your app via a browser.
The test being run has its own instance, as well as the app accessed by the test.
The only reason here you would use $app->loadEnvironmentFrom is to leverage Eloquent, and even then it must be on a separate connection.

In codeception functional test seeInDatabase not works from laravel

I am using codeception for testing in laravel 5.2.
Here is my codeception.yml file:
actor: Tester
paths:
tests: tests_codecept
log: tests_codecept/_output
data: tests_codecept/_data
support: tests_codecept/_support
envs: tests_codecept/_envs
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=kartice_test'
user: '*******'
password: '*******'
dump: tests_codecept/_data/dump.sql
populate: true
cleanup: true
reconnect: true
and here is functional.suite.yml file:
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- \Helper\Functional
- Asserts
- Laravel5:
environment_file: .env.testing
- Db
here is my test method:
public function provera_dodavanja_novog_klijenta(FunctionalTester $I)
{
$this->authenticate($I);
$I->amOnPage('/kancelarija/komitenti/create');
$I->see('Kreiranje novog komitenta');
$I->fillField('input[name=komitent_code]', 'kom1');
$I->fillField('input[name=komitent_name]', 'Komitent 1');
$I->click('btnSave');
$I->seeInDatabase('komitenti', ['code' => 'kom1', 'name' => 'Komitent 1']);
$I->see('Komitent Komitent 1 je uspešno kreiran.');
}
Running functional test fails with message:
Step I see in database "komitenti",{"code":"kom1","name":"Komitent 1"}
Fail No matching records found for criteria {"code":"kom1","name":"Komitent 1"} in table komitenti
Failed asserting that 0 is greater than 0.
What I am doing wrong?
I have seen question Codeception seeInDatabase() doesn't work for me but this didn't helpe me.
You should probably useseeRecord method instead of seeInDatabase. I don't know why but for me first one was working and second one - not.
I use gulp tdd and when testing forms come across this error.
Please check:
You added this to Requests
<YourFormRequest>use App\Http\Requests\<YourFormRequest>;
Ensure the Model for your table is mass assignable
protected $fillable = ['tableField1', 'tableField2']

Karma proxies are not working

I am using Karma (v0.12.37) as test runner along with JSPM (v0.16.2). I have added following proxy config in karma so as to allow proper loading of JSPM files:
proxies: {
'/base/jspm_packages/': '/base/app/jspm_packages/'
}
Bu this doesn't work out and fails on following:
PhantomJS 2.0.0 (Windows 8 0.0.0) ERROR: 'Potentially unhandled rejection [10] Error: XHR error loading http://localhost:9876/base/jspm_packages/npm/babel-core#5.8.22.js
Error loading http://localhost:9876/base/jspm_packages/npm/babel-core#5.8.22.js
Error loading http://localhost:9876/base/app/pages/examples/todo-example/todo.controller.test.js'
Debug Logs are giving:
proxying request - /base/jspm_packages/npm/babel-core#5.8.22.js to localhost:9876
/base/app/jspm_packages/npm/babel-core#5.8.22.js { host: 'localhost',
port: 9876,
baseProxyUrl: '/base/app/jspm_packages/',
https: false }
But the following url containing 'app' in it works properly:
http ://localhost:9876/base/ app/ jspm_packages/npm/babel-core#5.8.22.js
Any clue on what is going wrong?
Try:
proxies: {
'/app/': '/base/app/',
'/jspm_packages/': '/base/jspm_packages/'
}
If you have configured your jspm-config with a baseUrl of "/", try removing the baseUrl entry since karma-jspm does not support a custom baseUrl. Then you should be able to get rid of the "proxies" entry for the jspm_packages.
See: https://github.com/Workiva/karma-jspm/issues/91
After having done lot of trial and error, found out the following way:
Instead of playing with proxies, alter the jspm paths config in karma.config.js
jspm: {
...
paths: {
"github:*": "app/jspm_packages/github/*",
"npm:*": "app/jspm_packages/npm/*",
'app/*': 'app/*.js'
},
...
},
What finally did the trick for me (karma, babel, JSPM/SystemJS) was to have this:
Remove baseUrl from the karma.conf.js and have this jspm section:
jspm: {
config: 'config.js',
loadFiles: [
'www/**/*.spec.js'
],
serveFiles: [
'www/**/!(*spec).js'
],
paths: {
"github:*": "/base/jspm_packages/github/*",
"npm:*": "/base/jspm_packages/npm/*",
'www/*': '/base/www/*'
}
},

Resources