We have been pulling our hair for a few days and can't really seem to get a hold of the actual problem. We wanted to create a testbench, to increase our code coverage but this proved to be not so easy as anticipated.
After including the correct zone files, we found, by looking at the QuickStart from angular, that we needed to call TestBed.initTestEnvironment. Which needs to parameters, which we imported:
import * as browserTesting from '#angular/platform-browser-dynamic/testing';
TestBed.initTestEnvironment(
browserTesting.BrowserDynamicTestingModule,
browserTesting.platformBrowserDynamicTesting()
);
However, as soon as we try and run this via Karma (with jasmine) we run into a 404:
Running "karma:single" (karma) task
Verifying property karma.single exists in config...OK
File: [no files]
Options: background=false, client={}
20 12 2016 13:22:25.757:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
20 12 2016 13:22:25.764:INFO [launcher]: Starting browser Chrome
20 12 2016 13:22:26.439:INFO [Chrome 54.0.2840 (Linux 0.0.0)]: Connected on socket cuixl-0soveFUA_PAAAA with id 58970475
20 12 2016 13:22:26.711:WARN [web-server]: 404: /base/jspm_packages/npm/#angular/compiler#2.3.0/bundles/compiler-testing.umd.js/index.js
20 12 2016 13:22:26.713:WARN [web-server]: 404: /base/jspm_packages/npm/#angular/core#2.3.0/bundles/core-testing.umd.js/index.js
20 12 2016 13:22:26.714:WARN [web-server]: 404: /base/jspm_packages/npm/#angular/platform-browser#2.3.0/bundles/platform-browser-testing.umd.js/index.js
Chrome 54.0.2840 (Linux 0.0.0) ERROR
Error: (SystemJS) XHR error (404 Not Found) loading /home/arend/Documents/Projects/Barco/opspace/barco-opspace/jspm_packages/npm/#angular/compiler#2.3.0/bundles/compiler-testing.umd.js/index.js
Error: XHR error (404 Not Found) loading /home/arend/Documents/Projects/Barco/opspace/barco-opspace/jspm_packages/npm/#angular/compiler#2.3.0/bundles/compiler-testing.umd.js/index.js
at XMLHttpRequest.wrapFn [as _onreadystatechange] (/home/arend/Documents/Projects/Barco/opspace/barco-opspace/jspm_packages/npm/zone.js#0.7.2/dist/zone.js:729:25) [<root>]
at Zone.runTask (/home/arend/Documents/Projects/Barco/opspace/barco-opspace/jspm_packages/npm/zone.js#0.7.2/dist/zone.js:135:41) [<root> => <root>]
at XMLHttpRequest.ZoneTask.invoke (/home/arend/Documents/Projects/Barco/opspace/barco-opspace/jspm_packages/npm/zone.js#0.7.2/dist/zone.js:285:27) [<root>]
Error loading /home/arend/Documents/Projects/Barco/opspace/barco-opspace/jspm_packages/npm/#angular/compiler#2.3.0/bundles/compiler-testing.umd.js/index.js as "./bundles/compiler-testing.umd.js/index" from /home/arend/Documents/Projects/Barco/opspace/barco-opspace/jspm_packages/npm/#angular/compiler#2.3.0/testing.js
looking at "jspm_packages/npm/#angular/compiler#2.3.0/testing.js", we quickly found that it held the wrong information:
module.exports = require('./bundles/compiler-testing.umd.js/index');
instead of the expected:
module.exports = require('./bundles/compiler-testing.umd');
If I manually correct this, all works perfectly. So my question:
How do we prevent JSPM or anyone from generating a wrong testing.js file?
Our idea is that, for some reason, jspm thinks the compiler-testing.umd.js file is a folder and so appends /index to it
*we included the angular files via config.js: *
System.config({
defaultJSExtensions: true,
transpiler: "typescript",
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
map: {
"#angular/common": "npm:#angular/common#2.3.0",
"#angular/compiler": "npm:#angular/compiler#2.3.0",
"#angular/core": "npm:#angular/core#2.3.0",
"#angular/core/testing": "npm:#angular/core#2.3.0/bundles/core-testing.umd.js",
"#angular/forms": "npm:#angular/forms#2.3.0",
"#angular/http": "npm:#angular/http#2.3.0",
"#angular/http/testing": "npm:#angular/http#2.3.0/bundles/http-testing.umd.js",
"#angular/platform-browser": "npm:#angular/platform-browser#2.3.0",
"#angular/platform-browser-dynamic": "npm:#angular/platform-browser-dynamic#2.3.0",
"#angular/platform-browser-dynamic/testing": "npm:#angular/platform-browser-dynamic#2.3.0/bundles/platform-browser-dynamic-testing.umd.js",
"#angular/router": "npm:#angular/router#3.3.0",
After a long and extensive search and hours of comparison, I actually found the problem and the solution to all this:
Problem: the angular2 examples all use the npm_modules and so they adapted the systemjs file to use the npm folder, however, we opt to use JSPM as this makes a clean cut between our backend/infrastructure and our frontend. Allowing us to, without having to change our configuration, add/remove/upgrade packages. Because angular2 modules are actually 2 modules in one, it caused JSPM to to funny things with this and thus, in the end, always tried to load the wrong file: e.g. "core-testing.umd.js/index" instead of just "core-testing.umd".
Solution: finally I struck gold: update to jspm 0.17 (at the time of writing this is still in beta)
The new JSPM correctly detects the testing module as well and loading is now done correctly!
Related
I just started developing my first application with Ionic 3 and I am now in the process of making some unit tests. Now I am facing a problem "compiling" the a unit test of a Service when Platform is one of its dependencies.
Here is the abstract of the Service:
#Injectable()
export class MyService {
constructor(public platform: Platform) {}
myMethod(): Observable<any> {
if (this.platform.is('android')) {
return new Observable(android);
else if (this.platform.is('ios')) {
return new Observable(iOS);
}
}
}
And here is the Unit Test I made following some tutorials from the Internet:
describe('XXX', () => {
var service: MyService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [MyService, Platform]
});
});
it('should xxx', inject([MyService], (service) => {
var result = service.mymethod();
expect(result).toBeDefined();
}));
});
The configuration for my tests has been made following this blog post. I have some other spec files that run successfully, except for this one that throws the following error:
PS C:\Workspaces\JS-TS\taccess> npm run test
> taccess#0.0.1 test C:\Workspaces\JS-TS\taccess
> karma start ./test-config/karma.conf.js --single-run
(node:17164) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
‼ 「wdm」:
i 「wdm」: Compiled with warnings.
i 「wdm」: Compiling...
‼ 「wdm」:
i 「wdm」: Compiled with warnings.
26 07 2018 07:20:43.963:INFO [karma]: Karma v2.0.5 server started at http://0.0.0.0:9876/
26 07 2018 07:20:44.003:INFO [launcher]: Launching browser Chrome with unlimited concurrency
26 07 2018 07:20:44.806:INFO [launcher]: Starting browser Chrome
26 07 2018 07:20:54.988:INFO [Chrome 68.0.3440 (Windows 10 0.0.0)]: Connected on socket u2KlYyff-qRa_fnHAAAA with id 6508927
Chrome 68.0.3440 (Windows 10 0.0.0) ERROR
{
"message": "An error was thrown in afterAll\nUncaught Error: Cannot find module './components/app/app-root'",
"str": "An error was thrown in afterAll\nUncaught Error: Cannot find module './components/app/app-root'"
}
Chrome 68.0.3440 (Windows 10 0.0.0) ERROR
{
"message": "An error was thrown in afterAll\nUncaught Error: Cannot find module './components/app/app-root'",
"str": "An error was thrown in afterAll\nUncaught Error: Cannot find module './components/app/app-root'"
}
Chrome 68.0.3440 (Windows 10 0.0.0): Executed 0 of 0 ERROR (0.008 secs / 0 secs)
Chrome 68.0.3440 (Windows 10 0.0.0): Executed 0 of 0 ERROR (0.142 secs / 0 secs)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! taccess#0.0.1 test: `karma start ./test-config/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the taccess#0.0.1 test 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\xxx\AppData\Roaming\npm-cache\_logs\2018-07-26T05_20_56_762Z-debug.log
Why do I need to inject Platform into the Service? Because I am using the Cordova pluging for BLE and there are some differences between iOS and Android than I need to manage.
Has anyone any clue about what is happening? What am I doing wrong?
Note 1: I have checked removing the dependency with Platform and the test (with some modifications due the lack of Platform) works just fine.
After some time I have discovered what the problem is: Visual Studio Code.
For some reason VSCode changed this import
import { Platform } from 'ionic-angular';
to this other
import { Platform } from 'ionic-angular/umd';
As soon as I removed the /umd everyhting worked like a charm.
Hope this helps others in the future.
As title, i try the unit test with Karma in lastest version of Vue.
i am sure the test file is currect because i run it in defalut vue appliction.It runs well.
But when i run npm run unit in my working application, i gives error info below:
Chrome 65.0.3325 (Mac OS X 10.13.3) ERROR
Uncaught ReferenceError: Vue is not defined
at webpack:/external%20%22Vue%22:1:0 <- index.js:1418
i googled this for a long time, but got nothing. Is anyone met this before?
after rest for a while, i think through it. Why it will lint Vue is not defined? And how does the test component work? I wonder it may be caused by my Vue import Strategies. In order to reduce the time of page opened in browser, i import vue and other packages using CDN, i guess it can't accepted by Karma.I tried to roll back,and run npm run unit,fortunately, everything runs well.
Chrome 65.0.3325 (Mac OS X 10.13.3): Executed 1 of 1 SUCCESS (0.034 secs / 0.011 secs)
TOTAL: 1 SUCCESS
thank you, guys.Think and solve the problem is really magic and exciting.
I am newbie to laravel. I am using laravel 5.4 version, we have requirement of writing phpunit test cases for our application, So I have searched for writing phpunit testcases and also read the documentation in laravel website. I read about the 'dusk' feature for doing the browser tests. So, I have a doubt that is "Is the dusk is mandatory for writing the phpunit test cases in laravel 5.4? I also tried to install the 'dusk' package into our application but it is not getting installed after I run the command "composer require laravel/dusk".
below is the error that I am getting on command prompt:
c:\xampp\htdocs\ourappname>composer require laravel/dusk
using version ^1.1 for laravel/dusk
./composer.json has been updated
Loading composer repositories with package information
Updating dependies (including require-dev)
Package operations: 2 installs, 4 updates, 9 removals
- Removing maatwebsite/excel (2.1.17)
- Removing phpoffice/phpexcel (1.8.1)
- Removing jeremeamia/superclosure (2.3.0)
- Removing symfony/polyfill-php56 (v1.3.0)
- Removing symfony/polyfill-util (v1.3.0)
- Removing guzzlehttp/guzzle (6.2.3)
- Removing guzzlehttp/psr7 (1.4.2)
- Removing psr/http-message (1.0.1)
- Removing guzzlehttp/promises (v1.3.1)
- Updating psy/psysh (v0.8.3 => v0.8.5): Loading from cache
- Updating swiftmailer/swiftmailer (v5.4.7 => v5.4.8): Loading from cache
- Updating sebastian/diff (1.4.1 => 1.4.2): Loading from cache
- Updating laravel/framework (v5.4.21 => v5.4.23): Loading from cache
- Installing facebook/webdriver (1.4.1): Loading from cache
- Installing laravel/dusk (v1.1.0): Loading from cache
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Maatwebsite\Excel\ExcelServiceProvider' not found
Script php artisan optimize handling the post-update-cmd event returned with error code 1
Installation failed, reverting ./composer.json to its original content.
c:\xampp\htdocs\ourappname>
Anyone please tell me how to fix it? and also what is the process for writing the test cases in laravel 5.4? should we use 'dusk'? or any other way to do it? Thanks.
No, Dusk is not required to do unit testing. You can just use the basic tests.
Your error is related to when you installed the Excel package on your application; the Service Provider was added to your config/app.php, but now that you've removed the package from your application ("Removing maatwebsite/excel (2.1.17)") you also need to remove the Service Provider.
I've been asked to evaluate Robotframework and happy with what I've seen for the most part. For it to be a viable option for me however, I need it to work in Firefox.
Marionette capabilities were a problem in my Ruby/Capybara environment, and I was able to shut it off.
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox, desired_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false))
end
Getting the same thing in Robot / Python 2.7 / ff44.0 has generated an error in either direction.
When marionette is on:
${dc} Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.FIREFOX sys, selenium.webdriver
Set To Dictionary ${dc} marionette=${True}
Open Browser ${url_bck_auto} Firefox desired_capabilities=${dc}
I get this:
Our products rock | FAIL |
WebDriverException: Message: Unsupported Marionette protocol version
2, required 3
If I turn it off, gecko bumps me to ff51.0.1(32-bit) and I get a different message:
Our products rock | FAIL |
WebDriverException: Message: Can't load the profile. Possible firefox
version mismatch. You must use GeckoDriver instead for Firefox 48+.
Profile Dir: c:\users\blah\appdata\local\temp\tmpqzlxha\webdriver-
py-profilecopy If you specified a log_file in the FirefoxBinary
constructor, check it for details.
Geckodriver is version 0.15.0
Any help will be appreciated, thanks!
On Windows 10 I'm running Robot Framework 3.0, Selenium2Library 1.8.0, Selenium 3.0.2 and when I start your example, or the simplified single open browser http://google.com I get the same result when using Gecko 0.15.0. The browser starts but does not move to the desired page. The driver closes successfully but the browser stays open.
When using the same setup, but downgrading Geckodriver to 0.14.0 the results change, and the browser behaves as expected. Loads the page and closes when Close Browser keyword is called.
So, I recommend downgrading to Geckodriver 0.14.0.
I was using version 3.3 of the otrs and decided to upgrade to 4.0.9. I took to first uninstall all the modules that are not official (KIX4OTRS, complement and others), but after the upgrade by following the steps of the official documentation, without mistakes, I'm in trouble while trying to access the overview in the CMDB . The error occurs only in the overview, the creation and modification of items usually works.
Even after removing the KIX4OTRS still contained some messages it.
Error:
Backend ERROR: OTRS-CGI-10 Perl: 5.16.0 OS: linux Time: Wed Oct 21 14:26:45 2015 Message: No config option found for the view 'Custom'! RemoteAddress: 191.1.200.123 RequestURI: /otrs/index.pl?Action=AgentITSMConfigItem Traceback (3255): Module: Kernel::Output::HTML::LayoutITSMConfigItem::ITSMConfigItemListShow Line: 332 Module: Kernel::Modules::AgentITSMConfigItem::Run Line: 302 Module: Kernel::System::Web::InterfaceAgent::Run Line: 996 Module: ModPerl::ROOT::ModPerl::Registry::opt_otrs_bin_cgi_2dbin_index_2epl::handler Line: 41 Module: (eval) (v1.99) Line: 204 Module: ModPerl::RegistryCooker::run (v1.99) Line: 204 Module: ModPerl::RegistryCooker::default_handler (v1.99) Line: 170 Module: ModPerl::Registry::handler (v1.99) Line: 31
*I checked the Perl modules are all Okay
*My ITSM is version 4.0.9
It worked! Finally ... I used DataBase Browser software and deleted some entries and now I can access the CMDB. I deleted some entries referring to my ID in the table "user_preferences" session_id and session_profile. I'm not sure with was responsible for solving the problem.