jasmine-browser-runner 2.0.0-beta.1 → 2.0.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 +15 -26
- package/lib/examples/default_esm_config.json +2 -0
- package/lib/server.js +11 -3
- package/lib/support/loaders.js +5 -2
- package/lib/types.js +6 -0
- package/package.json +4 -4
- package/run.html.ejs +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
[](https://circleci.com/gh/jasmine/jasmine-browser)
|
|
2
|
-
|
|
3
|
-
|
|
4
1
|
jasmine-browser-runner runs your Jasmine specs in a browser. It's suitable for
|
|
5
2
|
interactive use with normal browsers as well as running specs in CI builds
|
|
6
3
|
using either headless Chrome or Saucelabs.
|
|
@@ -9,44 +6,34 @@ using either headless Chrome or Saucelabs.
|
|
|
9
6
|
|
|
10
7
|
```bash
|
|
11
8
|
npm install --save-dev jasmine-browser-runner jasmine-core
|
|
9
|
+
npx jasmine-browser-runner init
|
|
12
10
|
```
|
|
13
11
|
|
|
14
12
|
or
|
|
15
13
|
|
|
16
14
|
```bash
|
|
17
15
|
yarn add -D jasmine-browser-runner jasmine-core
|
|
16
|
+
npx jasmine-browser-runner init
|
|
18
17
|
```
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
If you intend to use ES modules, add `--esm` to the `jasmine-browser-runner init`
|
|
20
|
+
command.
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"**/*.?(m)js"
|
|
27
|
-
],
|
|
28
|
-
"specDir": "spec",
|
|
29
|
-
"specFiles": [
|
|
30
|
-
"**/*[Ss]pec.?(m)js"
|
|
31
|
-
],
|
|
32
|
-
"helpers": [
|
|
33
|
-
"helpers/asyncAwait.js"
|
|
34
|
-
],
|
|
35
|
-
"env": {
|
|
36
|
-
"random": true
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
```
|
|
22
|
+
Then, customize `spec/support/jasmine-browser.json` to suit your needs. You can
|
|
23
|
+
change the spec files, helpers, and source files that are loaded, specify the
|
|
24
|
+
[Jasmine env's configuration](https://jasmine.github.io/api/edge/Configuration.html),
|
|
25
|
+
and more.
|
|
40
26
|
|
|
41
27
|
You can also use the `--config` option to specify a different file. This file can be a JSON file or a javascript file that exports a object that looks like the JSON above.
|
|
42
28
|
|
|
43
|
-
|
|
29
|
+
To start the server so that you can run the specs interactively (particularly
|
|
30
|
+
useful for debugging):
|
|
44
31
|
|
|
45
32
|
```
|
|
46
33
|
npx jasmine-browser-runner serve
|
|
47
34
|
```
|
|
48
35
|
|
|
49
|
-
|
|
36
|
+
To run the specs in a browser (defaults to Firefox):
|
|
50
37
|
|
|
51
38
|
```
|
|
52
39
|
npx jasmine-browser-runner runSpecs
|
|
@@ -70,7 +57,9 @@ Its value can be `"firefox"`, `"headlessFirefox"`, `"safari"`,
|
|
|
70
57
|
If a source, spec, or helper file's name ends in `.mjs`, it will be loaded as
|
|
71
58
|
an ES module rather than a regular script. Note that ES modules can only be
|
|
72
59
|
loaded from other ES modules. So if your source files are ES modules, your
|
|
73
|
-
spec files need to be ES modules too.
|
|
60
|
+
spec files need to be ES modules too. Want to use a different extension than
|
|
61
|
+
`.esm`? Just set the `esmFilenameExtension` config property, e.g.
|
|
62
|
+
`"esmFilenameExtension": ".js"`.
|
|
74
63
|
|
|
75
64
|
To allow spec files to import source files via relative paths, set the `specDir`
|
|
76
65
|
config field to something that's high enough up to include both spec and source
|
|
@@ -223,7 +212,7 @@ Firefox, and Microsoft Edge) as well as Node.
|
|
|
223
212
|
|
|
224
213
|
| Environment | Supported versions |
|
|
225
214
|
|-------------------|------------------------|
|
|
226
|
-
| Node |
|
|
215
|
+
| Node | 18, 20 |
|
|
227
216
|
| Safari | 15-16 |
|
|
228
217
|
| Chrome | Evergreen |
|
|
229
218
|
| Firefox | Evergreen, 102 |
|
package/lib/server.js
CHANGED
|
@@ -14,7 +14,7 @@ class Server {
|
|
|
14
14
|
* @param {ServerCtorOptions} options
|
|
15
15
|
*/
|
|
16
16
|
constructor(options) {
|
|
17
|
-
this.options = options;
|
|
17
|
+
this.options = { ...options };
|
|
18
18
|
this.useHtmlReporter =
|
|
19
19
|
options.useHtmlReporter === undefined ? true : options.useHtmlReporter;
|
|
20
20
|
this.projectBaseDir = options.projectBaseDir || path.resolve();
|
|
@@ -29,6 +29,13 @@ class Server {
|
|
|
29
29
|
return unWindows(path.join('/__jasmine__', fileName));
|
|
30
30
|
})
|
|
31
31
|
.concat(this.bootFiles());
|
|
32
|
+
|
|
33
|
+
if (!this.options.esmFilenameExtension) {
|
|
34
|
+
this.options.esmFilenameExtension = '.mjs';
|
|
35
|
+
} else if (this.options.esmFilenameExtension[0] !== '.') {
|
|
36
|
+
this.options.esmFilenameExtension =
|
|
37
|
+
'.' + this.options.esmFilenameExtension;
|
|
38
|
+
}
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
bootFiles() {
|
|
@@ -75,9 +82,9 @@ class Server {
|
|
|
75
82
|
this.options.srcDir,
|
|
76
83
|
this.options.srcFiles,
|
|
77
84
|
'/__src__'
|
|
78
|
-
).filter(
|
|
85
|
+
).filter(url => {
|
|
79
86
|
// Exclude ES modules. These will be loaded by other ES modules.
|
|
80
|
-
return !url.endsWith(
|
|
87
|
+
return !url.endsWith(this.options.esmFilenameExtension);
|
|
81
88
|
});
|
|
82
89
|
const helperUrls = this.getUrls(
|
|
83
90
|
this.options.specDir,
|
|
@@ -163,6 +170,7 @@ class Server {
|
|
|
163
170
|
cssFiles: self.allCss(),
|
|
164
171
|
jasmineJsFiles: self.jasmineJs(),
|
|
165
172
|
userJsFiles: self.userJs(),
|
|
173
|
+
esmFilenameExtension: self.options.esmFilenameExtension,
|
|
166
174
|
importMap: self.importMap(),
|
|
167
175
|
enableTopLevelAwait: self.options.enableTopLevelAwait || false,
|
|
168
176
|
})
|
package/lib/support/loaders.js
CHANGED
|
@@ -19,7 +19,10 @@ window._jasmine_loadEsModule = function(src) {
|
|
|
19
19
|
document.head.appendChild(script);
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
window._jasmine_loadWithTopLevelAwaitSupport = async function(
|
|
22
|
+
window._jasmine_loadWithTopLevelAwaitSupport = async function(
|
|
23
|
+
scriptUrls,
|
|
24
|
+
esmFilenameExtension
|
|
25
|
+
) {
|
|
23
26
|
const scriptsLoaded = (async function() {
|
|
24
27
|
// Load scripts sequentially to ensure that users can get a stable order
|
|
25
28
|
// by disabling randomization or setting a seed. This can be considerably
|
|
@@ -28,7 +31,7 @@ window._jasmine_loadWithTopLevelAwaitSupport = async function(scriptUrls) {
|
|
|
28
31
|
// describes will execute in a consistent order in the presence of top-level
|
|
29
32
|
// await.
|
|
30
33
|
for (const url of scriptUrls) {
|
|
31
|
-
const isEsm = url.endsWith(
|
|
34
|
+
const isEsm = url.endsWith(esmFilenameExtension);
|
|
32
35
|
|
|
33
36
|
if (isEsm) {
|
|
34
37
|
try {
|
package/lib/types.js
CHANGED
|
@@ -70,6 +70,12 @@
|
|
|
70
70
|
* @name ServerCtorOptions#srcFiles
|
|
71
71
|
* @type string[] | undefined
|
|
72
72
|
*/
|
|
73
|
+
/**
|
|
74
|
+
* The file extension used by ES modules
|
|
75
|
+
* @name ServerCtorOptions#esmFilenameExtension
|
|
76
|
+
* @type string | undefined
|
|
77
|
+
* @default ".mjs"
|
|
78
|
+
*/
|
|
73
79
|
|
|
74
80
|
/**
|
|
75
81
|
* Specifies the properties of the configuration file, as well as
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jasmine-browser-runner",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"selenium-webdriver": "^4.8.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"jasmine-core": "^5.0.0
|
|
46
|
+
"jasmine-core": "^5.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"ejs-lint": "^2.0.0",
|
|
50
50
|
"eslint": "^8.38.0",
|
|
51
51
|
"eslint-plugin-jasmine": "^4.1.3",
|
|
52
|
-
"jasmine": "^5.0.0
|
|
53
|
-
"jasmine-core": "^5.0.0
|
|
52
|
+
"jasmine": "^5.0.0",
|
|
53
|
+
"jasmine-core": "^5.0.0",
|
|
54
54
|
"prettier": "^1.17.1",
|
|
55
55
|
"shelljs": "^0.8.3",
|
|
56
56
|
"temp": "^0.9.4"
|
package/run.html.ejs
CHANGED
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
<% userJsFiles.forEach(function(jsFile) { %>
|
|
25
25
|
'<%= jsFile %>',
|
|
26
26
|
<% }) %>
|
|
27
|
-
]);
|
|
27
|
+
], '<%=esmFilenameExtension%>');
|
|
28
28
|
</script>
|
|
29
29
|
<% } else { %>
|
|
30
30
|
<% userJsFiles.forEach(function(jsFile) { %>
|
|
31
|
-
<% if (jsFile.endsWith(
|
|
31
|
+
<% if (jsFile.endsWith(esmFilenameExtension)) { %>
|
|
32
32
|
<script type="module">_jasmine_loadEsModule('<%= jsFile %>')</script>
|
|
33
33
|
<% } else { %>
|
|
34
34
|
<script src="<%= jsFile %>" type="text/javascript"></script>
|