I try to configure simple project on jasmine using node.js. I got following files:
/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'**/*.testdev.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'foo',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 60000,
print: function() {}
},
useAllAngular2AppRoots: true,
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e'
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter());
}
};
Then a test file:
import {} from 'jasmine';
describe ("test", function() {
it ("should work", function() {
console.log('============ Main Workflow file starts');
});
});
And I receive error when I'm running npm test:
C:\newcheckproject>npm test
> newcheck#1.0.0 test C:\\newcheckproject
> protractor
(node:7492) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[12:47:12] I/launcher - Running 1 instances of WebDriver
[12:47:12] I/direct - Using ChromeDriver directly...
[12:47:15] E/launcher - Error: TypeError: SpecReporter is not a constructor
at onPrepare (C:\Users\OSP\WebstormProjects\newcheckproject\protractor.conf.js:30:38)
at q_1.Promise (C:\Roaming\npm\node_modules\protractor\lib\util.ts:48:39)
at Function.promise (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:682:9)
at Object.runFilenameOrFn_ (C:\Roaming\npm\node_modules\protractor\lib\util.ts:39:10)
at plugins_.onPrepare.then (C:\Roaming\npm\node_modules\protractor\lib\runner.ts:103:21)
at _fulfilled (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:796:13)
at C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:556:49
at runSingle (C:\Roaming\npm\node_modules\protractor\node_modules\q\q.js:137:13)
[12:47:15] E/launcher - Process exited with error code 100
npm ERR! Test failed. See above for more details.
All answers says that I should replace in the protractor file a line: var SpecReporter = require('jasmine-spec-reporter');, but I do have it. What might also a problem here?
Since 3.0.0, jasmine-spec-reporter module exports SpecReporter and DisplayProcessor.
According to the documentation, you need to configure it like this:
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter());
Related
I have two pipes in my Angular Projekt. The test for both of them look the same, and are just test for existance. One of them is failing with the error message: An error was thrown in afterAll\nUncaught TypeError: _this.handler.handle is not a function thrown
The test looks like the following:
it('create an instance', () => {
const pipe = new MyPipe();
expect(pipe).toBeTruthy();
});
Even when I change the code to not even creating the Pipe it still fails.
it('create an instance', () => {
expect(true).toBeTruthy();
});
So it seems to be something wrong with the test itself but I wasn't able to figure out why.
karma.conf.js
config.set({
basePath: '',
frameworks: ['jasmine', '#angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('#angular-devkit/build-angular/plugins/karma'),
require('karma-junit-reporter')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul', 'junit']
: ['progress', 'kjhtml', 'junit'],
junitReporter: {
outputFile: 'test-results.xml'
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
You should ensure the following is true in your code:
in the "spec" you are not including HttpClientModule and instead use HttpClientTestingModule
See the SO post here regarding that one:
TypeError: _this.handler.handle is not a function error
Also ensure that any subscribe from a http request has an error block.
Wrong:
this.myservice.func().subscribe(result => {
// do stuff
})
Right:
this.myservice.func().subscribe(result => {
// do stuff
}, error => {
// process error
})
See the SO post regarding that one:
Angular5 / ng test ERROR : TypeError: this.handler.handle is not a function
(top answer)
Note this is especially true if you do some sort of service call in ngInit.
I have been trying to trigger the browser and open Google using Karma with Jasmine.
Karma console is giving the following error:
Karma error message
Selenium-standalone log:
Selenium standalone log
Karma.conf.js->
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
plugins: [
'karma-browserify',
'karma-jasmine',
'karma-firefox-launcher'
],
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['browserify','jasmine'],
// list of files / patterns to load in the browser
files: [
'../../../scripts/jasmineTest.spec.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'../../../scripts/jasmineTest.spec.js' : [ 'browserify' ]
},
browserify: {
debug: true,
// transform: [ 'brfs' ]
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
My Jasmine script:
var wdio = require('../webdriverio')
describe("Jasmine test", function(){
var client = {}
client = wdio.remote({
desiredCapabilities: {
browserName: 'firefox'
}
})
client.init()
client.url("https://www.google.co.in")
it("test-1", function(done){
// expect(false).not.toBe(true)
// expect(2).toEqual(2)
done()
})
it("test-2", function(done){
// var a = ['A','B','C']
// expect(a).toContain('D')
done()
})
})
I am using nwb to configure a react app, I would use like to chai and enzyme to set up my testing environment. I have made the following changes to accomplish this, I created a tests.webpack.js file:
import chai from 'chai';
import chaiEnzyme from 'chai-enzyme';
import chaiAsPromised from 'chai-as-promised';
import sinonChai from 'sinon-chai';
chai.use(chaiEnzyme());
chai.use(chaiAsPromised);
chai.use(sinonChai);
const context = require.context('./src', true, /\.spec\.js/);
context.keys.forEach(context);
I also modified the karma config in nwb.config.js:
const karmaChaiPlugins = require('karma-chai-plugins');
module.exports = {
type: 'react-component',
npm: {
esModules: true,
umd: {
global: 'ReactMg',
externals: {
react: 'React',
},
},
},
karma: {
testContext: 'tests.webpack.js',
plugins: [
karmaChaiPlugins,
],
frameworks: ['mocha', 'chai', 'chai-as-promised'],
},
webpack: {
compat: {
enzyme: true,
sinon: true,
},
},
};
I get an error when running nwb test after defining index.spec.js in src:
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
TypeError: undefined is not a function (evaluating 'context.keys.forEach(context)')
at tests.webpack.js:73
PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.375 secs / 0 secs)
Karma exit code was 1
To fix error TypeError: undefined is not a function
You should change context.keys.forEach(context); on context.keys().forEach(context); because keys is function[1]
[1] - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
I'm trying to generate reports in Protractor and i followed this tutorial to do that.
Here is my conf.js file.
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter = new HtmlReporter({
baseDirectory: 'D:/My Work/Protractor/Financial/protractor-result', // a location to store screen shots.
docTitle: 'Protractor Demo Reporter',
docName: 'protractor-demo-tests-report.html'
});
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['invoice.js'],
capabilities: {
browserName: 'chrome',
},
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
},
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
}
}
I tried run this using command protractor conf.js and there's no folder generated containing test results. If I use command, protractor specs\configurations.js following error occurs.
ERROR - failed loading configuration file specs/conf.js
C:\Users\Manuli\AppData\Roaming\npm\node_modules\protractor\lib\configParser.js:
204
throw e;
^
Error: Cannot find module 'D:\My Work\Protractor\Financial\specs\conf.js'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at ConfigParser.addFileConfig (C:\Users\Manuli\AppData\Roaming\npm\node_modu
les\protractor\lib\configParser.js:195:22)
at Object.init (C:\Users\Manuli\AppData\Roaming\npm\node_modules\protractor\
lib\launcher.js:103:18)
at Object.<anonymous> (C:\Users\Manuli\AppData\Roaming\npm\node_modules\prot
ractor\lib\cli.js:140:23)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
Why can't I generate reports?
Thanks in advance. :)
I changesd my conf.js as this.
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'D:/My Work/Protractor/Financial/screenshots',
filename: 'my-report.html'
});
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['invoice.js'],
capabilities: {
browserName: 'chrome',
},
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
// Assign the test reporter to each running instance
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
}
Then I used npm install protractor-jasmine2-screenshot-reporter --save-dev command to install npm.
Working now. :)
I've tried setting up a minimal test demonstration, but I'm stuck when I try to run tests.
What I get is:
Listening on 0.0.0.0:9000
Starting tunnel...
Error: Failed to load module request from /tmp/local-selenium-intern/request.js (parent: tests/functional)
at <node_modules/intern/node_modules/dojo/dojo.js:757:12>
at <fs.js:207:20>
at Object.oncomplete <fs.js:107:15>
What I expect is that internal modules (such as request doesn't require any explicit configuration for them to load correctly).
I have this test configuration:
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
capabilities: {
'selenium-version': '2.35.0',
'idle-timeout': 30
},
environments: [
{ browserName: 'firefox' },
{ browserName: 'chrome' }
],
maxConcurrency: 3,
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
loader: {
// TODO: What to add here?
},
suites: [ 'tests/unit' ],
functionalSuites: [ 'tests/functional' ],
excludeInstrumentation: /^(?:tests|node_modules)\//
});
tests/functional.js contains this:
'use strict';
define([
'intern!object',
'intern/chai!assert',
'request'
], function (registerSuite, assert, request) {
registerSuite({
name: 'async demo',
'async test': function () {
var dfd = this.async(1000);
request('http://example.com/test.json').then(dfd.callback(function (data) {
assert.strictEqual(data, 'Hello world!');
}), dfd.reject.bind(dfd));
}
});
});
(An example from interns own documentation.)
The example provided is very basic and can be tested by downloading the code below followed `npm install && npm start``:
https://github.com/mzedeler/local-selenium-intern/tree/request-broken
From looking at your repository, I see you fixed the issue by using the request module from Intern's copy of Dojo. While this works, it's better to use your own copy of Dojo for your tests. Intern (the non-geezer version, at least) doesn't use standard Dojo, and makes no guarantees about the functionality therein. The current release of Dojo (1.10.0) is available through the npm repository, so it's easy to include as a project dependency.
Also, the test config in your project is a bit out of date. Specifically, the webdriver and useSauceConnect options have been replaced by tunnel and tunnelOptions. More information about the changes in Intern 2 is available in the 2.0.0 release notes.