Karma's base directory location - unit-testing

Unable to load template fixtures for my tests while using karma. To simplify,
Went to c:\
Created a 1.txt text file.
Made a simple karma init file containing:
basePath: '',
Started karma using:
C:\> karma start .\sample.conf.js
Chrome opened up at:
http://localhost:9876/?id=49209467
I then tried to navigate to:
http://localhost:9876/base/1.txt
but got a "NOT FOUND" error message in the browser, and a message from karma:
WARN [web-server]: 404: /base/1.txt
What am I missing here?

Found the answer:
By adding the following to the karma config file:
files: [
....
{ pattern: 'mocks/**/*.html', watched: true, served: true, included: false },
....
I managed to access the required file by browsing to
http://localhost:9876/base/mocks/file.html
Where th "/base/" prefix is required by default (if even changable).

Related

Deploying to elastic beanstalk using gulp - Static files permissions issue

Recently I've had to change from using eb deploy to using a gulp task to deploy my project to AWS elastic beanstalk.
The reason for this is that I need to babel transform ES6 files to ES5. I don not want to commit the transformed files to our git and eb deploy uses the git-archive command to make the zip to deploy.
The transform and deploy works, I'm running into an issue with static files.
gulp.task('ebDeploy', function() {
return gulp.src([
'./.ebextensions/**', // Include the .ebextensions folder
'./**/*.js', // Match all .js files
'!./es6/**/*', // Exclude files in /es6 dir
'!node_modules', '!node_modules/**', // Exclude the node_modules folder and contained files
'*.js', // Include JS Files in the base dir
'package.json', // Include this specific file in base dir
'./config/**', // Include everything under /config
'./public/**', './public/**/*', // Include everything under /public
'./views/**/*.ejs' // Include all .ejs files under /views
], { base: './' })
.pipe(print())
.pipe(gulpEbDeploy({
//name: 'my-application', // optional: If not set, the name from package.json will be used
//version: '1.0.0', // optional: If not set, the version from package.json will be used
timestamp: true, // optional: If set to false, the zip will not have a timestamp
waitForDeploy: true, // optional: if set to false the task will end as soon as it starts deploying
amazon: {
// accessKeyId: "< your access key (fyi, the 'short' one) >", // optional
// secretAccessKey: "< your secret access key (fyi, the 'long' one) >", // optional
// signatureVersion: "v4", // optional
region: 'eu-west-2',
bucket: 'elasticbeanstalk',
applicationName: 'foo',
environmentName: 'bar'
}
}))
});
I have checked the zip that get's uploaded and it contains all the correct files. However it seems that eb deploy does something to permissions that i need to duplicate.
When I use eb deploy (after committing the /build files which I'm trying to prevent)
Everything works fine.
When I use my gulp task: I get the following error when trying to access static files.
06:49:28.81 server.js:98 | Global Error Handler
06:49:28.81 server.js:99 | { Error: EACCES: permission denied, stat '/var/app/current/public/css/default.css'
at Error (native)
errno: -13,
code: 'EACCES',
syscall: 'stat',
path: '/var/app/current/public/css/default.css',
expose: false,
statusCode: 500,
status: 500 }
What do I need to do to make these files work as intended.

Yii2 codeception authentication and XML reports output

I have some trouble testing my code with codeception in Yii2 and i hope one of you can help me.
First of all my authentication doesn't work as expected.
In my Class PagesUrl the user isn't logged in but in my template file the user is logged in. Whenever the page is not accessed with Codeception it's working fine.
Code to check if user is logged in: var_dump(Yii::$app->getUser()->getIsGuest());
Config of UrlManager:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'common\routes\PagesUrl',
'pattern' => '',
'route' => 'site/index',
],
//Some additional rules
],
]
Second I can't seem to generate XML reports.
Command for test output: codecept run functional LoginFormCest --xml -vvv
Gives this output:
Codeception PHP Testing Framework v2.1.0
Powered by PHPUnit 4.8.35-1-g912b8c1e9 by Sebastian Bergmann and contributors.
Functional Tests (5) ----------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Filesystem, Yii2
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Printing JUNIT report into report.xml
[PHPUnit_Framework_Exception]
Undefined index: log_incomplete_skipped
Exception trace:
() at C:\xampp\htdocs\stoneart-v2\vendor\codeception\base\src\Codeception\Subscriber\ErrorHandler.php:75
Codeception\Subscriber\ErrorHandler->errorHandler() at C:\xampp\htdocs\stoneart-v2\vendor\codeception\base\src\Codeception\PHPUnit\Runner.php:145
Codeception\PHPUnit\Runner->applyReporters() at C:\xampp\htdocs\stoneart-v2\vendor\codeception\base\src\Codeception\PHPUnit\Runner.php:91
Codeception\PHPUnit\Runner->doEnhancedRun() at C:\xampp\htdocs\stoneart-v2\vendor\codeception\base\src\Codeception\SuiteManager.php:157
Codeception\SuiteManager->run() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Codecept.php:200
Codeception\Codecept->runSuite() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Codecept.php:172
Codeception\Codecept->run() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Command\Run.php:184
Codeception\Command\Run->execute() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\symfony\console\Command\Command.php:264
Symfony\Component\Console\Command\Command->run() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\symfony\console\Application.php:846
Symfony\Component\Console\Application->doRunCommand() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\symfony\console\Application.php:191
Symfony\Component\Console\Application->doRun() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\symfony\console\Application.php:122
Symfony\Component\Console\Application->run() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\codeception\codeception\codecept:28
Command for test coverage: codecept run functional LoginFormCest --coverage-xml
Gives this output:
FAILURES!
Tests: 5, Assertions: 3, Failures: 5.
[yii\base\ErrorException]
Undefined index: quiet
Exception trace:
() at C:\xampp\htdocs\stoneart-v2\vendor\codeception\base\src\Codeception\Coverage\Subscriber\Printer.php:61
::call_user_func:{C:\xampp\htdocs\stoneart-v2\vendor\symfony\event-dispatcher\EventDispatcher.php:184}() at C:\xampp\htdocs\stoneart-v2\vendor\symfony\event-dispatcher\EventDispatcher.php:184
Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at C:\xampp\htdocs\stoneart-v2\vendor\symfony\event-dispatcher\EventDispatcher.php:46
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Codecept.php:218
Codeception\Codecept->printResult() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Command\Run.php:204
Codeception\Command\Run->execute() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\symfony\console\Command\Command.php:264
Symfony\Component\Console\Command\Command->run() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\symfony\console\Application.php:846
Symfony\Component\Console\Application->doRunCommand() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\symfony\console\Application.php:191
Symfony\Component\Console\Application->doRun() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\symfony\console\Application.php:122
Symfony\Component\Console\Application->run() at C:\Users\j-rub\AppData\Roaming\Composer\vendor\codeception\codeception\codecept:28
Codeception.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
memory_limit: 1024M
colors: false
modules:
config:
Yii2:
configFile: 'tests/config/test.php'
cleanup: false
coverage:
enabled: true
whitelist:
include:
- common/modules/news/*
Updating to the newest version did the work for me. Although there seems to be a bug displaying the right version of codeception. I would recommend to check your composer.json. Thanks.

How to use jenkins pipeline script with UnitTest++ 1.4

I have some C++ code which I build on jenkins. I ran UnitTest++ 1.4 to test the C++ code and this generates some TestResults*.xml.
This works nice as long as I configure the jenkins build job using the web frontend:
For a new build job I have to use the jenkins pipeline plugin instead, so I have to write a Jenkinsfile. For evaluating my TestResults*.xml, I only found two alternatives:
junit 'TestResults*.xml'
step([$class: 'JUnitResultArchiver', testResults: 'TestResults*.xml'])
But none of them work. Seems that junit xml format is different to UnitTest++ 1.4.
Does anyone know which Jenkinsfile statement is required to correctly use UnitTest++ 1.4 test results xml output?
The solution is, to use xUnit plugin instead if JUnit plugin. Like this:
step([
$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1,
thresholds: [
[$class: 'FailedThreshold', failureNewThreshold: '', failureThreshold: '0', unstableNewThreshold: '', unstableThreshold: ''],
[$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']
],
tools: [[
$class: 'UnitTestJunitHudsonTestType',
deleteOutputFiles: true,
failIfNotNew: true,
pattern: 'result.xml',
skipNoTestFiles: false,
stopProcessingIfError: true
]]
])

Exclude pattern or folder in istanbul coverage

I have an istanbul coverage that i use in my package.json like below.
"test:coverage": "./node_modules/.bin/babel-istanbul --include-all-sources cover ./node_modules/.bin/_mocha ./src/**/__tests__/*.js",
And i jave an .istanbul.yml script like below.
verbose: true
instrumentation:
extension: .js
root: ./src
default-excludes: true
excludes: ['./src/**/__tests__/**', './src/electron.js']
embed-source: false
variable: __coverage__
compact: true
preserve-comments: false
complete-copy: false
save-baseline: false
baseline-file: ./coverage/coverage-baseline.json
reporting:
print: summary
reports:
- lcov
dir: ./coverage
watermarks:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
hooks:
hook-run-in-context: false
post-require-hook: null
I am trying to exclude the tests folder and the electron.js files from the coverage. However , the file and the folder are not excluding. Please where do i go wrong and how can i fix this ? Any help would be appreciated.
Incase if some one is still having this issue. Below is how i solved mine by modifying
instrumentation:
root: src
include-all-sources: true
verbose: true
excludes: ["**/__tests__/**" ,"./electron.js"]
reporting:
dir: "coverage"
What worked for us was adding the exclude syntax in our babel config:
plugins: [
[
'istanbul',
{
exclude: ['**/example/**/**/*'],
},
],
],
We clearly hand't read thoroughly the docs! https://github.com/istanbuljs/babel-plugin-istanbul#ignoring-files

grunt-text-replace doesn't work

I installed grunt-text-replace with npm install grunt-text-replace --save-dev command and add grunt.loadNpmTasks('grunt-text-replace'); to gruntfile.js and add write this:
replace: {
example: {
src: ['css/mystyle.css'],
overwrite: true,
replacements: [{
from: 'wizard', // string replacement
to: 'wizardstep'
}]
}
}
then run grunt replace in command line and after that show me done, without error but my replacement doesn't work and applied.
Unfortunately I entered path incorrectly and other hand grunt-text-replace doesn't show me message if source file path incorrect.
just I correct source path