jasmine-browser-runner 2.1.0 → 2.2.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/lib/server.js +24 -9
- package/lib/types.js +23 -0
- package/package.json +1 -1
package/lib/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const defaultExpress = require('express'),
|
|
2
2
|
glob = require('glob'),
|
|
3
3
|
ejs = require('ejs'),
|
|
4
4
|
path = require('path'),
|
|
@@ -15,6 +15,7 @@ class Server {
|
|
|
15
15
|
*/
|
|
16
16
|
constructor(options) {
|
|
17
17
|
this.options = { ...options };
|
|
18
|
+
this.express = this.options.express || defaultExpress;
|
|
18
19
|
this.useHtmlReporter =
|
|
19
20
|
options.useHtmlReporter === undefined ? true : options.useHtmlReporter;
|
|
20
21
|
this.projectBaseDir = options.projectBaseDir || path.resolve();
|
|
@@ -133,26 +134,40 @@ class Server {
|
|
|
133
134
|
*/
|
|
134
135
|
start(serverOptions) {
|
|
135
136
|
serverOptions = serverOptions || {};
|
|
136
|
-
const app = express();
|
|
137
|
+
const app = this.express();
|
|
137
138
|
|
|
138
|
-
app.use('/__jasmine__', express.static(this.jasmineCore.files.path));
|
|
139
|
-
app.use('/__boot__', express.static(this.jasmineCore.files.bootDir));
|
|
140
|
-
app.use(
|
|
141
|
-
|
|
139
|
+
app.use('/__jasmine__', this.express.static(this.jasmineCore.files.path));
|
|
140
|
+
app.use('/__boot__', this.express.static(this.jasmineCore.files.bootDir));
|
|
141
|
+
app.use(
|
|
142
|
+
'/__images__',
|
|
143
|
+
this.express.static(this.jasmineCore.files.imagesDir)
|
|
144
|
+
);
|
|
145
|
+
app.use(
|
|
146
|
+
'/__support__',
|
|
147
|
+
this.express.static(path.join(__dirname, 'support'))
|
|
148
|
+
);
|
|
142
149
|
app.use(
|
|
143
150
|
'/__spec__',
|
|
144
|
-
express.static(path.join(this.projectBaseDir, this.options.specDir))
|
|
151
|
+
this.express.static(path.join(this.projectBaseDir, this.options.specDir))
|
|
145
152
|
);
|
|
146
153
|
app.use(
|
|
147
154
|
'/__src__',
|
|
148
|
-
express.static(path.join(this.projectBaseDir, this.options.srcDir))
|
|
155
|
+
this.express.static(path.join(this.projectBaseDir, this.options.srcDir))
|
|
149
156
|
);
|
|
150
157
|
|
|
158
|
+
if (this.options.middleware) {
|
|
159
|
+
for (const [path, middleware] of Object.entries(
|
|
160
|
+
this.options.middleware
|
|
161
|
+
)) {
|
|
162
|
+
app.use(path, middleware);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
151
166
|
if (this.options.importMap) {
|
|
152
167
|
const dir = this.options.importMap.moduleRootDir
|
|
153
168
|
? path.join(this.projectBaseDir, this.options.importMap.moduleRootDir)
|
|
154
169
|
: this.projectBaseDir;
|
|
155
|
-
app.use('/__moduleRoot__', express.static(dir));
|
|
170
|
+
app.use('/__moduleRoot__', this.express.static(dir));
|
|
156
171
|
}
|
|
157
172
|
|
|
158
173
|
const indexTemplate = ejs.compile(
|
package/lib/types.js
CHANGED
|
@@ -132,6 +132,29 @@
|
|
|
132
132
|
* @type boolean | undefined
|
|
133
133
|
* @default false
|
|
134
134
|
*/
|
|
135
|
+
/**
|
|
136
|
+
* <p>An optional map from paths to Express application middleware to mount on
|
|
137
|
+
* those paths. This can be used to serve static files, proxy requests to
|
|
138
|
+
* another server, etc.
|
|
139
|
+
* <p>Note: Requests made by jasmine-browser-runner (e.g. /, /__jasmine__/*,
|
|
140
|
+
* /__spec__/*, etc) are considered private APIs for semver purposes. If you
|
|
141
|
+
* configure middleware that modifies these requests and responses, there is a
|
|
142
|
+
* possibility that future jasmine-browser-runner releases, including minor and
|
|
143
|
+
* patch releases, may be incompatible with that middleware.
|
|
144
|
+
* @example
|
|
145
|
+
* // jasmine-browser.js
|
|
146
|
+
* const express = require('express');
|
|
147
|
+
*
|
|
148
|
+
* module.exports = {
|
|
149
|
+
* // ...
|
|
150
|
+
* middleware: {
|
|
151
|
+
* '/assets': express.static('./path/to/assets')
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* @name Configuration#middleware
|
|
155
|
+
* @type object | undefined
|
|
156
|
+
* @default undefined
|
|
157
|
+
*/
|
|
135
158
|
|
|
136
159
|
/**
|
|
137
160
|
* Describes a web browser.
|