Skip to content

Commit ca6b5bf

Browse files
committed
Convert to Intern 4.
1 parent d55826b commit ca6b5bf

19 files changed

+1033
-864
lines changed

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@
6868
"maxlen": 120,
6969
"indent": 4,
7070
"maxerr": 250,
71-
"predef": [ "require", "define", "module" ],
71+
"predef": [ "require", "define", "module", "intern", "requirejs" ],
7272
"maxcomplexity": 10
7373
}

Gruntfile.js

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = function (grunt) {
44
var filesList = [
55
"*.js",
66
"*.json",
7+
"!package-lock.json",
78
"i18n/*.js",
89
"tests/*.js"
910
];
@@ -41,19 +42,23 @@ module.exports = function (grunt) {
4142
}
4243
},
4344

44-
intern: {
45-
remote: {
45+
// Run Intern from grunt while still using the intern.json file.
46+
// There are many ways to do this, so I just picked one.
47+
// Note though that the grunt intern task does not automatically load intern.json.
48+
run: {
49+
"intern-local": {
50+
cmd: "npx",
51+
args: ["intern"],
4652
options: {
47-
runType: "runner",
48-
config: "tests/intern",
49-
reporters: ["runner"]
53+
failOnError: true
5054
}
5155
},
52-
local: {
56+
57+
"intern-remote": {
58+
cmd: "npx",
59+
args: ["intern", "config=@sauce"],
5360
options: {
54-
runType: "runner", // defaults to "client"
55-
config: "tests/intern.local",
56-
reporters: ["runner"]
61+
failOnError: true
5762
}
5863
}
5964
},
@@ -72,8 +77,7 @@ module.exports = function (grunt) {
7277
grunt.loadNpmTasks("grunt-contrib-jshint");
7378
grunt.loadNpmTasks("grunt-jsbeautifier");
7479
grunt.loadNpmTasks("grunt-lineending");
75-
grunt.loadNpmTasks("intern");
76-
80+
grunt.loadNpmTasks("grunt-run");
7781

7882
// By default, lint and run all tests.
7983
grunt.registerTask("default", ["jshint", "test:remote"]);
@@ -138,41 +142,20 @@ module.exports = function (grunt) {
138142
});
139143

140144
// Testing.
141-
// Always specify the target e.g. grunt test:remote, grunt test:remote
142-
// then add on any other flags afterwards e.g. console, lcovhtml.
145+
// Always specify the target e.g. grunt test:remote, grunt test:remote.
146+
// For more control, run testBuild:css and testBuild:jquery manually, then
147+
// directly call "npx intern".
143148
var testTaskDescription = "Run this task instead of the intern task directly! \n" +
144149
"Always specify the test target e.g. \n" +
145150
"grunt test:local\n" +
146-
"grunt test:remote\n\n" +
147-
"Add any optional reporters via a flag e.g. \n" +
148-
"grunt test:local:console\n" +
149-
"grunt test:local:lcovhtml\n" +
150-
"grunt test:local:console:lcovhtml";
151+
"grunt test:remote";
151152
grunt.registerTask("test", testTaskDescription, function (target) {
152-
function addReporter(reporter) {
153-
var property = "intern." + target + ".options.reporters",
154-
value = grunt.config.get(property);
155-
if (value.indexOf(reporter) !== -1) {
156-
return;
157-
}
158-
value.push(reporter);
159-
grunt.config.set(property, value);
160-
}
161-
162-
if (this.flags.lcovhtml) {
163-
addReporter("lcovhtml");
164-
}
165-
166-
if (this.flags.console) {
167-
addReporter("console");
168-
}
169-
170153
// First create the test builds. These are referenced from the intern tests.
171154
grunt.task.run("testBuild:css");
172155
grunt.task.run("testBuild:jquery");
173156

174157
// Then run the intern tests.
175-
grunt.task.run("intern:" + target);
158+
grunt.task.run("run:intern-" + target);
176159

177160
// Finally, delete the test builds so that they don't show up in "git status" as "untracked files".
178161
grunt.task.run("clean:testBuild");

intern-requirejs-loader.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// From https://stackoverflow.com/questions/54925478/how-do-i-configure-intern-4-to-use-requirejs/54927704#54927704
2+
/* globals Promise, requirejs */
3+
intern.registerLoader(function (options) {
4+
function initLoader(requirejs) {
5+
// Configure requireJS -- use options passed in through the intern.json
6+
// config, and add anything else.
7+
requirejs.config(options);
8+
9+
// This is the function Intern will actually call to load modules.
10+
return function (modules) {
11+
return new Promise(function (resolve, reject) {
12+
requirejs(modules, resolve, reject);
13+
});
14+
};
15+
}
16+
17+
if (typeof window !== "undefined") {
18+
return intern.loadScript("requirejs-dplugins/node_modules/requirejs/require.js").then(function () {
19+
return initLoader(requirejs);
20+
});
21+
} else {
22+
return initLoader(require("requirejs"));
23+
}
24+
});

intern.json

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
{
2+
"environments": [
3+
{
4+
"browserName": "chrome",
5+
"chromeOptions": {
6+
"args": ["headless", "disable-gpu"]
7+
},
8+
"fixSessionCapabilities": "no-detect"
9+
}
10+
],
11+
12+
"leaveRemoteOpen": false,
13+
14+
"basePath": "../",
15+
16+
"node": {
17+
"loader": {
18+
"script": "./intern-requirejs-loader.js",
19+
"options": {
20+
"baseUrl": "."
21+
}
22+
}
23+
},
24+
25+
"browser": {
26+
"loader": {
27+
"script": "requirejs-dplugins/intern-requirejs-loader.js",
28+
"options": {
29+
"baseUrl": "../../..",
30+
"packages": [
31+
{ "name": "intern", "location": "requirejs-dplugins/node_modules/intern" }
32+
]
33+
}
34+
}
35+
},
36+
37+
"suites": [
38+
"requirejs-dplugins/tests/unit/svg",
39+
"requirejs-dplugins/tests/unit/css",
40+
"requirejs-dplugins/tests/unit/has",
41+
"requirejs-dplugins/tests/unit/i18n",
42+
"requirejs-dplugins/tests/unit/Promise",
43+
"requirejs-dplugins/tests/unit/jquery"
44+
],
45+
46+
"functionalSuites": [
47+
"./tests/functional/cssBuild",
48+
"./tests/functional/jqueryBuild",
49+
"./tests/functional/jqueryScript"
50+
],
51+
52+
"coverage": [
53+
"**/*.js",
54+
"!nls/**",
55+
"!node_modules/**",
56+
"!samples/**",
57+
"!tests/**",
58+
"!intern*",
59+
"!Gruntfile.js"
60+
],
61+
62+
"tunnelOptions": {
63+
"drivers": [ "firefox", "internet explorer", "MicrosoftEdge" ]
64+
},
65+
66+
"WAIT_TIMEOUT": 30000,
67+
"POLL_INTERVAL": 500,
68+
69+
"defaultTimeout": 120000,
70+
"functionalTimeouts": {
71+
"connectTimeout": 60000,
72+
"executeAsync": 30000,
73+
"find": 10000,
74+
"pageLoad": 60000
75+
},
76+
77+
"configs": {
78+
"chrome-debug": {
79+
"description": "Run locally with Chrome visible and leave it open at end",
80+
"leaveRemoteOpen": true,
81+
"environments": [
82+
{ "browser": "chrome", "fixSessionCapabilities": false }
83+
]
84+
},
85+
86+
"firefox": {
87+
"description": "Run locally with Firefox",
88+
"environments": [
89+
{
90+
"browserName": "firefox",
91+
"fixSessionCapabilities": false,
92+
"moz:firefoxOptions": {
93+
"args": [
94+
"-headless", "--window-size=1024,768"
95+
]
96+
}
97+
}
98+
]
99+
},
100+
101+
"firefox-debug": {
102+
"description": "Run locally with Firefox visible and leave it open at end",
103+
"leaveRemoteOpen": true,
104+
"environments": [
105+
{ "browser": "firefox", "fixSessionCapabilities": false }
106+
]
107+
},
108+
109+
"safari": {
110+
"description": "Run locally with Safari visible and leave it open at end",
111+
"leaveRemoteOpen": true,
112+
"environments": [
113+
{ "browser": "safari", "fixSessionCapabilities": false }
114+
]
115+
},
116+
117+
"grid": {
118+
"description": "Run tests against selenium grid, must specify serverUrl and tunnelOptions.hostname",
119+
"tunnel": "null",
120+
"environments": [
121+
{ "browser": "chrome" }
122+
]
123+
},
124+
125+
"browserstack": {
126+
"description": "Run tests on BrowserStack.",
127+
"tunnel": "browserstack",
128+
"maxConcurrency": 2,
129+
"capabilities": {
130+
"idle-timeout": 60,
131+
"fixSessionCapabilities": "no-detect"
132+
},
133+
"environments": [
134+
{ "browser": "internet explorer", "version": ["11"] },
135+
{
136+
"browser": "firefox",
137+
"version": ["latest"],
138+
"platform": ["WINDOWS"]
139+
},
140+
{
141+
"browser": "chrome",
142+
"version": ["latest"],
143+
"platform": ["WINDOWS"]
144+
},
145+
{ "browser": "safari", "version": ["10"] }
146+
]
147+
},
148+
149+
"browserstack-ie": {
150+
"description": "Run tests on IE on BrowserStack.",
151+
"extends": ["browserstack"],
152+
"environments": [
153+
{ "browserName": "internet explorer", "version": "11", "name": "requirejs-dplugins"}
154+
]
155+
},
156+
157+
"sauce": {
158+
"description": "Run tests on SauceLabs",
159+
"environments": [
160+
{ "browserName": "MicrosoftEdge", "fixSessionCapabilities": false, "name": "requirejs-dplugins"},
161+
{ "browserName": "internet explorer", "version": "11", "fixSessionCapabilities": false,
162+
"name": "requirejs-dplugins"},
163+
{ "browserName": "firefox", "platform": [ "Windows 10" ], "fixSessionCapabilities": false,
164+
"name": "requirejs-dplugins" },
165+
{ "browserName": "chrome", "platform": [ "Windows 10" ], "fixSessionCapabilities": false,
166+
"name": "requirejs-dplugins" },
167+
{ "browserName": "safari", "fixSessionCapabilities": false, "name": "requirejs-dplugins" }
168+
],
169+
170+
"proxyPort": 9000,
171+
"maxConcurrency": 5,
172+
"coverage": false,
173+
"tunnel": "saucelabs"
174+
},
175+
176+
"sauce-chrome": {
177+
"description": "Run tests on Chrome/Windows 10 on SauceLabs",
178+
"environments": [
179+
{ "browserName": "chrome", "platform": [ "Windows 10" ], "fixSessionCapabilities": false,
180+
"name": "requirejs-dplugins" }
181+
],
182+
183+
"proxyPort": 9000,
184+
"maxConcurrency": 5,
185+
"coverage": false,
186+
"tunnel": "saucelabs"
187+
},
188+
189+
"sauce-firefox ": {
190+
"description": "Run tests on Firefox/Windows 10 on SauceLabs",
191+
"environments": [
192+
{ "browserName": "firefox", "platform": [ "Windows 10" ], "fixSessionCapabilities": false,
193+
"name": "requirejs-dplugins" }
194+
],
195+
196+
"proxyPort": 9000,
197+
"maxConcurrency": 5,
198+
"coverage": false,
199+
"tunnel": "saucelabs"
200+
},
201+
202+
"sauce-ie": {
203+
"description": "Run tests on IE on SauceLabs.",
204+
"extends": ["sauce"],
205+
"environments": [
206+
{ "browserName": "internet explorer", "version": "11", "fixSessionCapabilities": "no-detect",
207+
"name": "requirejs-dplugins" }
208+
],
209+
"coverage": null
210+
},
211+
212+
"sauce-safari": {
213+
"description": "Run tests on Safari (Mac) on SauceLabs",
214+
"environments": [
215+
{ "browserName": "safari", "fixSessionCapabilities": false, "name": "requirejs-dplugins" }
216+
],
217+
218+
"proxyPort": 9000,
219+
"maxConcurrency": 5,
220+
"coverage": false,
221+
"tunnel": "saucelabs"
222+
},
223+
224+
"sauce-ios": {
225+
"description": "Run tests on iOS on SauceLabs (currently hangs).",
226+
"extends": [
227+
"sauce"
228+
],
229+
"environments": [
230+
{ "browserName": "Safari", "platformName": "iOS", "platformVersion": "12.2",
231+
"deviceName": "iPad Simulator", "fixSessionCapabilities": "no-detect",
232+
"name": "requirejs-dplugins" }
233+
],
234+
"coverage": null
235+
},
236+
237+
"sauce-android": {
238+
"description": "Run tests on android on SauceLabs.",
239+
"extends": [
240+
"sauce"
241+
],
242+
"environments": [
243+
{ "browserName": "android", "platform": "Linux", "version": "6.0", "deviceName": "Android Emulator",
244+
"deviceType": "tablet", "fixSessionCapabilities": "no-detect", "name": "requirejs-dplugins" }
245+
],
246+
"coverage": null
247+
}
248+
249+
}
250+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"grunt-contrib-clean": "2.0.x",
88
"grunt-contrib-jshint": "2.1.x",
99
"grunt-jsbeautifier": "0.2.x",
10+
"grunt-run": "0.8.x",
1011
"requirejs": "2.1.x",
11-
"intern": "2.1.x",
12+
"intern": "4.4.x",
1213
"grunt-lineending": "1.0.x",
1314
"jsdom": "15.1.x"
1415
},

0 commit comments

Comments
 (0)