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();
}
});
}
});
});
128 changes: 128 additions & 0 deletions intern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"$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",
"tunnelOptions": {
"port": "9515",
"pathname": "/"
}
},

"firefox": {
"environments": "firefox",
"tunnelOptions": {
"port": "4444",
"pathname": "/"
}
},

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

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

"ie": {
"environments": "internet explorer",
"tunnelOptions": {
"port": "5555",
"pathname": "/"
}
}
},

"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"
]
},

"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"
],

"tunnel": "null"
msssk marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion 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.5",
msssk marked this conversation as resolved.
Show resolved Hide resolved
"nib": "~1.1.2"
},
"directories": {
Expand Down
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
}
}
136 changes: 136 additions & 0 deletions test/intern/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# dgrid automated testing with Intern

dgrid's test suite is written and configured to run with [Intern](https://theintern.io/). Unit tests can be run both
directly in a web browser and using WebDriver. Functional tests will only run with WebDriver.

## Running dgrid tests

### Full test suite with WebDriver & BrowserStack

Requirements:

* Node.js and npm installed locally
* dgrid dependencies installed locally (`npm install`)
* Active BrowserStack account and `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` environment variables set

```bash
> npx intern config=@browserstack
```

This will run Intern with the `"browserstack"` config from `intern.json`. Intern will run a local HTTP server to
serve dgrid test files to BrowserStack via Intern's DigDug proxy tunnel. The code in functional test suites will
run in the local Node.js environment. The remote control commands in the tests are sent to the remote browser via
Intern's WebDriver library, Leadfoot.

Refer to the documentation on the [Intern website](https://theintern.io/) if you want to configure Intern to run with a
local [Selenium](https://www.selenium.dev/) installation.

## Developing and debugging dgrid tests

> Tip: Use `grep` to run specific tests

The easiest way to debug tests is by running them from a local HTTP server in a local web browser. Opening
`dgrid/test/intern/runTests.html` will redirect you to Intern's test runner. By default this will run all of dgrid's
unit tests. You can click on any suite or test in the Intern Test Report to re-run specific tests. Doing so will add the
`grep` parameter to the URL's query string. You can specify your own value for `grep` to run only tests whose suite
name or test name match the value. Refer to the Intern documentation to see other Intern configuration values that
can be set in the query string.

### Functional tests

[Selenium](https://www.selenium.dev/) or individual WebDriver servers can be run locally.

> Tip: Chrome is the easiest and most reliable driver to run locally

* Download the appropriate [ChromeDriver](https://chromedriver.chromium.org/downloads) for the version of Chrome you have
* Launch ChromeDriver:
* `> chromedriver`
* Note: `chromedriver --help` will display the CLI options
* Run Intern with the `chrome` config:
* `> npx intern config=@chrome`

### Individual WebDriver servers

dgrid's Intern configuration includes configs for several browsers that can be used either with Selenium or individual
WebDriver servers. The config name is passed to Intern's `config` parameter on the command line.

config name | browser | WebDriver server
-------------|---------|------------------
`chrome` | Google Chrome | [ChromeDriver](https://chromedriver.chromium.org/downloads)
`firefox` | Mozilla Firefox | [geckodriver](https://github.com/mozilla/geckodriver/releases)
`safari` | Safari | [Safari](https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari)
`edge` | Microsoft Edge | [Microsoft WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/)
`ie` | Internet Explorer | [InternetExplorerDriver](https://selenium-release.storage.googleapis.com/index.html) ([info](https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver))

### Leaving the test browser open

dgrid's Intern configuration will leave the test browser open only if one or more tests fail. You can change
`leaveRemoteOpen` on the command line:

```bash
> npx intern config=@chrome leaveRemoteOpen=true
```

The `pretty` reporter erases errors that are output to the console. You can use the `runner` reporter while debugging
failures:

```bash
> npx intern config=@chrome reporters=runner
```

### Loader errors

Loader errors, both from Dojo's AMD loader and from Node.js' `require` may produce confusing output that does not
facilitate debugging. If you encounter a loader error carefully inspect all your imports and ensure that they are
correct.

<details>
msssk marked this conversation as resolved.
Show resolved Hide resolved
<summary>Expand to see example console output resulting from a loader error</summary>

```bash
Listening on localhost:9000 (ws 9001)
Tunnel started
Error: timeout
at makeError (D:\dev\src\dojo\dojo\dojo.js:129:15)
at Timeout.<anonymous> (D:\dev\src\dojo\dojo\dojo.js:1687:20)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
src: 'dojoLoader',
info: {
'dgrid/test/intern/functional/Editor': 1,
'D:/dev/src/dojo//dgrid/test/intern/functional/Editor.js': { main: 'main', name: 'dgrid', location: 'dgrid' }
}
}
src: dojoLoader
info: {
'dgrid/test/intern/functional/Editor': 1,
'D:/dev/src/dojo//dgrid/test/intern/functional/Editor.js': { main: 'main', name: 'dgrid', location: 'dgrid' }
}
.
(ノಠ益ಠ)ノ彡┻━┻
Error: timeout
at makeError @ ..\dojo\dojo.js:129:15
at Timeout.<anonymous> @ ..\dojo\dojo.js:1687:20
at listOnTimeout @ internal\timers.js:549:17
at processTimers @ internal\timers.js:492:7
(ノಠ益ಠ)ノ彡┻━┻
Error: Dojo loader error: timeout
@ src\loaders\dojo.ts:37:17
@ ..\dojo\dojo.js:392:14
at forEach @ ..\dojo\dojo.js:116:6
at req.signal @ ..\dojo\dojo.js:391:4
at Timeout.<anonymous> @ ..\dojo\dojo.js:1687:6
at listOnTimeout @ internal\timers.js:549:17
at processTimers @ internal\timers.js:492:7
TOTAL: tested 0 platforms, 0 passed, 0 failed; fatal error occurred
```
</details>

## Code coverage

> Tip: Intern's browser runner does not generate code coverage
msssk marked this conversation as resolved.
Show resolved Hide resolved

When tests are run with `npx intern` then code coverage
information will be generated, regardless of whether the tests are run with a local or remote (BrowserStack) WebDriver
server. A summary of the coverage info is displayed in the console after the test run. Detailed coverage info is
written to the `dgrid/coverage` folder and can be viewed in a web browser by loading `dgrid/coverage/index.html`.
28 changes: 0 additions & 28 deletions test/intern/all.js

This file was deleted.

Loading