Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Intern tests to Intern 4 #1473

Merged
merged 11 commits into from
Jun 9, 2020
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
html-report
coverage
node_modules
28 changes: 27 additions & 1 deletion Editor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define([
'dojo/_base/array',
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/Deferred',
Expand All @@ -8,7 +9,7 @@ define([
'dojo/query',
'dojo/sniff',
'./Grid'
], function (declare, lang, Deferred, domConstruct, domClass, on, query, has, Grid) {
], function (arrayUtil, declare, lang, Deferred, domConstruct, domClass, on, query, has, Grid) {

return declare(null, {
editorFocusWrapperClassName: 'dgrid-editor-focus-wrapper',
Expand Down Expand Up @@ -68,6 +69,7 @@ define([
for (var id in this._editorInstances) {
var editorInstanceDomNode = this._getEditorRootNode(this._editorInstances[id].domNode);
if (editorInstanceDomNode && editorInstanceDomNode.parentNode) {
this._removeEditorBlurHandles();
// Remove any editor widgets from the DOM before List destroys it, to avoid issues in IE (#1100)
editorInstanceDomNode.parentNode.removeChild(editorInstanceDomNode);
}
Expand Down Expand Up @@ -374,6 +376,12 @@ define([
return (new Deferred()).resolve();
}

if (column._editorBlurHandle) {
// _StoreMixin#refreshCell will empty the cell, causing the blur handler to be triggered
// Remove the blur handler to avoid having it called unnecessarily (and throwing an error)
column._editorBlurHandle.remove();
}

return this.inherited(arguments);
},

Expand Down Expand Up @@ -938,6 +946,24 @@ define([
value = isNaN(asDate.getTime()) ? value : asDate;
}
return value;
},

_removeEditorBlurHandles: function () {
// summary:
// The blur handler created in _createSharedEditor will remove the editor node from the DOM.
// If other code needs to remove an editor node from the DOM it must first remove the editor's
// blur handle to avoid making a duplicate call to remove the node from the DOM which will
// throw an error.
arrayUtil.forEach(this.subRows, function (subRow) {
if (subRow instanceof Array) {
arrayUtil.forEach(subRow, function (column) {
column._editorBlurHandle && column._editorBlurHandle.remove();
});
}
else {
subRow._editorBlurHandle && subRow._editorBlurHandle.remove();
}
});
}
});
});
34 changes: 0 additions & 34 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('intern');

// grunt-contrib-stylus does not appear to support globbed destination filenames,
// so generate the desired destination/source configuration ahead of time
Expand Down Expand Up @@ -41,41 +40,8 @@ module.exports = function (grunt) {
files: [ 'css/**/*.styl' ],
tasks: [ 'stylus' ]
}
},

intern: {
options: {
reporters: [ 'LcovHtml', 'Pretty' ],
runType: 'runner',
config: 'test/intern/intern'
},

local: {
options: {
config: 'test/intern/intern-local'
}
},

browserstack: {},

saucelabs: {
options: {
config: 'test/intern/intern-saucelabs'
}
}
}
});

grunt.registerTask('default', [ 'stylus', 'watch:stylus' ]);
grunt.registerTask('test', function () {
var flags = Object.keys(this.flags);

if (!flags.length) {
flags.push('local');
}

flags.forEach(function (flag) {
grunt.task.run('intern:' + flag);
});
});
};
94 changes: 2 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages: [

dgrid works with Dojo 1.8.2 or higher, and supports the following browsers:

* IE 9+ (IE8 still unofficially supported, but no longer tested)
* IE 11 (IE8+ still unofficially supported, but no longer tested)
* Edge latest
* Firefox latest + ESR
* Chrome latest (desktop and mobile)
Expand Down Expand Up @@ -123,94 +123,4 @@ for dgrid, as well as Dojo and a number of other JavaScript libraries.

# Testing

dgrid uses [Intern](http://theintern.io/) as its test runner. Tests can
either be run using the browser, or using a cloud provider such as
[BrowserStack](https://www.browserstack.com/) or [Sauce Labs](https://saucelabs.com/).
More information on writing your own tests with Intern can be found in the
[Intern user guide](https://theintern.github.io/intern/).

*Note that installing dgrid via npm will not include the test folder; if you
wish to run dgrid's unit tests, download the package directly.*

## Setting up

**Note:** Commands listed in this section are all written assuming they are
run inside the `dgrid` directory.

Run `npm install` to install Intern:

```
npm install
```

## Running via the browser

1. Open a browser to http://hostname/path_to_dgrid/test/intern/runTests.html
2. View the console

## Running via BrowserStack or Sauce Labs

Make sure the proper credentials are set in the environment:

```
# for BrowserStack:
export BROWSERSTACK_USERNAME=<your_browserstack_username>
export BROWSERSTACK_ACCESS_KEY=<your_browserstack_access_key>

# for Sauce Labs:
export SAUCE_USERNAME=<your_sauce_username>
export SAUCE_ACCESS_KEY=<your_sauce_access_key>
```

Then kick off the runner with the following command:

```
# for BrowserStack:
grunt intern:browserstack

# for Sauce Labs:
grunt intern:saucelabs
```

## Running via local Selenium server

### Windows

Obtain the latest version of the Selenium server and the IE driver server from
[Selenium's Download page](http://docs.seleniumhq.org/download/). (The IE driver server needs to be
placed in a folder on your PATH.)

The Selenium server can be started by executing:

```
java -jar path\to\selenium-server-standalone-<version>.jar
```

### Mac OS X

The easiest way to obtain the Selenium standalone server for Mac OS X is by
using [Homebrew](http://brew.sh/). Once Homebrew is installed, run the following
commands:

```sh
brew update # ensure you have the latest formulae
brew install selenium-server-standalone
brew install chromedriver # for automating tests in Chrome
```

`selenium-server-standalone` installs a `selenium-server` script
which can be used to start up the server. For additional information
(e.g. how to start the server at login), see the output of
`brew info selenium-server-standalone`.

### Running the tests

Once the Selenium server is running, kick off the Intern test runner with the following command:

```
grunt test
```

This runs the `intern:local` Grunt task, which uses the configuration in `intern-local.js`.
This configuration overrides `intern.js` to use `NullTunnel`, and to test in Chrome by default
(this can be customized as desired according to the browsers you have installed).
See [test/README.md](test/README.md).
122 changes: 122 additions & 0 deletions intern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"$schema": "./node_modules/intern/schemas/config.json",
"name": "dgrid",

"basePath": "../",
"leaveRemoteOpen": "fail",

"configs": {
"browserstack": {
"comment": "BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY environment variables must be set",
"capabilities": {
"buildName": "dgrid 1.3.2-pre",
"projectName": "dgrid",
"resolution": "1366x768"
},
"environments": [
{
"browser": "chrome",
"version": [ "latest", "latest-3" ],
"platform": [ "WINDOWS", "MAC" ]
},
{
"browser": "firefox",
"version": [ "latest", "latest-3" ],
"platform": [ "WINDOWS", "MAC" ]
},
{
"browser": "safari",
"version": "latest"
},
{
"browser": "MicrosoftEdge",
"version": "latest"
},
{
"browser": "internet explorer",
"version": "11"
}
],
"tunnel": "browserstack",
"maxConcurrency": 4,
"leaveRemoteOpen": false
},

"chrome": {
"environments": "chrome"
},

"firefox": {
"environments": "firefox"
},

"safari": {
"environments": "safari"
},

"edge": {
"environments": "MicrosoftEdge"
},

"ie": {
"environments": "internet explorer"
}
},

"functionalSuites": [
"./test/intern/functional/*.js",
"!dgrid/test/intern/functional/util.js"
],

"browser": {
"suites": [
"dgrid/test/intern/browserSuites"
],

"loader": {
"script": "dojo",
"options": {
"internLoaderPath": "dojo/dojo.js",
"packages": [
{ "name": "dojo", "location": "dojo" },
{ "name": "dijit", "location": "dijit" },
{ "name": "dgrid", "location": "dgrid" },
{ "name": "dstore", "location": "dstore" }
]
}
}
},

"node": {
"reporters": [
"htmlcoverage",
"pretty"
]
},

"tunnel": "selenium",

"functionalTimeouts": {
"executeAsync": 10000,
"find": 10000,
"pageLoad": 10000
},

"coverage": [
"./extensions/*.js",
"./_StoreMixin.js",
"./CellSelection.js",
"./ColumnSet.js",
"./Editor.js",
"./Grid.js",
"./GridFromHtml.js",
"./GridWithColumnSetsFromHtml.js",
"./Keyboard.js",
"./List.js",
"./OnDemandGrid.js",
"./OnDemandList.js",
"./Selection.js",
"./Selector.js",
"./Tree.js"
]
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"grunt-contrib-clean": "~1.0.0",
"grunt-contrib-stylus": "~1.2.0",
"grunt-contrib-watch": "~1.1.0",
"intern": "~3.0.6",
"intern": "~4.8.7",
"nib": "~1.1.2"
},
"directories": {
Expand All @@ -23,7 +23,8 @@
"main": "./OnDemandGrid",
"icon": "http://packages.dojofoundation.org/images/dgrid.png",
"scripts": {
"test-server": "node ./test/data/rest-node.js"
"serve": "npx http-serve ../",
"serve-rest": "node ./test/data/rest-node.js"
},
"dojoBuild": "package.js"
}
8 changes: 8 additions & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../.jshintrc",
"globals": {
"exports": true,
"module": true,
"intern": true
}
}
Loading