jasmine-browser-runner 1.3.0 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/lib/server.js +3 -25
- package/lib/support/loaders.js +65 -0
- package/lib/types.js +7 -0
- package/lib/webdriver.js +6 -19
- package/package.json +8 -7
- package/run.html.ejs +17 -7
- package/lib/support/loadEsModule.js +0 -20
package/README.md
CHANGED
|
@@ -75,6 +75,9 @@ config field to something that's high enough up to include both spec and source
|
|
|
75
75
|
files, and set `srcFiles` to `[]`. You can autogenerate such a configuration by
|
|
76
76
|
running `npx jasmine-browser-runner init --esm`.
|
|
77
77
|
|
|
78
|
+
If you have specs or helper files that use top-level await, set the
|
|
79
|
+
`enableTopLevelAwait` config property is set to `true`.
|
|
80
|
+
|
|
78
81
|
## Use with Rails
|
|
79
82
|
|
|
80
83
|
You can use jasmine-browser-runner to test your Rails application's JavaScript,
|
|
@@ -194,5 +197,24 @@ config.projectBaseDir = path.resolve('some/path');
|
|
|
194
197
|
jasmineBrowser.startServer(config, { port: 4321 });
|
|
195
198
|
```
|
|
196
199
|
|
|
200
|
+
## Supported environments
|
|
201
|
+
|
|
202
|
+
jasmine-browser-runner tests itself across popular browsers (Safari, Chrome,
|
|
203
|
+
Firefox, and Microsoft Edge) as well as Node.
|
|
204
|
+
|
|
205
|
+
| Environment | Supported versions |
|
|
206
|
+
|-------------------|------------------------|
|
|
207
|
+
| Node | 12.17+, 14, 16, 18, 20 |
|
|
208
|
+
| Safari | 15-16 |
|
|
209
|
+
| Chrome | Evergreen |
|
|
210
|
+
| Firefox | Evergreen, 102 |
|
|
211
|
+
| Edge | Evergreen |
|
|
212
|
+
|
|
213
|
+
For evergreen browsers, each version of jasmine-browser-runner is tested against
|
|
214
|
+
the version of the browser that is available to us at the time of release. Other
|
|
215
|
+
browsers, as well as older & newer versions of some supported browsers, are
|
|
216
|
+
likely to work. However, jasmine-browser-runner isn't tested against them and
|
|
217
|
+
they aren't actively supported.
|
|
197
218
|
|
|
219
|
+
To find out what environments work with a particular Jasmine release, see the [release notes](https://github.com/jasmine/jasmine/tree/main/release_notes).
|
|
198
220
|
|
package/lib/server.js
CHANGED
|
@@ -2,8 +2,7 @@ const express = require('express'),
|
|
|
2
2
|
glob = require('glob'),
|
|
3
3
|
ejs = require('ejs'),
|
|
4
4
|
path = require('path'),
|
|
5
|
-
fs = require('fs')
|
|
6
|
-
os = require('os');
|
|
5
|
+
fs = require('fs');
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* @class Server
|
|
@@ -30,28 +29,6 @@ class Server {
|
|
|
30
29
|
return unWindows(path.join('/__jasmine__', fileName));
|
|
31
30
|
})
|
|
32
31
|
.concat(this.bootFiles());
|
|
33
|
-
|
|
34
|
-
// Validate globs
|
|
35
|
-
const isWindows = (options.platform || os.platform)() === 'win32';
|
|
36
|
-
for (const globs of [
|
|
37
|
-
options.specFiles,
|
|
38
|
-
options.srcFiles,
|
|
39
|
-
options.helpers,
|
|
40
|
-
]) {
|
|
41
|
-
if (globs) {
|
|
42
|
-
for (const g of globs) {
|
|
43
|
-
if (isWindows && g.includes('\\')) {
|
|
44
|
-
const fixed = g.replace(/\\/g, '/');
|
|
45
|
-
console.warn(
|
|
46
|
-
'Backslashes in file paths behave inconsistently ' +
|
|
47
|
-
'between platforms and might not be treated as directory ' +
|
|
48
|
-
'separators in a future version. Consider changing ' +
|
|
49
|
-
`${g} to ${fixed}.`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
32
|
}
|
|
56
33
|
|
|
57
34
|
bootFiles() {
|
|
@@ -80,7 +57,7 @@ class Server {
|
|
|
80
57
|
}
|
|
81
58
|
|
|
82
59
|
getSupportFiles() {
|
|
83
|
-
|
|
60
|
+
const result = ['/__support__/loaders.js'];
|
|
84
61
|
if (!this.useHtmlReporter) {
|
|
85
62
|
result.push('/__support__/clearReporters.js');
|
|
86
63
|
}
|
|
@@ -152,6 +129,7 @@ class Server {
|
|
|
152
129
|
cssFiles: self.allCss(),
|
|
153
130
|
jasmineJsFiles: self.jasmineJs(),
|
|
154
131
|
userJsFiles: self.userJs(),
|
|
132
|
+
enableTopLevelAwait: self.options.enableTopLevelAwait || false,
|
|
155
133
|
})
|
|
156
134
|
);
|
|
157
135
|
} catch (error) {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* eslint-env browser, jasmine */
|
|
2
|
+
|
|
3
|
+
window._jasmine_loadEsModule = function(src) {
|
|
4
|
+
var script = document.createElement('script');
|
|
5
|
+
script.type = 'module';
|
|
6
|
+
|
|
7
|
+
// Safari reports syntax errors in ES modules as a script element error
|
|
8
|
+
// event rather than a global error event. Rethrow so that Jasmine can
|
|
9
|
+
// pick it up and fail the suite.
|
|
10
|
+
script.addEventListener('error', function(event) {
|
|
11
|
+
var msg =
|
|
12
|
+
'An error occurred while loading ' +
|
|
13
|
+
src +
|
|
14
|
+
'. Check the browser console for details.';
|
|
15
|
+
throw new Error(msg);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
script.src = src;
|
|
19
|
+
document.head.appendChild(script);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
window._jasmine_loadWithTopLevelAwaitSupport = async function(scriptUrls) {
|
|
23
|
+
const scriptsLoaded = (async function() {
|
|
24
|
+
// Load scripts sequentially to ensure that users can get a stable order
|
|
25
|
+
// by disabling randomization or setting a seed. This can be considerably
|
|
26
|
+
// slower than the normal way of doing things because the browser won't
|
|
27
|
+
// parallelize the HTTP requests. But it's the only way to ensure that the
|
|
28
|
+
// describes will execute in a consistent order in the presence of top-level
|
|
29
|
+
// await.
|
|
30
|
+
for (const url of scriptUrls) {
|
|
31
|
+
const isEsm = url.endsWith('.mjs');
|
|
32
|
+
|
|
33
|
+
if (isEsm) {
|
|
34
|
+
try {
|
|
35
|
+
await import(url);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
setTimeout(function() {
|
|
38
|
+
// Rethrow the error so jasmine-core's global error handler can pick it up.
|
|
39
|
+
throw e;
|
|
40
|
+
});
|
|
41
|
+
await new Promise(function(resolve) {
|
|
42
|
+
setTimeout(resolve);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
await new Promise(function(resolve) {
|
|
47
|
+
const script = document.createElement('script');
|
|
48
|
+
script.addEventListener('load', function() {
|
|
49
|
+
resolve();
|
|
50
|
+
});
|
|
51
|
+
script.addEventListener('error', function() {
|
|
52
|
+
resolve();
|
|
53
|
+
});
|
|
54
|
+
script.src = url;
|
|
55
|
+
document.head.appendChild(script);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
})();
|
|
60
|
+
|
|
61
|
+
const bootJasmine = window.onload;
|
|
62
|
+
window.onload = function() {
|
|
63
|
+
scriptsLoaded.then(bootJasmine);
|
|
64
|
+
};
|
|
65
|
+
};
|
package/lib/types.js
CHANGED
|
@@ -111,6 +111,13 @@
|
|
|
111
111
|
* @type boolean | undefined
|
|
112
112
|
* @default true
|
|
113
113
|
*/
|
|
114
|
+
/**
|
|
115
|
+
* Whether to enable support for top-level await. This option is off by default
|
|
116
|
+
* because it comes with a performance penalty.
|
|
117
|
+
* @name Configuration#enableTopLevelAwait
|
|
118
|
+
* @type boolean | undefined
|
|
119
|
+
* @default false
|
|
120
|
+
*/
|
|
114
121
|
|
|
115
122
|
/**
|
|
116
123
|
* Describes a web browser.
|
package/lib/webdriver.js
CHANGED
|
@@ -23,6 +23,7 @@ function buildWebdriver(browserInfo, webdriverBuilder) {
|
|
|
23
23
|
'--no-sandbox',
|
|
24
24
|
'window-size=1024,768',
|
|
25
25
|
'--disable-gpu',
|
|
26
|
+
'--disable-dev-shm-usage', // flag needed to avoid issues within docker https://stackoverflow.com/questions/56218242/headless-chromium-on-docker-fails
|
|
26
27
|
],
|
|
27
28
|
});
|
|
28
29
|
return webdriverBuilder
|
|
@@ -50,17 +51,11 @@ function buildWebdriver(browserInfo, webdriverBuilder) {
|
|
|
50
51
|
tags: sauce.tags,
|
|
51
52
|
};
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
capabilities[Capability.PLATFORM_NAME] = sauce.os;
|
|
59
|
-
capabilities[Capability.BROWSER_VERSION] = sauce.browserVersion;
|
|
60
|
-
capabilities['sauce:options'] = {
|
|
61
|
-
'tunnel-identifier': sauce.tunnelIdentifier,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
54
|
+
capabilities[Capability.PLATFORM_NAME] = sauce.os;
|
|
55
|
+
capabilities[Capability.BROWSER_VERSION] = sauce.browserVersion;
|
|
56
|
+
capabilities['sauce:options'] = {
|
|
57
|
+
'tunnel-identifier': sauce.tunnelIdentifier,
|
|
58
|
+
};
|
|
64
59
|
|
|
65
60
|
return webdriverBuilder
|
|
66
61
|
.withCapabilities(capabilities)
|
|
@@ -72,12 +67,4 @@ function buildWebdriver(browserInfo, webdriverBuilder) {
|
|
|
72
67
|
.build();
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
function sauceRequiresLegacyJWPProps(browserName, browserVersion) {
|
|
76
|
-
// Saucelabs supports W3C capability property names for most browsers,
|
|
77
|
-
// but requires legacy JWP property names for some older browsers.
|
|
78
|
-
// See <https://wiki.saucelabs.com/display/DOCS/W3C+Capabilities+Support>.
|
|
79
|
-
// Of the browsers that Jasmine supports, only Safari <12 need JWP names.
|
|
80
|
-
return browserName === 'safari' && parseInt(browserVersion, 10) < 12;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
70
|
module.exports = { buildWebdriver };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jasmine-browser-runner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"description": "Serve and run your Jasmine specs in a browser",
|
|
5
5
|
"bin": "bin/jasmine-browser-runner",
|
|
6
6
|
"exports": "./index.js",
|
|
@@ -39,17 +39,18 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"ejs": "^3.1.6",
|
|
41
41
|
"express": "^4.16.4",
|
|
42
|
-
"glob": "^
|
|
43
|
-
"selenium-webdriver": "
|
|
42
|
+
"glob": "^10.0.0",
|
|
43
|
+
"selenium-webdriver": "^4.8.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"jasmine-core": "^
|
|
46
|
+
"jasmine-core": "^5.0.0-beta.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"
|
|
49
|
+
"ejs-lint": "^2.0.0",
|
|
50
|
+
"eslint": "^8.38.0",
|
|
50
51
|
"eslint-plugin-jasmine": "^4.1.3",
|
|
51
|
-
"jasmine": "^
|
|
52
|
-
"jasmine-core": "^
|
|
52
|
+
"jasmine": "^5.0.0-beta.0",
|
|
53
|
+
"jasmine-core": "^5.0.0-beta.0",
|
|
53
54
|
"prettier": "^1.17.1",
|
|
54
55
|
"shelljs": "^0.8.3",
|
|
55
56
|
"temp": "^0.9.4"
|
package/run.html.ejs
CHANGED
|
@@ -13,13 +13,23 @@
|
|
|
13
13
|
<% jasmineJsFiles.forEach(function(jsFile) { %>
|
|
14
14
|
<script src="<%= jsFile %>" type="text/javascript"></script>
|
|
15
15
|
<% }) %>
|
|
16
|
-
<%
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
<% if (enableTopLevelAwait) { %>
|
|
17
|
+
<script type="module">
|
|
18
|
+
await _jasmine_loadWithTopLevelAwaitSupport([
|
|
19
|
+
<% userJsFiles.forEach(function(jsFile) { %>
|
|
20
|
+
'<%= jsFile %>',
|
|
21
|
+
<% }) %>
|
|
22
|
+
]);
|
|
23
|
+
</script>
|
|
24
|
+
<% } else { %>
|
|
25
|
+
<% userJsFiles.forEach(function(jsFile) { %>
|
|
26
|
+
<% if (jsFile.endsWith('.mjs')) { %>
|
|
27
|
+
<script type="module">_jasmine_loadEsModule('<%= jsFile %>')</script>
|
|
28
|
+
<% } else { %>
|
|
29
|
+
<script src="<%= jsFile %>" type="text/javascript"></script>
|
|
30
|
+
<% } %>
|
|
31
|
+
<% }) %>
|
|
32
|
+
<% } %>
|
|
23
33
|
|
|
24
34
|
<div id="jasmine_content"></div>
|
|
25
35
|
</body>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser, jasmine */
|
|
2
|
-
|
|
3
|
-
window._jasmine_loadEsModule = function(src) {
|
|
4
|
-
var script = document.createElement('script');
|
|
5
|
-
script.type = 'module';
|
|
6
|
-
|
|
7
|
-
// Safari reports syntax errors in ES modules as a script element error
|
|
8
|
-
// event rather than a global error event. Rethrow so that Jasmine can
|
|
9
|
-
// pick it up and fail the suite.
|
|
10
|
-
script.addEventListener('error', function(event) {
|
|
11
|
-
var msg =
|
|
12
|
-
'An error occurred while loading ' +
|
|
13
|
-
src +
|
|
14
|
-
'. Check the browser console for details.';
|
|
15
|
-
throw new Error(msg);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
script.src = src;
|
|
19
|
-
document.head.appendChild(script);
|
|
20
|
-
};
|