ember test throw error - Cannot read property 'tagName' of undefined - ember.js

i have migrated ember 3.16 to 3.24
I struck on ember test error. But the app works fine
Chrome 88.0 - [17 ms] - Unit | Service | preferences: it exists
---
actual: >
null
stack: >
TypeError: Cannot read property 'tagName' of undefined
at Class.setup (https://localhost:4221/assets/vendor.js:41026:134)
at Class.setupEventDispatcher (https://localhost:4221/assets/vendor.js:42523:18)
at Class._bootSync (https://localhost:4221/assets/vendor.js:42447:14)
at https://localhost:4221/assets/vendor.js:45731:77
at initializePromise (https://localhost:4221/assets/vendor.js:74537:7)
at new Promise (https://localhost:4221/assets/vendor.js:75038:35)
at Class.boot (https://localhost:4221/assets/vendor.js:45731:27)
at https://localhost:4221/assets/test-support.js:3656:65
at invokeCallback (https://localhost:4221/assets/vendor.js:74510:17)
at https://localhost:4221/assets/vendor.js:74575:26
message: >
Promise rejected before "it exists": Cannot read property 'tagName' of undefined
negative: >
false
browser log:

Related

Unit testing in vuejs

I am trying to configure/run my first unit test for Vuejs. But I can't get past the configuration issues. I have tried installing the libraries but for some reason I keep getting errors.
Here is what an example of my code looks like:
My directory structure:
hello/
dist/
node_modules/
src/
components/
hello.vue
test/
setup.js
test.spec.js
.babelrc
package.json
webpack.config.js
Contents inside my files
src/components/hello.vue
<template> <div> {{message}} </div> </template>
<script>
export default {
name: 'hello',
data () { return message: 'Hi' },
created () {
// ...
}
}
test/setup.js
// setup JSDOM
require('jsdom-global')()
// make expect available globally
global.expect = require('expect')
test/test.spect.js
import { shallow } from 'vue/test-utils'
import { hello} from '../../../src/components/hello.vue'
describe('hello', () => {
// just testing simple data to see if it works
expect(1).toBe(1)
})
.babelrc
{
"env": {
"development": {
"presets": [
[
"env",
{
"modules": false
}
]
]
},
"test": {
"presets": [
[
"env",
{
"modules": false,
"targets": {
"node": "current"
}
}
]
],
"plugins": [
"istanbul"
]
}
}
}
package.json
...
"scripts": {
"build": "webpack -p",
"test": "cross-env NODE_ENV=test nyc mocha-webpack --webpack-config webpack.config.js --require test/setup.js test/**/*.spec.js"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"cross-env": "^5.1.1",
"css-loader": "^0.28.7",
"file-loader": "^1.1.5",
"node-sass": "^4.7.2",
"sass-loader": "^6.0.6",
"vue-loader": "^13.5.0",
"vue-template-compiler": "^2.5.9",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7",
"jsdom": "^11.3.0",
"jsdom-global": "^3.0.2",
"mocha": "^3.5.3",
"mocha-webpack": "^1.0.0-rc.1",
"nyc": "^11.4.1",
"expect": "^21.2.1",
"#vue/test-utils": "^1.0.0-beta.12"
},
...
"nyc": {
"include": [
"src/**/*.(js|vue)"
],
"instrument": false,
"sourceMap": false
}
and finally my webpack.config.js
...
if(process.env.NODE_ENV == "test") {
module.exports.externals = [ require ('webpack-node-externals')()]
module.exports.devtool = 'inline-cheap-module-source-map'
}
now when I run npm test from my root folder hello/ I get this error:
> hello#1.0.0 test C:\Users\john\vue-learn\hello
> npm run e2e
> hello#1.0.0 e2e C:\Users\john\vue-learn\hello
> node test/e2e/runner.js
Starting selenium server... started - PID: 12212
[Test] Test Suite
=====================
Running: default e2e tests
× Timed out while waiting for element <#app> to be present for 5000 milliseconds. - expected "visible" but got: "not found"
at Object.defaultE2eTests [as default e2e tests] (C:/Users/john/Google Drive/lab/hello/test/e2e/specs/test.js:13:8)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
FAILED: 1 assertions failed (20.281s)
_________________________________________________
TEST FAILURE: 1 assertions failed, 0 passed. (20.456s)
× test
- default e2e tests (20.281s)
Timed out while waiting for element <#app> to be present for 5000 milliseconds. - expected "visible" but got: "not found"
at Object.defaultE2eTests [as default e2e tests] (C:/Users/john/Google Drive/lab/hello/test/e2e/specs/test.js:13:8)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello#1.0.0 e2e: `node test/e2e/runner.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello#1.0.0 e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\john\AppData\Roaming\npm-cache\_logs\2018-04-03T23_53_15_976Z-debug.log
npm ERR! Test failed. See above for more details.
I don't know why this happens. When I installed my webpack project at first I didn't install a testing library with the npm init command so there are no conflicts, but still I get that error:
update (after bounty)
I'm just trying to test my vuejs application. Hopefully with jasmine/karma. If anyone knows how to integrate these into a simple app and run the firsts test, I can take it from there. My problem is not writing tests but configuring it
So first thing you didn't need to enable the end to end testing in your project. I would say start fresh
$ npm install -g vue-cli
$ vue init webpack vue-testing
? Project name vue-testing
? Project description A Vue.js project
? Author Tarun Lalwani <tarun.lalwani#payu.in>
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests Yes
? Pick a test runner karma
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created? (recommended) yarn
Say N to Setup e2e tests with Nightwatch and use Karma for the Pick a test runner.
$ npm test
> vue-testing#1.0.0 test /Users/tarun.lalwani/Desktop/tarunlalwani.com/tarunlalwani/workshop/ub16/so/vue-testing
> npm run unit
> vue-testing#1.0.0 unit /Users/tarun.lalwani/Desktop/tarunlalwani.com/tarunlalwani/workshop/ub16/so/vue-testing
> cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run
07 04 2018 21:35:28.620:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
07 04 2018 21:35:28.629:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
07 04 2018 21:35:28.645:INFO [launcher]: Starting browser PhantomJS
07 04 2018 21:35:32.891:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket M1HeZIiOis3eE3mLAAAA with id 44927405
HelloWorld.vue
✓ should render correct contents
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 SUCCESS (0.061 secs / 0.041 secs)
TOTAL: 1 SUCCESS
=============================== Coverage summary ===============================
Statements : 100% ( 2/2 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
Lines : 100% ( 2/2 )
================================================================================
Now your npm test would work fine.
According to the error logs you provide here, the failing tests that you spot are the End to End ones. Indeed, by executing the command npm test e2e you're testing using Nightwatch. See under /tests/e2e/specs. Here you should have a default test file checking that your Vue application properly create a DOM element identified as app.
The test should be the following:
// For authoring Nightwatch tests, see
// http://nightwatchjs.org/guide#usage
module.exports = {
'default e2e tests': function (browser) {
// automatically uses dev Server port from /config.index.js
// default: http://localhost:8080
// see nightwatch.conf.js
const devServer = browser.globals.devServerURL
browser
.url(devServer)
.waitForElementVisible('#app', 5000)
.assert.elementPresent('.hello')
.assert.containsText('h1', 'Welcome to Your Vue.js App')
.assert.elementCount('img', 1)
.end()
}
}
In your case this test is failing because you have probably removed the file named App.vue that is generated through vue-cli scaffolding. The error you get is because the above test checks, with a 5 seconds timeout, if a DOM node named "app" is rendered (i.e.: .waitForElementVisible('#app', 5000)).
Basically it is failing because you actually do not provide this div in your application anymore (due of App.vue removal, maybe).
So you have two options here:
restoring the App.vue file (i.e.: create a div identified as 'app' where you mount a Vue instance);
editing the end to end according to your needs.
Hope this helps!

Codeception Allure Module error: [Doctrine\Common\Annotations\AnnotationException] The annotation "#env" ... was never imported

Our current project uses Codeception with the Codeception Allure addon and we are now seeing the following error when we run codecept run acceptance --env chrome --group banana --debug. This error began appearing a few days ago and we are unsure how to correct it. Has anyone ran into this error recently? I have found a number of old posts regarding similar issues but they have all been fixed by the project owners.
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "#env" in method
LogIntoAdminCest::logIntoAdmin() was never imported. Did you maybe
forget to add a "use" statement for this annotation?
Exception trace:
() at /vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54
Doctrine\Common\Annotations\AnnotationException::semanticalError() at /vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:727
Doctrine\Common\Annotations\DocParser->Annotation() at /vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:663
Doctrine\Common\Annotations\DocParser->Annotations() at /vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:354
Doctrine\Common\Annotations\DocParser->parse() at /vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php:284
Doctrine\Common\Annotations\AnnotationReader->getMethodAnnotations() at /vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/IndexedReader.php:71
Doctrine\Common\Annotations\IndexedReader->getMethodAnnotations() at /vendor/allure-framework/allure-php-api/src/Yandex/Allure/Adapter/Annotation/AnnotationProvider.php:43
Yandex\Allure\Adapter\Annotation\AnnotationProvider::getMethodAnnotations() at /vendor/allure-framework/allure-codeception/src/Yandex/Allure/Adapter/AllureAdapter.php:250
Yandex\Allure\Adapter\AllureAdapter->testStart() at n/a:n/a
call_user_func() at /vendor/symfony/event-dispatcher/EventDispatcher.php:212
Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at /vendor/symfony/event-dispatcher/EventDispatcher.php:44
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:90
Codeception\PHPUnit\Listener->startTest() at /vendor/phpunit/phpunit/src/Framework/TestResult.php:386
PHPUnit_Framework_TestResult->startTest() at /vendor/codeception/codeception/src/Codeception/Test/Test.php:74
Codeception\Test\Test->run() at /vendor/phpunit/phpunit/src/Framework/TestSuite.php:722
PHPUnit_Framework_TestSuite->run() at /vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:106
Codeception\PHPUnit\Runner->doEnhancedRun() at /vendor/codeception/codeception/src/Codeception/SuiteManager.php:157
Codeception\SuiteManager->run() at /vendor/codeception/codeception/src/Codeception/Codecept.php:184
Codeception\Codecept->runSuite() at /vendor/codeception/codeception/src/Codeception/Codecept.php:175
Codeception\Codecept->run() at /vendor/codeception/codeception/src/Codeception/Command/Run.php:376
Codeception\Command\Run->runSuites() at /vendor/codeception/codeception/src/Codeception/Command/Run.php:303
Codeception\Command\Run->execute() at /vendor/symfony/console/Command/Command.php:264
Symfony\Component\Console\Command\Command->run() at /vendor/symfony/console/Application.php:874
Symfony\Component\Console\Application->doRunCommand() at /vendor/symfony/console/Application.php:228
Symfony\Component\Console\Application->doRun() at /vendor/symfony/console/Application.php:130
Symfony\Component\Console\Application->run() at /vendor/codeception/codeception/src/Codeception/Application.php:103
Codeception\Application->run() at /vendor/codeception/codeception/codecept:36
run [-o|--override OVERRIDE] [-e|--ext EXT] [--report] [--html [HTML]] [--xml [XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--coverage-crap4j [COVERAGE-CRAP4J]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--] [<suite>] [<test>]

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.

Rails 4.2 console issues - using RAILS_ENV=development

trying to run
$ rails c RAILS_ENV=development
1 warning and 1 error are raised which I do not understand
# warning :
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
# error
/config/initializers/devise.rb:13:in `+': no implicit conversion of nil into String (TypeError)
However , the config.eager_load is set to false in the development environment
config/environment/development.rb
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
…/…
And looking at the config/initializers/devise.rb ( line 13) I have
config/initializers/devise.rb
Devise.setup do |config|
…/…
(13) config.mailer_sender = 'no-reply#' + Rails.application.secrets.domain_name
…/…
which lead to the config/secrets.yml file
config/secrets.yml
development:
domain_name: example.com
it's quite understandable , as running rails c ( whithout RAILS_ENV) , I get
$ rails c
development environment (Rails 4.2.3)
irb: warn: can't alias context from irb_context.
irb(main):001:0> Rails.application.secrets.domain_name
=> "example.com"
this warning is also cryptic :
irb: warn: can't alias context from irb_context
could not find any info on Google search... but at least it runs in development ....
why this warning and error using RAILS_ENV ? any enlightenment welcome
too bad .. I should HAVE READ the latest 4.2 doc !!!
so I should NOT be using RAILS_ENV at all !!
$ rails console staging
Loading staging environment (Rails 4.2.3)
irb(main):001:0> exit
$ rails console development
Loading development environment (Rails 4.2.3)
irb: warn: can't alias context from irb_context.
irb(main):001:0> exit

Grails possible race condition in database session?

I'm learning grails and read Grails In Action book. Try perform some tests from it, but got strange behaviour for me. I have next simple integration test:
#Test
public void testProjections() throws Exception {
User user1 = new User(mail: 'test1#test.tld', password: 'password1').save(flush: true)
User user2 = new User(mail: 'test2#test.tld', password: 'password2').save(flush: true)
assertNotNull(user1)
assertNotNull(user2)
// Chain add Tag to Post
user1.addToPosts(new Post(content: 'First').addToTags(new Tag(name: 'tag-0')))
// Separate add tag to post
Post post = user1.posts.iterator().next()
Tag tag1 = new Tag(name: 'tag-1')
post.addToTags(tag1)
// http://stackoverflow.com/questions/6288991/do-i-ever-need-to-explicitly-flush-gorm-save-calls-in-grails
// Have tried with and without next line without success:
//sessionFactory.getCurrentSession().flush()
assertEquals(['tag-0', 'tag-1'], user1.posts.iterator().next().tags*.name.sort()) // line 154
…
}
Then I run it twice subsequently:
grails>
grails> test-app -rerun -integration
| Running 5 integration tests... 2 of 5
| Failure: testProjections(com.tariffus.QueryIntegrationTests)
| java.lang.AssertionError: expected:<[tag-0, tag-1]> but was:<[tag-1]>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:743)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:144)
at com.tariffus.QueryIntegrationTests.testProjections(QueryIntegrationTests.groovy:154)
| Completed 5 integration tests, 1 failed in 0m 0s
| Tests FAILED - view reports in /home/pasha/Projects/grails/com.tariffus/target/test-reports
grails>
grails> test-app -rerun -integration
| Running 5 integration tests... 2 of 5
| Failure: testProjections(com.tariffus.QueryIntegrationTests)
| java.lang.AssertionError: expected:<[3, 1, 2]> but was:<[[tag-1, tag-2, tag-0, tag-5, tag-3, tag-4], [tag-6]]>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:743)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:144)
at com.tariffus.QueryIntegrationTests.testProjections(QueryIntegrationTests.groovy:164)
| Completed 5 integration tests, 1 failed in 0m 0s
| Tests FAILED - view reports in /home/pasha/Projects/grails/com.tariffus/target/test-reports
grails>
As you can see first fails on line 157 and second, runned just after that in second without any modification goes further.
I use Postgres database and environment test configured dataSource in mode dbCreate = 'update'.
What I do incorrect and why it works sometimes?
I would say that a source of problem is this line:
user1.addToPosts(new Post(content: 'First').addToTags(new Tag(name: 'tag-0')))
These dynamic addTo* methods does not propagate save to the associated instances until save() is called on the parent instance. So calling save() on user1 after should fix it:
user1.addToPosts(new Post(content: 'First').addToTags(new Tag(name: 'tag-0')))
user1.save()
This should propagate save() to Post instance at first and then to Tag instance transitively.