jasmine-browser-runner 0.9.0 → 0.10.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 CHANGED
@@ -8,13 +8,13 @@ using either headless Chrome or Saucelabs.
8
8
  # Getting started
9
9
 
10
10
  ```bash
11
- npm install --save-dev jasmine-browser-runner
11
+ npm install --save-dev jasmine-browser-runner jasmine-core
12
12
  ```
13
13
 
14
14
  or
15
15
 
16
16
  ```bash
17
- yarn add -D jasmine-browser-runner
17
+ yarn add -D jasmine-browser-runner jasmine-core
18
18
  ```
19
19
 
20
20
  Add a `spec/support/jasmine-browser.json`. For example:
@@ -73,6 +73,11 @@ modules. ES modules will silently fail to load in browsers that don't
73
73
  support them. Other kinds of load-time errors are detected and reported as suite
74
74
  errors.
75
75
 
76
+ To allow spec files to import source files via relative paths, set the `specDir`
77
+ config field to something that's high enough up to include both spec and source
78
+ files, and set `srcFiles` to `[]`. You can autogenerate such a configuration by
79
+ running `npx jasmine-browser-runner init --esm`.
80
+
76
81
  ## Use with Rails
77
82
 
78
83
  You can use jasmine-browser-runner to test your Rails application's JavaScript,
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  var path = require('path'),
4
- jasmineCore = require('jasmine-core'),
4
+ jasmineCore = require('../lib/jasmineCore'),
5
5
  Command = require('../lib/command'),
6
6
  jasmineBrowser = require('../index.js');
7
7
 
package/lib/command.js CHANGED
@@ -1,6 +1,11 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
- const { loadConfig, validateConfig, defaultConfig } = require('./config');
3
+ const {
4
+ loadConfig,
5
+ validateConfig,
6
+ defaultConfig,
7
+ defaultEsmConfig,
8
+ } = require('./config');
4
9
 
