intern
A next-generation code testing stack for JavaScript.
Intern: The user guide
How do asynchronous tests work in Intern testing framework? I have tried to get them run exactly as in the example, but the async test passes immediately without waiting for the callback to be run.
it('should connect in 5 seconds', function () {
var dfd = this.async(5000);
conn.connect(credentials, dfd.callback(function(result) {
expect(result).to.... something
}));
}
The test passes immediately. What am I doing wrong?
Source: (StackOverflow)
I want to try running an Intern functional test (i.e. using webdriver) on a single browser, on the local machine. The doc says that I need a "Selenium 2 Server".
How do I setup the server exactly though? Do I need to download and install it separately from Intern? (If so, how?) And do I need to start it as a separate process, before calling "node runner.js"? (If so, how?)
Source: (StackOverflow)
I'm trying to set up Intern.io so I can test my angular app. I'm also using Grunt and Bower. I'm just trying to get barebones watch task that automatically runs the tests. My problem when I try to run tests is I get the following error message:
Running "intern:app" (intern) task
ReferenceError: window is not defined
at /Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/vendor/src/angular/angular.js:19288:3
at Function.vm.runInThisContext (/Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/node_modules/intern/node_modules/istanbul/lib/hook.js:163:16)
at /Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/node_modules/intern/node_modules/dojo/dojo.js:760:8
at fs.js:271:14
at Object.oncomplete (fs.js:107:15)
Warning: ReferenceError: window is not defined
at /Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/vendor/src/angular/angular.js:19288:3
at Function.vm.runInThisContext (/Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/node_modules/intern/node_modules/istanbul/lib/hook.js:163:16)
at /Users/evanvandegriff/Documents/work/nomi_v2/nomi_v2/web/node_modules/intern/node_modules/dojo/dojo.js:760:8
at fs.js:271:14
at Object.oncomplete (fs.js:107:15) Use --force to continue.
My app.js looks like:
angular.module( 'ngNomi', [
])
.config( function myAppConfig () {
})
.run( function run () {
})
.controller( 'AppCtrl', function AppCtrl ( $scope, $location ) {
});
Here is my 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.
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.41.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: '28', platform: [ 'OS X 10.9', 'Windows 7', 'Linux' ] },
{ browserName: 'chrome', version: '34', platform: [ 'OS X 10.9', '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,
// Name of the tunnel class to use for WebDriver tests
tunnel: 'SauceLabsTunnel',
// 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'
// },
// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
// can be used here
loader: {
packages: [
{ name: 'angular', location: 'vendor/src/angular/angular' },
{ name: 'angular-mocks', location: 'vendor/src/angular/angular-mocks' }
]
},
// Non-functional test suite(s) to run in each browser
suites: [ 'src/app.test.js' ],
// 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: /^node_modules/
});
Basically, how do I get the window to be defined in that file when running tests?
Source: (StackOverflow)
How can I simulate this feature? It seems like a conscious choice to have a WaitForDeletedById
but not the reverse.
Upon an ajax load, how can I wait for the existence of a new element on the page, rather than the absence of one?
Source: (StackOverflow)
I have a large project I'm writing intern tests against, I'm able to generate 90%+ coverage for my own package however coverage is being reported much less than this because other packages (such as dojo, dijit etc) are also being included in the report total.
Is there an 'out of the box' intern way to exclude files from coverage reports?
Istanbul supports an 'exclude-pattern', is it simply a case of writing another custom intern reporter to configure excludes?
Source: (StackOverflow)
I use Google Chrome with Intern to run automated tests and I would like to know if there is a way to launch Chrome in emulation mode from CLI or using a specific flag to test mobile rendering. If not, do you know a good workaround ?
I could directly use the Android Emulator (from Android SDK) with Selenium Webdriver apk or with mobile Chrome but tests are crashing most of the time, emulators don't respond and I have to restart it. Also, I need to test on the largest possible scope, not limited to Android devices.
Chrome on desktop is a lot more stable and even if a test fails, chrome always respond and can be closed automatically by Intern.
I tried a workaround with the "--enable-touch-events" flag and with a custom userAgent but it's producing weird behaviors. Maybe some other flags would help me ?
Thank you in advance for your answer.
Source: (StackOverflow)
I'm having an issue getting Intern 2 to wait for elements to be present. In Intern 1 I was using wait()
to set express time periods for the page to wait for an element to be present after some user action. With Intern 2 there seems to be setFindTimeout()
which should always tell a find()
method to wait a bit for the element to be present. I've set setFindTimeout()
and tried using pollUntil
to handle these waits but the tests are still failing with the error "element not visible".
Here is a sample test that is using the same requirements as my real tests and is looking for an element Id which appears 5 seconds after this page loads.
define([
'intern!object',
'intern/chai!assert',
'require',
'tests/util',
'intern/dojo/node!leadfoot/Command',
'intern/dojo/node!leadfoot/Session',
'intern/dojo/node!leadfoot/helpers/pollUntil'
], function (registerSuite, assert, require, util, Command, Session, pollUntil) {
registerSuite([
{
name: 'testing_find_by_wait',
test_create_form_on_web: function() {
console.log('Create a form with account, number, number and formula fields')
return this.remote
.setFindTimeout(10000)
.setWindowSize(1280, 960)
.get("http://www.kgstew.com/waittest.html")
.then(pollUntil('return document.getElementById("demo")', 10000))
.findById('demo')
.click()
.end()
}
}
]);
});
Source: (StackOverflow)
I am trying to test a Require.js project using Intern. I'm running into errors in my tests where jQuery is not defined when jQuery plugins are being loaded. My loader config looks like this:
loader: {
// Aliased paths
paths: {
'dt': 'dt',
'jq': 'jquery',
'jquery': 'jquery/jquery-1.8.3',
'jquerymx': 'jquery/jquerymx-3.2.custom',
'jquery.ui': 'jquery/jquery-ui-1.9.2.custom.min',
'jquery.ui.widget': 'jquery/jquery.ui.widget',
'jquery.jscrollpane': 'jquery/jquery.jscrollpane.min.edit',
'jquery.colorbox': 'jquery/jquery.colorbox-min',
'jquery.selectbox': 'jquery/jquery.selectbox-0.2.min.edit',
'jquery.base64': 'jquery/jquery.base64',
'jquery.cookie': 'jquery/jquery.cookie',
'jquery.urldecoder': 'jquery/jquery.urldecoder.min',
'jquery.fileupload': 'jquery/jquery.fileupload',
'jquery.history': 'history/scripts/compressed/history.adapter.jquery',
'openajax': 'openajax_2.0.7/OpenAjaxUnmanagedHub',
'zeroclipboard': 'zeroclipboard/ZeroClipboard'
},
// Plugin mappings
map: {
'*': {
'css': 'requirejs/require-css/css',
'text': 'requirejs/text'
}
},
// Shims for non-AMD libraries, mainly jQuery plugins
shim: {
'openajax': {
exports: 'OpenAjax'
},
'zeroclipboard': {
exports: 'ZeroClipboard'
},
'jquerymx': ['jquery'],
'jquery.ui': ['jquery'],
'jquery.ui.widget': ['jquery'],
'jquery.jscrollpane': ['jquery'],
'jquery.colorbox': ['jquery'],
'jquery.selectbox': ['jquery'],
'jquery.base64': ['jquery'],
'jquery.cookie': ['jquery'],
'jquery.urldecoder': ['jquery'],
'jquery.fileupload': ['jquery'],
'jquery.history': [
'jquery',
'history/scripts/compressed/history',
'history/scripts/compressed/history.html4'
]
}
}
I've checked to make sure jQuery and my other dependencies are actually being loaded, and they are, just not in the right order. Does the Dojo AMD loader that Intern use not handle the shim configuration?
Source: (StackOverflow)
I am trying to test Intern to see if it would be a good fit for a testing framework. I am trying to test the following code in Intern.
var HelloWorld;
HelloWorld = (function () {
function HelloWorld (name) {
this.name = name || "N/A";
}
HelloWorld.prototype.printHello = function() {
console.log('Hello, ' + this.name);
};
HelloWorld.prototype.changeName = function(name) {
if (name === null || name === undefined) {
throw new Error('Name is required');
}
this.name = name;
};
return HelloWorld;
})();
exports = module.exports = HelloWorld;
The file is located in 'js-test-projects/node/lib/HelloWorld.js' and Intern is located at 'js-test-projects/intern'. I am using the 1.0.0 branch of Intern. Whenever I try to include the file and run the test I don't get any output after "Defaulting to console reporter". Here is the test file.
define([
'intern!tdd',
'intern/chai!assert',
'dojo/node!../lib/HelloWorld'
], function (tdd, assert, HelloWorld) {
console.log(HelloWorld);
});
Source: (StackOverflow)
As per the title, I'm trying to test some AMD modules written in ES6 JS, running from nodejs.
I tried first with Intern: even after enabling --harmony
in nodejs, I ended up facing Intern's dependency chain, where I was not able to enable Harmony in e.g. Istanbul, esprima and others (I opened an issue for that).
I then moved onto mocha, and here I'm stuck ... strangely. I enabled Harmony both for nodejs and mocha itself, here's the package.json
test script:
"test": "node --harmony node_modules\\mocha\\bin\\mocha tests --harmony --recursive"
that I run from command prompt as npm test my_test_folder
. Still, some ES6 constructs (like const
) pass ok, but then it chokes on destructuring assignment. Here are the first output lines:
const { log, dir } = require('../consoleLogger.js');
^
SyntaxError: Unexpected token {
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
[...continues...]
I've also checked this SO thread and heard about transpilers, but I don't really know if they could work and I'm now trying to make transpilers work in this case.
Any idea on how to solve this, without resorting to change all ES6 bits spread in code? TA.
Source: (StackOverflow)
I'm trying to set a cookie for an intern functional test, but the cookie data doesn't seem to be available on the page. Here's the setup:
registerSuite(function() {
'test': function() {
return this.remote
.get(require.toUrl("index.html")
.setFindTimeout(5000)
.setCookie({name: "foo", value: "bar"})
.then(function() {
//... test here ...
});
}
});
When accessing document.cookie inside index.html, there is no data. Any tips on what I am doing wrong?
Update:
I haven't solved the problem, but figured out that you need call setCookie() before get(). The way I'm hacking around this is to call get() on a noop URL, and then calling setCookie()
return this.remote
.get('/')
.setCookie({name: "foo", value: "bar"})
.get(require.toUrl("index.html")
.setFindTimeout(5000)
.setCookie({name: "foo", value: "bar"})
.then(function() {
//... test here ...
});
Source: (StackOverflow)
Intern.js is a great testrunner but it only appears to work with SauceLabs. My company already uses BrowserStack and are very happy with it. I was wondering if anyone has been able to integrate Intern.js with BrowserStack and if so how?
Source: (StackOverflow)
Is it possible to create and run test suites for custom client-side
JavaScript, not created as Node modules? How should the
configuration be altered then?
There is loader section in the Intern configuration, specifying the
packages that will be loaded, if I get it right. Is it necessary to
include my custom JS code here somehow?
Where shall I put my test suites and how should they look like, when they are not belonging to any Node package, only to my custom JS code, again. In other words, how will I "load" and run them?
I have tried to get it work in some way, whereas I am not experienced with Node. My attempts resulted like this:
$ node client.js config=tests/js/intern
Defaulting to "console" reporter
Source: (StackOverflow)
The intern 2 documentation gives the following example of waiting for a condition to be true on a test page after loading it:
this.remote
.get(require.toUrl('./SomeTest.html'))
.then(pollUntil('return window.ready;', 5000));
Unfortunately, it doesn't explain how to load the pollUntil helper in order to use it in the previous example... Does anybody have a complete working example that uses pollUntil ?
Thanks for your help.
Source: (StackOverflow)