Dojo 1.9 and Intern 1.7 - require.on is not defined? - javascript

Dojo 1.9 and Intern 1.7
I am having a problem with Intern in that it's reporting that require.on is not defined and my test suite is falling over.
This is only happening when trying to define a test that includes a widget. it looks like when the widget package is requried then it hits a line require.on("idle", onload) but fails because require.on is undefined.
As a test, I defined require.on and the test does not fall over.
All I can think of is that the version of dojo that intern ships with is interfering with the normal dojo module when requiring widgets using intern?
Here is a cut down version of my test:
define([
"intern!object",
"intern/chai!expect",
"dijit/form/Button"
],
function (
registerSuite,
expect,
Button) {
registerSuite({
name: "Simple test",
"failing test for demo" : function (){
expect(true).to.be.false;
}
});
});
Here is my configuration:
define({
// The port on which the instrumenting proxy will listen
proxyPort: 9000,
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
// Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
// specified browser environments in the `environments` array below as well. See
// https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and
// https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities.
// Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment
// automatically
capabilities: {
'selenium-version': '2.40.0'
},
// Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce
// OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other
// capabilities options specified for an environment will be copied as-is
environments: [
{ browserName: 'chrome' }
],
// Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
maxConcurrency: 3,
// Whether or not to start Sauce Connect before running tests
useSauceConnect: false,
// Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password
// in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be
// publishing this configuration file somewhere
webdriver: {
host: 'localhost',
port: 4444
},
// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
// can be used here
loader: {
// Packages that should be registered with the loader in each testing environment
packages: [
{
name: "dojo",
location: "libs/dojo"
}{
name: "dijit",
location: "libs/dijit"
},{
name: "unitTests",
location: "test/unit"
}
]
},
// Non-functional test suite(s) to run in each browser
suites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */
"unitTests/exampleTest"
],
// Functional test suite(s) to run in each browser once non-functional tests are completed
functionalSuites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */
],
// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^tests\//
});
Folder structure is:
app/
libs/
dojo
dijit
intern
test/
unit/
exampleTest.js
intern.js
I am running the test straight from the google chrome browser:
http://{webroot}/app/libs/intern/client.html?config=../test/intern
I do have some tests that run successfully but do not include any widgets.
Thanks for any help.

You are running an outdated version of Dojo 1.9 that expects that the AMD loader being used is the one that comes with Dojo 1.9, which is not the case in a default installation of Intern. You have two options:
Upgrade to Dojo 1.9.3 or later. (Recommended.)
Use the useLoader configuration option to point to dojo.js from your copy of Dojo 1.9:
define({
// ...
useLoader: {
'host-browser': 'path/to/dojo1.9/dojo.js'
}
})

Related

multiCapabilities and jasmine focused tests

