Skip to content

Commit a4783e8

Browse files
authored
Update Intern tests to Intern 4 (#1473)
* Update unit tests to Intern 4 * ColumnSet: fix test on scaled displays * Editor: fix blur-related logic * Grunt: remove obsolete Intern tasks * README.md: replace testing info with link to test/README.md
1 parent 040768f commit a4783e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1928
-1824
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
html-report
1+
coverage
22
node_modules

Editor.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
define([
2+
'dojo/_base/array',
23
'dojo/_base/declare',
34
'dojo/_base/lang',
45
'dojo/Deferred',
@@ -8,7 +9,7 @@ define([
89
'dojo/query',
910
'dojo/sniff',
1011
'./Grid'
11-
], function (declare, lang, Deferred, domConstruct, domClass, on, query, has, Grid) {
12+
], function (arrayUtil, declare, lang, Deferred, domConstruct, domClass, on, query, has, Grid) {
1213

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

379+
if (column._editorBlurHandle) {
380+
// _StoreMixin#refreshCell will empty the cell, causing the blur handler to be triggered
381+
// Remove the blur handler to avoid having it called unnecessarily (and throwing an error)
382+
column._editorBlurHandle.remove();
383+
}
384+
377385
return this.inherited(arguments);
378386
},
379387

@@ -938,6 +946,24 @@ define([
938946
value = isNaN(asDate.getTime()) ? value : asDate;
939947
}
940948
return value;
949+
},
950+
951+
_removeEditorBlurHandles: function () {
952+
// summary:
953+
// The blur handler created in _createSharedEditor will remove the editor node from the DOM.
954+
// If other code needs to remove an editor node from the DOM it must first remove the editor's
955+
// blur handle to avoid making a duplicate call to remove the node from the DOM which will
956+
// throw an error.
957+
arrayUtil.forEach(this.subRows, function (subRow) {
958+
if (subRow instanceof Array) {
959+
arrayUtil.forEach(subRow, function (column) {
960+
column._editorBlurHandle && column._editorBlurHandle.remove();
961+
});
962+
}
963+
else {
964+
subRow._editorBlurHandle && subRow._editorBlurHandle.remove();
965+
}
966+
});
941967
}
942968
});
943969
});

Gruntfile.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = function (grunt) {
44
grunt.loadNpmTasks('grunt-contrib-clean');
55
grunt.loadNpmTasks('grunt-contrib-stylus');
66
grunt.loadNpmTasks('grunt-contrib-watch');
7-
grunt.loadNpmTasks('intern');
87

98
// grunt-contrib-stylus does not appear to support globbed destination filenames,
109
// so generate the desired destination/source configuration ahead of time
@@ -41,41 +40,8 @@ module.exports = function (grunt) {
4140
files: [ 'css/**/*.styl' ],
4241
tasks: [ 'stylus' ]
4342
}
44-
},
45-
46-
intern: {
47-
options: {
48-
reporters: [ 'LcovHtml', 'Pretty' ],
49-
runType: 'runner',
50-
config: 'test/intern/intern'
51-
},
52-
53-
local: {
54-
options: {
55-
config: 'test/intern/intern-local'
56-
}
57-
},
58-
59-
browserstack: {},
60-
61-
saucelabs: {
62-
options: {
63-
config: 'test/intern/intern-saucelabs'
64-
}
65-
}
6643
}
6744
});
6845

6946
grunt.registerTask('default', [ 'stylus', 'watch:stylus' ]);
70-
grunt.registerTask('test', function () {
71-
var flags = Object.keys(this.flags);
72-
73-
if (!flags.length) {
74-
flags.push('local');
75-
}
76-
77-
flags.forEach(function (flag) {
78-
grunt.task.run('intern:' + flag);
79-
});
80-
});
8147
};