5
10
  const commonOptions = [
6
11
  { name: 'config', type: 'string', description: 'path to the config file' },
@@ -17,6 +22,14 @@ const subCommands = [
17
22
  {
18
23
  name: 'init',
19
24
  description: 'initialize a new Jasmine project',
25
+ options: [
26
+ {
27
+ name: 'esm',
28
+ type: 'bool',
29
+ description:
30
+ 'configure for use with ES modules (<script type="module">)',
31
+ },
32
+ ],
20
33
  },
21
34
  {
22
35
  name: 'serve',
@@ -133,7 +146,7 @@ class Command {
133
146
  this._logger.log('jasmine-core v' + this._config.jasmineCore.version());
134
147
  }
135
148
 
136
- init() {
149
+ init(options) {
137
150
  const dest = 'spec/support/jasmine-browser.json';
138
151
 
139
152
  if (fs.existsSync(dest)) {
@@ -142,7 +155,13 @@ class Command {
142
155
  }
143
156
 
144
157
  fs.mkdirSync(path.dirname(dest), { recursive: true });
145
- fs.writeFileSync(dest, defaultConfig());
158
+
159
+ if (options.esm) {
160
+ fs.writeFileSync(dest, defaultEsmConfig());
161
+ } else {
162
+ fs.writeFileSync(dest, defaultConfig());
163
+ }
164
+
146
165
  this._logger.log(`Wrote configuration to ${dest}.`);
147
166
  }
148
167
 
package/lib/config.js CHANGED
@@ -58,4 +58,18 @@ function defaultConfig() {
58
58
  });
59
59
  }
60
60
 
61
- module.exports = { loadConfig, validateConfig, defaultConfig };
61
+ function defaultEsmConfig() {
62
+ return fs.readFileSync(
63
+ require.resolve('./examples/default_esm_config.json'),
64
+ {
65
+ encoding: 'utf8',
66
+ }
67
+ );
68
+ }
69
+
70
+ module.exports = {
71
+ loadConfig,
72
+ validateConfig,
73
+ defaultConfig,
74
+ defaultEsmConfig,
75
+ };
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "srcDir": "src",
3
3
  "srcFiles": [
4
- "**/*.?(m)js"
4
+ "**/*.js"
5
5
  ],
6
6
  "specDir": "spec",
7
7
  "specFiles": [
8
- "**/*[sS]pec.?(m)js"
8
+ "**/*[sS]pec.js"
9
9
  ],
10
10
  "helpers": [
11
- "helpers/**/*.?(m)js"
11
+ "helpers/**/*.js"
12
12
  ],
13
13
  "env": {
14
14
  "stopSpecOnExpectationFailure": false,
@@ -0,0 +1,19 @@
1
+ {
2
+ "srcDir": "src",
3
+ "srcFiles": [],
4
+ "specDir": ".",
5
+ "specFiles": [
6
+ "spec/**/*[sS]pec.?(m)js"
7
+ ],
8
+ "helpers": [
9
+ "spec/helpers/**/*.?(m)js"
10
+ ],
11
+ "env": {
12
+ "stopSpecOnExpectationFailure": false,
13
+ "stopOnSpecFailure": false,
14
+ "random": true
15
+ },
16
+ "browser": {
17
+ "name": "firefox"
18
+ }
19
+ }
@@ -0,0 +1,11 @@
1
+ try {
2
+ module.exports = require('jasmine-core');
3
+ } catch (e) {
4
+ if (e.code === 'MODULE_NOT_FOUND') {
5
+ throw new Error(
6
+ "Could not load jasmine-core. Please make sure that it's installed."
7
+ );
8
+ } else {
9
+ throw e;
10
+ }
11
+ }
package/lib/server.js CHANGED
@@ -20,7 +20,7 @@ class Server {
20
20
  this.batchReporter = options.batchReporter || false;
21
21
  this.jsonDomReporter = options.jsonDomReporter || false;
22
22
  this.projectBaseDir = options.projectBaseDir || path.resolve();
23
- this.jasmineCore = options.jasmineCore || require('jasmine-core');
23
+ this.jasmineCore = options.jasmineCore || require('./jasmineCore');
24
24
  this.jasmineCssFiles = this.jasmineCore.files.cssFiles.map(function(
25
25
  fileName
26
26
  ) {
@@ -53,7 +53,7 @@ class Server {
53
53
  getUrls(baseDir, globs, urlRoot) {
54
54
  return findFiles(path.join(this.projectBaseDir, baseDir), globs || []).map(
55
55
  function(p) {
56
- return unWindows(path.join(urlRoot, p));
56
+ return isUrl(p) ? p : unWindows(path.join(urlRoot, p));
57
57
  }
58
58
  );
59
59
  }
@@ -221,6 +221,10 @@ function findPort(serverPort, optionsPort) {
221
221
  return 8888;
222
222
  }
223
223
 
224
+ function isUrl(s) {
225
+ return s.startsWith('http://') || s.startsWith('https://');
226
+ }
227
+
224
228
  function findFiles(baseDir, globs) {
225
229
  const { includeGlobs, excludeGlobs } = globs.reduce(
226
230
  function(ongoing, g) {
@@ -241,12 +245,16 @@ function findFiles(baseDir, globs) {
241
245
  const result = [];
242
246
 
243
247
  for (const g of includeGlobs) {
244
- const files = glob.sync(g, { ignore: excludeGlobs, cwd: baseDir });
248
+ if (isUrl(g)) {
249
+ result.push(g);
250
+ } else {
251
+ const files = glob.sync(g, { ignore: excludeGlobs, cwd: baseDir });
245
252
 
246
- for (const f of files) {
247
- // De-duplicate
248
- if (result.indexOf(f) === -1) {
249
- result.push(f);
253
+ for (const f of files) {
254
+ // De-duplicate
255
+ if (result.indexOf(f) === -1) {
256
+ result.push(f);
257
+ }
250
258
  }
251
259
  }
252
260
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jasmine-browser-runner",
3
- "version": "0.9.0",
3
+ "version": "0.10.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",
@@ -13,7 +13,8 @@
13
13
  "run.html.ejs",
14
14
  "bin/*.js",
15
15
  "lib/**/*.js",
16
- "lib/examples/default_config.json"
16
+ "lib/examples/default_config.json",
17
+ "lib/examples/default_esm_config.json"
17
18
  ],
18
19
  "scripts": {
19
20
  "posttest": "eslint bin/* lib spec scripts index.js --ignore-path=.styleIgnore && prettier --check --ignore-path=.styleIgnore lib/*.js lib/**/*.js spec/**/*.js scripts/*.js index.js",
@@ -40,17 +41,17 @@
40
41
  },
41
42
  "homepage": "https://github.com/jasmine/jasmine-browser-runner#readme",
42
43
  "dependencies": {
43
- "ejs": "^2.6.1",
44
+ "ejs": "^3.1.6",
44
45
  "express": "^4.16.4",
45
46
  "glob": "^7.1.7",
46
- "selenium-webdriver": "^4.0.0-beta.4"
47
+ "selenium-webdriver": "^4.1.0"
47
48
  },
48
49
  "peerDependencies": {
49
50
  "jasmine-core": "^3.9.0"
50
51
  },
51
52
  "devDependencies": {
52
- "eslint": "^6.8.0",
53
- "eslint-plugin-jasmine": "^2.10.1",
53
+ "eslint": "^8.3.0",
54
+ "eslint-plugin-jasmine": "^4.1.3",
54
55
  "jasmine": "^3.9.0",
55
56
  "jasmine-core": "^3.9.0",
56
57
  "prettier": "^1.17.1",
package/run.html.ejs CHANGED
@@ -8,6 +8,8 @@
8
8
  <% cssFiles.forEach(function(cssFile) { %>
9
9
  <link rel="stylesheet" href="<%= cssFile %>" type="text/css" media="screen"/>
10
10
  <% }) %>
11
+ </head>
12
+ <body>
11
13
  <% jasmineJsFiles.forEach(function(jsFile) { %>
12
14
  <script src="<%= jsFile %>" type="text/javascript"></script>
13
15
  <% }) %>
@@ -19,8 +21,6 @@
19
21
  <% } %>
20
22
  <% }) %>
21
23
 
22
- </head>
23
- <body>
24
24
  <div id="jasmine_content"></div>
25
25
  </body>
26
26
  </html>