The Story:
We have a rather huge end-to-end protractor test codebase. We have two configs - one is "local" - to run the tests in Chrome and Firefox using directConnect, and the other one is "remote" - to run tests on a remote selenium server - BrowserStack in our case.
Our "local" config is configured to run some tests in Chrome and some in Firefox - because we really cannot run some tests in Chrome - for instance, keyboard shortcuts don't work in Chrome+Mac. Running the tests that require using keyboard shortcuts in Firefox is a workaround until the linked chromedriver issue is resolved.
Here is the relevant part of the configuration:
var firefox_only_specs = [
"../specs/some_spec1.js",
"../specs/some_spec2.js",
"../specs/some_spec3.js"
];
exports.config = {
directConnect: true,
multiCapabilities: [
{
browserName: "chrome",
chromeOptions: {
args: ["incognito", "disable-extensions", "start-maximized"]
},
specs: [
"../specs/**/*.spec.js",
"../specs/**/**/*.spec.js",
"../specs/**/**/**/*.spec.js"
],
exclude: firefox_only_specs
},
{
browserName: "firefox",
specs: firefox_only_specs
}
],
// ...
};
The problem:
Now, the problem is that, if I'm debugging a single test, or want to run a single test - I'm marking it is as focused (via fdescribe/fit) - but protractor starts two driver sessions - one for Chrome and the other one for Firefox, using both configured capabilities:
Running "protractor:local" (protractor) task
[launcher] Running 2 instances of WebDriver
...
------------------------------------
[chrome #1] PID: 2329
[chrome #1] Using ChromeDriver directly...
[chrome #1] Spec started
...
------------------------------------
[firefox #2] PID: 2330
[firefox #2] Using FirefoxDriver directly...
[firefox #2] Spec started
...
The question:
Is there a way to tell protractor to use the only one capability that has a focused spec configured?
Using currently latest protractor 3.0.0.
Hope the question is clear. Let me know if you need any additional information.
I wonder if you can do something to wrap the it statements like:
onPrepare: function() {
browser.getCapabilities().then(function(caps) {
global.browserName = caps.caps_.browserName;
});
global.firefoxOnly = function(name, testFunction) {
if (browserName === 'firefox') {
return it(name, testFunction);
} else {
return xit(name, testFunction).pend('firefox only');
}
};
}
Then when you write a test, instead of it use something like:
describe('when I do something', function() {
firefoxOnly('it should do the right thing', function() {
doSomething();
expect(thing).toBe(right);
)};
});
I have no idea if this actually works, just throwing it out there. In fact, when I get back to my testing computer and try it out, I would be interested in adding a function like wip to use instead of xit to automatically pend my ATDD tests!
Is there a way to tell protractor to use the only one capability that has a focused spec configured?
According to the relevant github issue, it is not possible.

jspm + karma + karma-jspm + plugin-typescript

This post is stackoverflow repost from my issues at https://github.com/frankwallis/plugin-typescript/issues/64 and https://github.com/Workiva/karma-jspm/issues/112
We plan to upgrade our team stack for web ui so we decide:
1) use Karma as test launcher and jasmine as framework ( mocha and custom runners before)
2) use TypeScript for source code with UMD or system module out (pure Javascript before)
3) use SystemJS as module loader to allow use different module's types (CommonJS, AMD, system , ES6) without overheat ( RequireJS before)
And additionally:
1) we want to run tests directly from typescript code without precompilation and storing JS on disk
2) we want to have test environment layout very close to production layout
3) we have setup karma + jasmine + karma-typescript-preprocessor and it works well. BUT we want ot work with JSPM/SystemJS loader while in this case we will be sure that our test environment match production where SystemJS loader is used. Becuase for another hand we will require to write some custom bootstrap things for test-only.
But we have problems with karma + jspm + typescript-plugin (jspm).
In JSPM './config.js'
System.config({
baseURL: "/",
"transpiler": false,
"packages": {
"src": {
"main": "test.ts",
"defaultExtension": "ts",
"meta": {
"*.ts": {
"loader": "ts"
},
"*.js": {
"loader": "ts"
}
}
}
},
paths: {
"npm:*": "jspm/npm/*",
"github:*": "jspm/github/*"
},
map: {
"ts": "github:frankwallis/plugin-typescript#2.2.3",
"typescript": "npm:typescript#1.6.2",
"github:frankwallis/plugin-typescript#2.2.3": {
"typescript": "npm:typescript#1.6.2"
}
}
});
In Karma config:
// Karma configuration
// Generated on Mon Nov 30 2015 02:58:44 GMT+0500 (RTZ 4 (зима))
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jspm','jasmine'],
plugins:[
"karma-jspm",
'karma-jasmine',
'karma-chrome-launcher'
],
jspm: {
loadFiles: ['src/test.ts'], //we just try to check one simple test
packages: "jspm/"
} ,
proxies : { // avoid Karma's ./base virtual directory
'/src/': '/base/src/',
'/jspm/': '/base/jspm/'
},
reporters: ['progress'],
port: 9876,
browsers: ['Chrome']
})
}
But something goes wrong:
30 11 2015 14:53:34.564:WARN [web-server]: 404: /jspm/github/frankwallis/pl
ugin-typescript#2.2.3
Chrome 46.0.2490 (Windows 10 0.0.0) ERROR: 'Potentially unhandled rejection [6]
Error: XHR error (404 Not Found) loading http://localhost:9876/jspm/github/frank
wallis/plugin-typescript#2.2.3
at error (http://localhost:9876/base/jspm/system.src.js?6536115be64e0ff966e0
5546f7767676fa7c03d6:1020:16)
at XMLHttpRequest.xhr.onreadystatechange (http://localhost:9876/base/jspm/sy
stem.src.js?6536115be64e0ff966e05546f7767676fa7c03d6:1028:13)'
And we checked that url is valid: for ex /jspm/github/frankwallis/plugin-typescript#2.2.3\utils.js is served well by Karma.
I don't understand why it trys to load whole typescript plugin directory.
So we have question:
1) Is it a bug or our fail in understanding/config
2) If it's our fail - how to fix it?
3) May be we choose not correct how to test with Karma + JSPM + Typescript?
Any advice will be helpful.
Have found mistake ourselves: "defaultJSExtensions": true, was not in .\config.js
I used karma-uiuxengineering-jspm instead of karma-jspm.
It's a fork which seemed to fix my problems at the time, and which supports JSPM 0.17-beta.
The repo also has some seed projects for angular2 and typescript (using JSPM) with a testing environment. It really helped me the set up my project.

Why does using Mongo in package tests fail when the package has api.use('mongo')?

