From cee494a8fe0e08671b125ad0bae65fd1aa17a60a Mon Sep 17 00:00:00 2001 From: Bill Keese Date: Thu, 18 Jul 2019 19:15:11 +0900 Subject: [PATCH] Upgrade to Intern 4. --- .gitignore | 3 +- .jshintrc | 2 +- .travis.yml | 3 +- Gruntfile.js | 54 +---- intern-requirejs-loader.js | 24 +++ intern.json | 236 ++++++++++++++++++++++ package.json | 5 +- tests/intern/TestUtils.js | 15 -- tests/intern/config.js | 43 ---- tests/intern/local.js | 35 ---- tests/intern/saucelab.js | 41 ---- tests/intern/unit/all.js | 5 - tests/intern/unit/tests-infra.js | 15 -- tests/{intern => }/unit/dpointer-utils.js | 15 +- 14 files changed, 276 insertions(+), 220 deletions(-) create mode 100644 intern-requirejs-loader.js create mode 100644 intern.json delete mode 100644 tests/intern/TestUtils.js delete mode 100644 tests/intern/config.js delete mode 100644 tests/intern/local.js delete mode 100644 tests/intern/saucelab.js delete mode 100644 tests/intern/unit/all.js delete mode 100644 tests/intern/unit/tests-infra.js rename tests/{intern => }/unit/dpointer-utils.js (88%) diff --git a/.gitignore b/.gitignore index b512c09..34977ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +.idea \ No newline at end of file diff --git a/.jshintrc b/.jshintrc index 6da9b62..2dde6d2 100644 --- a/.jshintrc +++ b/.jshintrc @@ -67,7 +67,7 @@ "maxlen": 120, "indent": 4, "maxerr": 250, - "predef": [ "require", "define" ], + "predef": [ "require", "define", "intern" ], "quotmark": "double", "maxcomplexity": 10 } \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index fd03c0f..b5e25a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,8 @@ install: - npm install - bower install script: -- grunt jshint test:remote +- grunt jshint +- npx intern config=@sauce env: global: # ibm-js diff --git a/Gruntfile.js b/Gruntfile.js index 14d522a..70706d3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,7 +2,7 @@ module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), - + jshint: { src: [ "**/*.js", "!{node_modules,dev}/**" @@ -10,64 +10,12 @@ module.exports = function (grunt) { options: { jshintrc: ".jshintrc" } - }, - - intern: { - // run tests on local desktop browser(s) - local: { - options: { - runType: "runner", - config: "tests/intern/local", - reporters: ["runner"] - } - }, - // run tests on remote cloud service - remote: { - options: { - runType: "runner", - config: "tests/intern/saucelab", - reporters: ["runner"] - } - } } }); // Load plugins - grunt.loadNpmTasks("intern"); grunt.loadNpmTasks("grunt-contrib-jshint"); // Aliases grunt.registerTask("default", ["jshint"]); - - // Testing. - // always specify the target e.g. grunt test:remote, grunt test:remote - // then add on any other flags afterwards e.g. console, lcovhtml - var testTaskDescription = "Run this task instead of the intern task directly! \n" + - "Always specify the test target e.g. \n" + - "grunt test:local\n" + - "grunt test:local.android\n" + - "grunt test:local.ios\n" + - "grunt test:remote\n\n" + - "Add any optional reporters via a flag e.g. \n" + - "grunt test:local:console\n" + - "grunt test:local:lcovhtml\n" + - "grunt test:local:console:lcovhtml"; - grunt.registerTask("test", testTaskDescription, function (target) { - function addReporter(reporter) { - var property = "intern." + target + ".options.reporters", - value = grunt.config.get(property); - if (value.indexOf(reporter) !== -1) { - return; - } - value.push(reporter); - grunt.config.set(property, value); - } - if (this.flags.lcovhtml) { - addReporter("lcovhtml"); - } - if (this.flags.console) { - addReporter("console"); - } - grunt.task.run("intern:" + target); - }); }; \ No newline at end of file diff --git a/intern-requirejs-loader.js b/intern-requirejs-loader.js new file mode 100644 index 0000000..dd860ad --- /dev/null +++ b/intern-requirejs-loader.js @@ -0,0 +1,24 @@ +// From https://stackoverflow.com/questions/54925478/how-do-i-configure-intern-4-to-use-requirejs/54927704#54927704 +/* globals Promise, requirejs */ +intern.registerLoader(function (options) { + function initLoader(requirejs) { + // Configure requireJS -- use options passed in through the intern.json + // config, and add anything else. + requirejs.config(options); + + // This is the function Intern will actually call to load modules. + return function (modules) { + return new Promise(function (resolve, reject) { + requirejs(modules, resolve, reject); + }); + }; + } + + if (typeof window !== "undefined") { + return intern.loadScript("decor/node_modules/requirejs/require.js").then(function () { + return initLoader(requirejs); + }); + } else { + return initLoader(require("requirejs")); + } +}); diff --git a/intern.json b/intern.json new file mode 100644 index 0000000..4ea8bc6 --- /dev/null +++ b/intern.json @@ -0,0 +1,236 @@ +{ + "environments": [ + { + "browserName": "chrome", + "chromeOptions": { + "args": ["headless", "disable-gpu"] + }, + "fixSessionCapabilities": "no-detect" + } + ], + + "leaveRemoteOpen": false, + + "basePath": "../", + + "node": { + "loader": { + "script": "./intern-requirejs-loader.js", + "options": { + "baseUrl": "." + } + } + }, + + "browser": { + "loader": { + "script": "dpointer/intern-requirejs-loader.js", + "options": { + "baseUrl": "../../..", + "packages": [ + { "name": "intern", "location": "dpointer/node_modules/intern" } + ] + } + } + }, + + "suites": [ + "dpointer/tests/unit/dpointer-utils" + ], + + "functionalSuites": [ + ], + + "coverage": [ + "**/*.js", + "!nls/**", + "!node_modules/**", + "!samples/**", + "!tests/**", + "!intern*", + "!Gruntfile.js" + ], + + "tunnelOptions": { + "drivers": [ "firefox", "internet explorer", "MicrosoftEdge" ] + }, + + "WAIT_TIMEOUT": 30000, + "POLL_INTERVAL": 500, + + "defaultTimeout": 120000, + "functionalTimeouts": { + "connectTimeout": 60000, + "executeAsync": 30000, + "find": 10000, + "pageLoad": 60000 + }, + + "configs": { + "chrome-debug": { + "description": "Run locally with Chrome visible and leave it open at end", + "leaveRemoteOpen": true, + "environments": [ + { "browser": "chrome", "fixSessionCapabilities": false } + ] + }, + + "firefox": { + "description": "Run locally with Firefox", + "environments": [ + { + "browserName": "firefox", + "fixSessionCapabilities": false, + "moz:firefoxOptions": { + "args": [ + "-headless", "--window-size=1024,768" + ] + } + } + ] + }, + + "firefox-debug": { + "description": "Run locally with Firefox visible and leave it open at end", + "leaveRemoteOpen": true, + "environments": [ + { "browser": "firefox", "fixSessionCapabilities": false } + ] + }, + + "safari": { + "description": "Run locally with Safari visible and leave it open at end", + "leaveRemoteOpen": true, + "environments": [ + { "browser": "safari", "fixSessionCapabilities": false } + ] + }, + + "grid": { + "description": "Run tests against selenium grid, must specify serverUrl and tunnelOptions.hostname on command line", + "tunnel": "null", + "environments": [ + { "browser": "chrome" } + ] + }, + + "browserstack": { + "description": "Run tests on BrowserStack.", + "tunnel": "browserstack", + "maxConcurrency": 2, + "capabilities": { + "idle-timeout": 60, + "fixSessionCapabilities": "no-detect" + }, + "environments": [ + { "browser": "internet explorer", "version": ["11"] }, + { + "browser": "firefox", + "version": ["latest"], + "platform": ["WINDOWS"] + }, + { + "browser": "chrome", + "version": ["latest"], + "platform": ["WINDOWS"] + }, + { "browser": "safari", "version": ["10"] } + ] + }, + + "browserstack-ie": { + "description": "Run tests on IE on BrowserStack.", + "extends": ["browserstack"], + "environments": [ + { "browserName": "internet explorer", "version": "11", "name": "dpointer"} + ] + }, + + "sauce": { + "description": "Run tests on SauceLabs", + "environments": [ + { "browserName": "MicrosoftEdge", "fixSessionCapabilities": false, "name": "dpointer"}, + { "browserName": "internet explorer", "version": "11", "fixSessionCapabilities": false, "name": "dpointer"}, + { "browserName": "firefox", "platform": [ "Windows 10" ], "fixSessionCapabilities": false, "name": "dpointer" }, + { "browserName": "chrome", "platform": [ "Windows 10" ], "fixSessionCapabilities": false, "name": "dpointer" }, + { "browserName": "safari", "fixSessionCapabilities": false, "name": "dpointer" } + ], + + "proxyPort": 9000, + "maxConcurrency": 5, + "coverage": false, + "tunnel": "saucelabs" + }, + + "sauce-chrome": { + "description": "Run tests on Chrome/Windows 10 on SauceLabs", + "environments": [ + { "browserName": "chrome", "platform": [ "Windows 10" ], "fixSessionCapabilities": false, "name": "dpointer" } + ], + + "proxyPort": 9000, + "maxConcurrency": 5, + "coverage": false, + "tunnel": "saucelabs" + }, + + "sauce-firefox ": { + "description": "Run tests on Firefox/Windows 10 on SauceLabs", + "environments": [ + { "browserName": "firefox", "platform": [ "Windows 10" ], "fixSessionCapabilities": false, "name": "dpointer" } + ], + + "proxyPort": 9000, + "maxConcurrency": 5, + "coverage": false, + "tunnel": "saucelabs" + }, + + "sauce-ie": { + "description": "Run tests on IE on SauceLabs.", + "extends": ["sauce"], + "environments": [ + { "browserName": "internet explorer", "version": "11", "fixSessionCapabilities": "no-detect", + "name": "dpointer" } + ], + "coverage": null + }, + + "sauce-safari": { + "description": "Run tests on Safari (Mac) on SauceLabs", + "environments": [ + { "browserName": "safari", "fixSessionCapabilities": false, "name": "dpointer" } + ], + + "proxyPort": 9000, + "maxConcurrency": 5, + "coverage": false, + "tunnel": "saucelabs" + }, + + "sauce-ios": { + "description": "Run tests on iOS on SauceLabs (currently hangs).", + "extends": [ + "sauce" + ], + "environments": [ + { "browserName": "Safari", "platformName": "iOS", "platformVersion": "12.2", "deviceName": "iPad Simulator", + "fixSessionCapabilities": "no-detect", "name": "dpointer" } + ], + "coverage": null + }, + + "sauce-android": { + "description": "Run tests on android on SauceLabs.", + "extends": [ + "sauce" + ], + "environments": [ + { "browserName": "android", "platform": "Linux", "version": "6.0", "deviceName": "Android Emulator", + "deviceType": "tablet", "fixSessionCapabilities": "no-detect", "name": "dpointer" } + ], + "coverage": null + } + + } +} diff --git a/package.json b/package.json index 923cdf7..8bfde96 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,10 @@ "name": "dpointer", "version": "0.5.2", "devDependencies": { - "intern": "1.6.x", + "intern": "4.4.x", "grunt": "~0.4.2", - "grunt-contrib-jshint": "~0.6.3" + "grunt-contrib-jshint": "~0.6.3", + "requirejs": "2.1.x" }, "licenses": [ { diff --git a/tests/intern/TestUtils.js b/tests/intern/TestUtils.js deleted file mode 100644 index 8ca56f6..0000000 --- a/tests/intern/TestUtils.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Utilities for unit tests - */ -define([], function () { - // avoid failure on IE9: console is not be defined when dev tools is not opened - if (!window.console) { - window.console = {}; - } - if (!window.console.log) { - window.console.log = function () { - }; - } - return this; - } -); \ No newline at end of file diff --git a/tests/intern/config.js b/tests/intern/config.js deleted file mode 100644 index 7385549..0000000 --- a/tests/intern/config.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * dpointer - configuration of Intern unit and functional tests - * - * Use this test page URL for direct unit-testing: - * http://[host:port/path]/dpointer/node_modules/intern/client.html?config=tests/intern/config - * (requires a local http server to access project files from the device browser) - * - * Local desktop browser - * --------------------- - * 1. Open the test page URL in your browser - * 2. Look at the browser console to see the output result - * - * iOS devices - * ----------- - * 1. Plug the iOS device to your Mac or use the iOS simulator - * 2. Ensure Web inspector is 'on' on iOS (Settings > Safari > Advanced > Web inspector) - * 3. Ensure Safari Develop menu is available on Mac (Preferences > Advanced > Show Develop Menu) - * 3. Open Safari on the Mac (Develop > [your devive] > Inspectable applications) - * 4. Go to the test page - * See the output result in Safari desktop console (Inspectable > Console) - * - * Android devices - * --------------- - * 1. Plug the Android device to you computer or use the Android emulator - * 2. Open the Android browser and go to the test page - * See the output result in logcat (command 'adb logcat') - */ -define({ - suites: [ "dpointer/tests/intern/unit/all" ], - - loader: { - baseUrl: typeof window !== "undefined" ? "../../.." : ".." - }, - - useLoader: { - "host-node": "requirejs", - "host-browser": "../../../requirejs/require.js" - }, - - reporters: ["console"], - - excludeInstrumentation: /^(requirejs.*|dpointer\/tests)/ -}); diff --git a/tests/intern/local.js b/tests/intern/local.js deleted file mode 100644 index 2794989..0000000 --- a/tests/intern/local.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Configuration to run Intern tests locally with selenium. - * - * Desktop browsers - * ---------------- - * 1. Uncomment the local browser environments you want to test against. - * 2. Ensure a selenium server is started (chrome driver is required to test against Chrome) - * java -jar selenium-server-standalone.jar -port 4444 -Dwebdriver.chrome.driver=chromedriver - * 3. Run grunt test:local from test project root directory - * - */ -define([ - "./config" -], function (config) { - - config.environments = [ - { browserName: "firefox" } -// { browserName: "chrome" }, -// { browserName: "safari" }, -// { browserName: "internet explorer" } - ]; - - config.useSauceConnect = false; - config.webdriver = { - hostname: "localhost", - port: 4444 - }; - - config.proxyPort = 9000; - config.proxyUrl = "http://127.0.0.1:9000"; - - config.maxConcurrency = 1; - - return config; -}); diff --git a/tests/intern/saucelab.js b/tests/intern/saucelab.js deleted file mode 100644 index 5030172..0000000 --- a/tests/intern/saucelab.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Configuration to run Intern (1.x) tests on SauceLab. - * - * 1. Set environment variables SAUCE_USERNAME and SAUCE_ACCESS_KEY - * 2. Run grunt test:remote - */ -define([ - "./config" -], function (config) { - - config.environments = [ - // desktop - {browserName: "internet explorer", version: "9", platform: "Windows 7"}, - {browserName: "internet explorer", version: "10", platform: "Windows 8"}, - {browserName: "internet explorer", version: "11", platform: "Windows 8.1"}, - {browserName: "firefox", version: "31", platform: "Windows 7"}, - {browserName: "chrome", version: "32", platform: "Windows 7"}, - {browserName: "chrome", version: "35", platform: "Windows 8.1"}, - {browserName: "safari", version: "7", platform: "OS X 10.9"}, - // mobile - {browserName: "Safari", platformVersion: "7.1", platformName: "iOS", deviceName: "iPhone Simulator", - "appium-version": "1.2.2"} - ]; - - // SauceLab - config.useSauceConnect = true; - config.webdriver = { - hostname: "localhost", - port: 4444 - }; - config.environments.forEach(function (env) { - env.name = "dpointer"; - }); - - config.proxyPort = 9000; - config.proxyUrl = "http://127.0.0.1:9000/"; - - config.maxConcurrency = 1; - - return config; -}); \ No newline at end of file diff --git a/tests/intern/unit/all.js b/tests/intern/unit/all.js deleted file mode 100644 index 40b0bec..0000000 --- a/tests/intern/unit/all.js +++ /dev/null @@ -1,5 +0,0 @@ -// dpointer unit tests -define([ - //"./tests-infra" - "./dpointer-utils" -]); diff --git a/tests/intern/unit/tests-infra.js b/tests/intern/unit/tests-infra.js deleted file mode 100644 index 3c2c19c..0000000 --- a/tests/intern/unit/tests-infra.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Simple unit test case to validate the test infrastructure - */ -define([ - "intern!object", - "../TestUtils" - ], function (registerSuite) { - registerSuite({ - name: "validation", - "test infra": function () { - console.log("--- Test infra ok ---"); - } - }); - } -); \ No newline at end of file diff --git a/tests/intern/unit/dpointer-utils.js b/tests/unit/dpointer-utils.js similarity index 88% rename from tests/intern/unit/dpointer-utils.js rename to tests/unit/dpointer-utils.js index 4e0732e..f4af636 100644 --- a/tests/intern/unit/dpointer-utils.js +++ b/tests/unit/dpointer-utils.js @@ -1,12 +1,11 @@ -define([ - "intern!object", - "intern/chai!assert", - "dpointer/handlers/utils", - "../TestUtils" -], function (registerSuite, assert, utils) { +define(function (require) { + "use strict"; - registerSuite({ - name: "SyntheticPointer", + var registerSuite = intern.getPlugin("interface.object").registerSuite; + var assert = intern.getPlugin("chai").assert; + var utils = require("dpointer/handlers/utils"); + + registerSuite("SyntheticPointer", { // create a synthetic pointer and check that properties are well defined and equal to expected values. "check properties": function () { if ("onpointerdown" in document) {