README.md

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ packages: [
6868

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

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

124124
# Testing
125125

126-
dgrid uses [Intern](http://theintern.io/) as its test runner. Tests can
127-
either be run using the browser, or using a cloud provider such as
128-
[BrowserStack](https://www.browserstack.com/) or [Sauce Labs](https://saucelabs.com/).
129-
More information on writing your own tests with Intern can be found in the
130-
[Intern user guide](https://theintern.github.io/intern/).
131-
132-
*Note that installing dgrid via npm will not include the test folder; if you
133-
wish to run dgrid's unit tests, download the package directly.*
134-
135-
## Setting up
136-
137-
**Note:** Commands listed in this section are all written assuming they are
138-
run inside the `dgrid` directory.
139-
140-
Run `npm install` to install Intern:
141-
142-
```
143-
npm install
144-
```
145-
146-
## Running via the browser
147-
148-
1. Open a browser to http://hostname/path_to_dgrid/test/intern/runTests.html
149-
2. View the console
150-
151-
## Running via BrowserStack or Sauce Labs
152-
153-
Make sure the proper credentials are set in the environment:
154-
155-
```
156-
# for BrowserStack:
157-
export BROWSERSTACK_USERNAME=<your_browserstack_username>
158-
export BROWSERSTACK_ACCESS_KEY=<your_browserstack_access_key>
159-
160-
# for Sauce Labs:
161-
export SAUCE_USERNAME=<your_sauce_username>
162-
export SAUCE_ACCESS_KEY=<your_sauce_access_key>
163-
```
164-
165-
Then kick off the runner with the following command:
166-
167-
```
168-
# for BrowserStack:
169-
grunt intern:browserstack
170-
171-
# for Sauce Labs:
172-
grunt intern:saucelabs
173-
```
174-
175-
## Running via local Selenium server
176-
177-
### Windows
178-
179-
Obtain the latest version of the Selenium server and the IE driver server from
180-
[Selenium's Download page](http://docs.seleniumhq.org/download/). (The IE driver server needs to be
181-
placed in a folder on your PATH.)
182-
183-
The Selenium server can be started by executing:
184-
185-
```
186-
java -jar path\to\selenium-server-standalone-<version>.jar
187-
```
188-
189-
### Mac OS X
190-
191-
The easiest way to obtain the Selenium standalone server for Mac OS X is by
192-
using [Homebrew](http://brew.sh/). Once Homebrew is installed, run the following
193-
commands:
194-
195-
```sh
196-
brew update # ensure you have the latest formulae
197-
brew install selenium-server-standalone
198-
brew install chromedriver # for automating tests in Chrome
199-
```
200-
201-
`selenium-server-standalone` installs a `selenium-server` script
202-
which can be used to start up the server. For additional information
203-
(e.g. how to start the server at login), see the output of
204-
`brew info selenium-server-standalone`.
205-
206-
### Running the tests
207-
208-
Once the Selenium server is running, kick off the Intern test runner with the following command:
209-
210-
```
211-
grunt test
212-
```
213-
214-
This runs the `intern:local` Grunt task, which uses the configuration in `intern-local.js`.
215-
This configuration overrides `intern.js` to use `NullTunnel`, and to test in Chrome by default
216-
(this can be customized as desired according to the browsers you have installed).
126+
See [test/README.md](test/README.md).

intern.json

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"$schema": "./node_modules/intern/schemas/config.json",
3+
"name": "dgrid",
4+
5+
"basePath": "../",
6+
"leaveRemoteOpen": "fail",
7+
8+
"configs": {
9+
"browserstack": {
10+
"comment": "BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY environment variables must be set",
11+
"capabilities": {
12+
"buildName": "dgrid 1.3.2-pre",
13+
"projectName": "dgrid",
14+
"resolution": "1366x768"
15+
},
16+
"environments": [
17+
{
18+
"browser": "chrome",
19+
"version": [ "latest", "latest-3" ],
20+
"platform": [ "WINDOWS", "MAC" ]
21+
},
22+
{
23+
"browser": "firefox",
24+
"version": [ "latest", "latest-3" ],
25+
"platform": [ "WINDOWS", "MAC" ]
26+
},
27+
{
28+
"browser": "safari",
29+
"version": "latest"
30+
},
31+
{
32+
"browser": "MicrosoftEdge",
33+
"version": "latest"
34+
},
35+
{
36+
"browser": "internet explorer",
37+
"version": "11"
38+
}
39+
],
40+
"tunnel": "browserstack",
41+
"maxConcurrency": 4,
42+
"leaveRemoteOpen": false
43+
},
44+
45+
"chrome": {
46+
"environments": "chrome"
47+
},
48+
49+
"firefox": {
50+
"environments": "firefox"
51+
},
52+
53+
"safari": {
54+
"environments": "safari"
55+
},
56+
57+
"edge": {
58+
"environments": "MicrosoftEdge"
59+
},
60+
61+
"ie": {
62+
"environments": "internet explorer"
63+
}
64+
},
65+
66+
"functionalSuites": [
67+
"./test/intern/functional/*.js",
68+
"!dgrid/test/intern/functional/util.js"
69+
],
70+
71+
"browser": {
72+
"suites": [
73+
"dgrid/test/intern/browserSuites"
74+
],
75+
76+
"loader": {
77+
"script": "dojo",
78+
"options": {
79+
"internLoaderPath": "dojo/dojo.js",
80+
"packages": [
81+
{ "name": "dojo", "location": "dojo" },
82+
{ "name": "dijit", "location": "dijit" },
83+
{ "name": "dgrid", "location": "dgrid" },
84+
{ "name": "dstore", "location": "dstore" }
85+
]
86+
}
87+
}
88+
},
89+
90+
"node": {
91+
"reporters": [
92+
"htmlcoverage",
93+
"pretty"
94+
]
95+
},
96+
97+
"tunnel": "selenium",
98+
99+
"functionalTimeouts": {
100+
"executeAsync": 10000,
101+
"find": 10000,
102+
"pageLoad": 10000
103+
},
104+
105+
"coverage": [
106+
"./extensions/*.js",
107+
"./_StoreMixin.js",
108+
"./CellSelection.js",
109+
"./ColumnSet.js",
110+
"./Editor.js",
111+
"./Grid.js",
112+
"./GridFromHtml.js",
113+
"./GridWithColumnSetsFromHtml.js",
114+
"./Keyboard.js",
115+
"./List.js",
116+
"./OnDemandGrid.js",
117+
"./OnDemandList.js",
118+
"./Selection.js",
119+
"./Selector.js",
120+
"./Tree.js"
121+
]
122+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"grunt-contrib-clean": "~1.0.0",
1414
"grunt-contrib-stylus": "~1.2.0",
1515
"grunt-contrib-watch": "~1.1.0",
16-
"intern": "~3.0.6",
16+
"intern": "~4.8.7",
1717
"nib": "~1.1.2"
1818
},
1919
"directories": {
@@ -23,7 +23,8 @@
2323
"main": "./OnDemandGrid",
2424
"icon": "http://packages.dojofoundation.org/images/dgrid.png",
2525
"scripts": {
26-
"test-server": "node ./test/data/rest-node.js"
26+
"serve": "npx http-serve ../",
27+
"serve-rest": "node ./test/data/rest-node.js"
2728
},
2829
"dojoBuild": "package.js"
2930
}

test/.jshintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../.jshintrc",
3+
"globals": {
4+
"exports": true,
5+
"module": true,
6+
"intern": true
7+
}
8+
}

0 commit comments

Comments
 (0)