I'm developing a custom package. Its package.js is :
Package.describe({
name: 'adigiovanni:one-way-accounts',
version: '0.0.1',
summary: 'One Way Accounts',
git: '',
documentation: 'README.md',
});
Package.onUse(function (api) {
api.versionsFrom('1.2.0.2');
api.use('ecmascript');
api.use('mongo');
// api.imply('mongo');
api.addFiles([
'lib/collections/Accounts.js',
'lib/methods.js',
'lib/OneWayAccounts.js',
]);
api.export('OneWayAccounts');
});
Package.onTest(function (api) {
api.use([
'ecmascript',
'sanjo:jasmine#0.20.2',
'velocity:html-reporter',
]);
api.use('adigiovanni:one-way-accounts');
api.addFiles('tests/client/OneWayAccounts.js', 'client');
api.addFiles('tests/server/OneWayAccounts.js', 'server');
});
As you can see, package makes use of 'mongo'.
Tests fail with :
Reference error: Mongo is not defined
But if I uncomment the line api.imply('mongo') then tests succeed.
Same odd behavior applies to ecmascript dependency, if I don't api.use('ecmascript') in Package.onTest, tests fail.
Meteor version is 1.2.0.2.
Test runner is velocity.
Test framework is jasmine.
I am using Mongo and ES6 syntax and features in my tests.
What is happening and how can I fix it?
Using a package with api.use('other-package') in Package.onUse does not make 'other-package' available in your test codes in the same way it doesn't make it available for other packages that use('my-package') or in applications that meteor add my-package. To solve this issue there is two solutions depending on the need for other-package :
Allowing users of the package (including your tests) to access 'other-package' with api.imply
Package.onUse(function (api) {
//...
api.imply('other-package')
//...
})
This makes sense if and only if the package you imply is necessary to use your own package. Do not imply everything willy-nilly for scope convenience. See more in this question.
If it does not fall into that category,
Simply use the package in your tests
Package.onTest(function (api) {
//...
api.use('my-package')
api.use('other-package')
//...
})
This will allow you to use other-package in your tests too, without polluting scopes.

Trouble with Jasmine and Karma with Backbone

This is my first time testing an app and it's a bit of a headache. I have set up a testing enviroment. My index.html for jasmine within my test folder looks like this:
index.html
<!doctype html>
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" href="../bower_components/jasmine/lib/jasmine-core/jasmine.css">
</head>
<body>
<script src="../bower_components/jasmine/lib/jasmine-core/jasmine.js"></script>
<script src="../bower_components/jasmine/lib/jasmine-core/jasmine-html.js"></script>
<script src="../bower_components/jasmine/lib/jasmine-core/boot.js"></script>
<!-- include source files here... -->
<script src="../public/js/main.js"></script>
<script src="../public/js/AppView.js"></script>
<script src="../public/js/FormLoanView.js"></script>
<script src="../public/js/FormLoanModel.js"></script>
<script src="../public/js/ResponseLoanModel.js"></script>
<script src="../public/js/ResultLoanView.js"></script>
<!-- include spec files here... -->
<script src="spec/test.js"></script>
</body>
</html>
test.js
(function () {
describe('Form Model', function() {
describe('when instantiated', function() {
it('should exhibit attributes', function() {
var formModel = new FormLoanModel({});
console.log(formModel)
expect(formModel.get("Annual Income"))
.toEqual("");
});
});
});
})();
When opening my index.html I get the following message:
TypeError: undefined is not a function
So it looks like its running my test. After opening chrome developer tools, I get the following:
Uncaught ReferenceError: Backbone is not defined
So I realized jQuery and Backbone are not being loaded into the test. I came to learn that Karma helps us automate a lot of this. After using Yeoman to set up karma. I made edits to my karma.conf.js which now looks like this:
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2015-07-12 using
// generator-karma 1.0.0
module.exports = function(config) {
'use strict';
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
// as well as any additional frameworks (requirejs/chai/sinon/...)
frameworks: [
"jasmine"
],
// list of files / patterns to load in the browser
files: [ "../lib/*.js","../public/js/*.js","./spec/*.js"
],
// list of files / patterns to exclude
exclude: [
],
// web server port
port: 8080,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
"Chrome"
],
// Which plugins to enable
plugins: [
"karma-phantomjs-launcher",
"karma-jasmine"
],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
The files I added were libraries, my backbone modules, and my Jasmine tests. After typing karma start I get the following success screen at the local server indicated by the terminal:
Karma v0.12.37 - connected
Chrome 43.0.2357 (Mac OS X 10.10.2) is idle
So finally at this point I was hoping for index.html after refresh would correctly run my test, but it's not. It is still warning my about its lack of knowledge of backbone and jQuery. Can anyone help me figure out where I am going wrong?
File Strucutre
ROOT
-----lib
--------------backbone.js
--------------underscore.js
--------------jquery-1.11.3.js
-----public
--------------js
---------------------*backbone modules*
-----test
--------------spec
----------------------test.js
--------------index.html
--------------karma.conf.js
The 'basePath' and 'files' attributes of your Karma config work together to serve up the necessary files in the browser for the testing environment.
The base path will be evaluated from the working directory that Karma is run from, so if you run it in the root dir of your project, then '../libs/*.js' will not be a matching path for your bower_component javascript files, most likely.
If your static file folder tree does not start in the root dir of your project, then make sure 'basePath' points to where your static file folder tree starts.
try ../bower_components/**/*.js or ../**/*.js (file blob pattern style) or try adding an individual entry to "files" that points to each, i.e.,
'../bower_components/jquery/lib/jquery.min.js',
'../bower_components/jquery/lib/backbone.min.js'
etc, of course, making these entries point to the real locations. I'm guessing it's just this file path issue that's preventing them from being found, and therefore Karma's testing server is not serving them to the browser.

Intern - ReferenceError: document is not defined

Seeing this Error message when I'm trying to run Intern tests from within my test files dir. the (relevant) structure of the dir is:
test
resources
rest
pickup.js
cashManagement.js
gitignore
intern.js
packages.js
packages.sample.js
...
The inter.js contains references to testFile1.js and testFile2.js in the suites section. I played a bit with the way these 2 files are referenced and got a "Failed to load module..." error. So I guess now that's solved and the ReferenceError is the one I need to figure out. I did go over the existing threads and nothing seems to solve my issue. The full error message is pasted below. I'll gladly supply more relevant info if needed.
Thanks,
Eran
***ReferenceError: document is not defined**
at /Applications/dojo-release-1.10.2/dojo/has.js:31:33
at execModule (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:515:54)
at /Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:504:12
at Array.map (native)
at execModule (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:499:17)
at /Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:582:7
at guardCheckComplete (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:566:4)
at checkComplete (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:574:27)
at onLoadCallback (/Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:656:7)
at /Users/eranbrand/src/MobilePosSolution/ovc-build/ovc-repo/src/test/node_modules/intern/node_modules/dojo/dojo.js:761:5*
Here's the content of the intern.js file:
// Learn more about configuring this file at <https://github.com/theintern/intern/wiki/Configuring-Intern>.
// These default settings work OK for most people. The options that *must* be changed below are the
// packages, suites, excludeInstrumentation, and (if you want functional tests) functionalSuites.
serviceURL = "http://ovc.local:8080/POSMClient/json/process/execute/";
define(['./packages'], function(Packages) {
var returnValue = {
// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
// can be used here
loader: {
packages: Packages.packages
},
// The port on which the instrumenting proxy will listen
proxyPort: 9000,
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
// Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
// specified browser environments in the `environments` array below as well. See
// https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and
// https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities.
// Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment
// automatically
capabilities: {
'selenium-version': '2.39.0'
},
// Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce
// OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other
// capabilities options specified for an environment will be copied as-is
environments: [/*
{ browserName: 'internet explorer', version: '11', platform: 'Windows 8.1' },
{ browserName: 'internet explorer', version: '10', platform: 'Windows 8' },
{ browserName: 'internet explorer', version: '9', platform: 'Windows 7' },
{ browserName: 'firefox', version: '27', platform: [ 'OS X 10.6', 'Windows 7', 'Linux' ] },
{ browserName: 'chrome', version: '32', platform: [ 'OS X 10.6', 'Windows 7', 'Linux' ] },
{ browserName: 'safari', version: '6', platform: 'OS X 10.8' },
{ browserName: 'safari', version: '7', platform: 'OS X 10.9' }*/
],
// Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
maxConcurrency: 3,
// Whether or not to start Sauce Connect before running tests
useSauceConnect: false,
// Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password
// in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be
// publishing this configuration file somewhere
webdriver: {
host: 'localhost',
port: 4444
},
// The desired AMD loader to use when running unit tests (client.html/client.js). Omit to use the default Dojo
// loader
useLoader: {
'host-node': 'dojo/dojo',
'host-browser': 'node_modules/dojo/dojo.js'
},
// Non-functional test suite(s) to run in each browser
suites: [
"rest/pickup",
"rest/cashManagement"
],
// Functional test suite(s) to run in each browser once non-functional tests are completed
functionalSuites: [ /* 'myPackage/tests/functional' */ ],
// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^tests\//
}
return returnValue;
});
It looks like you're using the release build of Dojo, which assumes the document object will be available. To use that build you'll need to run intern with intern-runner or the browser client (client.html). If you'd prefer to run your tests with the node client (intern-client), you'll need to use the source distribution of Dojo or the dojo npm package.

Categories

Resources