GithubHelp home page GithubHelp logo

jasmine-browser-runner's Introduction

jasmine-browser-runner runs your Jasmine specs in a browser. It's suitable for interactive use with normal browsers as well as running specs in CI builds using either headless browsers or with a remote Selenuium grid provider such as Saucelabs.

Getting started

npm install --save-dev jasmine-browser-runner jasmine-core
npx jasmine-browser-runner init

or

yarn add -D jasmine-browser-runner jasmine-core
npx jasmine-browser-runner init

If you intend to use ES modules, add --esm to the jasmine-browser-runner init command.

Then, customize spec/support/jasmine-browser.mjs to suit your needs. You can change the spec files, helpers, and source files that are loaded, specify the Jasmine env's configuration, and more.

In addition to spec/support/jasmine-browser.mjs, jasmine-browser-runner also supports other config file paths:

  • spec/support/jasmine-browser.js
  • spec/support/jasmine-browser.json (generated by previous versions of the init subcommand)
  • Any other JavaScript or JSON file, if you use the --config option. This file can be a JSON file or a javascript file whose default export is a config object.

More information about the configuration can be found at the runner documentation website.

To start the server so that you can run the specs interactively (particularly useful for debugging):

npx jasmine-browser-runner serve

To run the specs in a browser (defaults to Firefox):

npx jasmine-browser-runner runSpecs

To use a browser other than Firefox, add a browser field to jasmine-browser.mjs:

export default {
  // ...
  "browser": "chrome"
}

Its value can be "firefox", "headlessFirefox", "safari", "MicrosoftEdge", "chrome", or "headlessChrome".

TLS support

To serve tests over HTTPS instead of HTTP, supply a path to a TLS cert and key in PEM format in jasmine-browser.mjs:

export default {
  // ...
  "tlsKey": "/path/to/tlsKey.pem",
  "tlsCert": "/path/to/tlsCert.pem",
  // ...
}

These can also be specified on the command line with --tlsKey and --tlsCert.

Note that if you are using a self-signed or otherwise invalid certificate, the browser will not allow the connection by default. Additional browser configs or command line options may be necessary to use an invalid TLS certificate.

Controlling which network interfaces are listened to

By default, jasmine-browser-runner listens to all available network interfaces. You might need that if you're using a remote grid such as Saucelabs. If you don't need that, you can improve security by listening only to localhost.

export default {
  // ...
  "listenAddress": "localhost",
  // ...
}

Hostname support

If you need to access your tests via a specific hostname, you can do that by setting the hostname configuration property:

export default {
  // ...
  "hostname": "mymachine.mynetwork",
  // ...
}

This can also be specified on the command line with --hostname.

Setting hostname but not listenAddress has the same effect as setting listenAddress to the same value as hostname. If you need to set a hostname but retain the default behavior of listening to all network interfaces, you can do that by setting listenAddress to "*".

There are a few important caveats when doing this:

  1. This name must either be an IP or a name that can really be resolved on your system. Otherwise, you will get ENOTFOUND errors.
  2. This name must correspond to an IP assigned to one of the network interfaces on your system. Otherwise, you will get EADDRNOTAVAIL errors.
  3. If this name matches the HSTS preload list, browsers will force the connection to HTTPS. If you are not using TLS, you will get an error that says The browser tried to speak HTTPS to an HTTP server. Misconfiguration is likely. You may be surprised by the names on that preload list, which include such favorite local network hostnames as:

ES module support

If a source, spec, or helper file's name ends in .mjs, it will be loaded as an ES module rather than a regular script. Note that ES modules can only be loaded from other ES modules. So if your source files are ES modules, your spec files need to be ES modules too. Want to use a different extension than .esm? Just set the esmFilenameExtension config property, e.g. "esmFilenameExtension": ".js".

To allow spec files to import source files via relative paths, set the specDir config field to something that's high enough up to include both spec and source files, and set srcFiles to []. You can autogenerate such a configuration by running npx jasmine-browser-runner init --esm.

If you have specs or helper files that use top-level await, set the enableTopLevelAwait config property is set to true.

Import maps are also supported:

export default {
   // ...
   "importMap": {
     "moduleRootDir": "node_modules", 
     "imports": {
       "some-lib":"some-lib/dist/index.mjs",
       "some-lib/": "some-lib/dist/",
       "some-cdn-lib": "https://example.com/some-cdn-lib"
      }
   }
}

Use with Rails

You can use jasmine-browser-runner to test your Rails application's JavaScript, whether you use the Asset Pipeline or Webpacker.

Webpacker

  1. Run yarn add --dev jasmine-browser-runner jasmine-core.
  2. Run npx jasmine-browser-runner init.
  3. Edit spec/support/jasmine-browser.mjs as follows:
export default {
  "srcDir": ".",
  "srcFiles": [],
  "specDir": "public/packs/js",
  "specFiles": [
    "specs-*.js"
  ],
  "helpers": [],
  // ...
}
  1. Create app/javascript/packs/specs.js (or app/javascript/packs/specs.jsx if you use JSX) as follows:
(function() {
  'use strict';

  function requireAll(context) {
    context.keys().forEach(context);
  }

  requireAll(require.context('spec/javascript/helpers/', true, /\.js/));
  requireAll(require.context('spec/javascript/', true, /[sS]pec\.js/));
})();
  1. Add 'spec/javascript' to the additional_paths array in config/webpacker.yml.
  2. Put your spec files in spec/javascript.

To run the specs:

  1. Run bin/webpack --watch.
  2. Run npx jasmine-browser-runner.
  3. visit http://localhost:8888.

Asset Pipeline

  1. Run yarn init if there isn't already package.json file in the root of the Rails application.
  2. Run yarn add --dev jasmine-browser-runner.
  3. Run npx jasmine-browser-runner init.
  4. Edit spec/support/jasmine-browser.mjs as follows:
export default {
  "srcDir": "public/assets",
  "srcFiles": [
    "application-*.js"
  ],
  "specDir": "spec/javascript",
  "specFiles": [
    "**/*[sS]pec.?(m)js"
  ],
  "helpers": [
    "helpers/**/*.?(m)js"
  ],
  // ...
}
  1. Put your spec files in spec/javascript.

To run the specs:

  1. Either run bundle exec rake assets:precompile or start the Rails application in an environment that's configured to precompile assets.
  2. Run npx jasmine-browser-runner.
  3. Visit http://localhost:8888.

Remote Grid support (Saucelabs, BrowserStack, etc.)

jasmine-browser-runner can run your Jasmine specs on a remote grid provider like Saucelabs, BrowserStack or your own Selenium Grid. To use a remote grid hub, set the browser object in your config file as follows:

// jasmine-browser.mjs
export default {
  // ...
  // BrowserStack
  "browser": {
    "name": "safari",
    "useRemoteSeleniumGrid": true,
    "remoteSeleniumGrid": {
      "url": "https://hub-cloud.browserstack.com/wd/hub",
      "bstack:options": {
        "browserVersion": "16",
        "os": "OS X",
        "osVersion": "Monterey",
        "local": "true",
        "localIdentifier": "tunnel ID",
        "debug": "true",
        "userName": "your BrowserStack username",
        "accessKey": "your BrowserStack access key"
      }
    }
  }
}
// jasmine-browser.mjs
export default {
  // ...
  // Saucelabs
  "browser": {
    "name": "safari",
    "useRemoteSeleniumGrid": true,
    "remoteSeleniumGrid": {
      "url": "https://ondemand.saucelabs.com/wd/hub",
      "platformName": "macOS 12",
      "sauce:options": {
        "tunnel-identifier": "tunnel ID",
        "userName": "your Saucelabs username",
        "accessKey": "your Saucelabs access key"
      }
    }
  }
}

When using a remote grid provider, all properties of the browser object are optional except for name which will be passed as the browserName capability, and useRemoteSeleniumGrid which must be set to a value of true. if a remoteSeleniumGrid object is included, any values it contains, with the exception of the url will be used as capabilties sent to the grid hub url. if no value is specified for the url then a default of http://localhost:4445/wd/hub is used.

It's common for remote grids to support only a limited set of ports. Check your remote grid's documentation to make sure that the port you're using is supported. When using a remote grid, jasmine-browser-runner will run on port 5555 unless you use the --port command line option or specify a port in the second parameter tostartServer.

Want more control?

// ESM
import path from 'path';
import jasmineBrowser from 'jasmine-browser-runner';
import config from './spec/support/jasmine-browser.mjs';

config.projectBaseDir = path.resolve('some/path');
jasmineBrowser.startServer(config, { port: 4321 });


// CommonJS
const path = require('path');
const jasmineBrowser = require('jasmine-browser-runner');

import('./spec/support/jasmine-browser.mjs')
  .then(function({default: config}) {
    config.projectBaseDir = path.resolve('some/path');
    jasmineBrowser.startServer(config, { port: 4321 });
  });

Supported environments

jasmine-browser-runner tests itself across popular browsers (Safari, Chrome, Firefox, and Microsoft Edge) as well as Node.

Environment Supported versions
Node 18, 20, 22
Safari 15-17
Chrome Evergreen
Firefox Evergreen, 102, 115
Edge Evergreen

For evergreen browsers, each version of jasmine-browser-runner is tested against the version of the browser that is available to us at the time of release. Other browsers, as well as older & newer versions of some supported browsers, are likely to work. However, jasmine-browser-runner isn't tested against them and they aren't actively supported.

To find out what environments work with a particular Jasmine release, see the release notes.

Copyright (c) 2019 Pivotal Labs
Copyright (c) 2020-2024 The Jasmine developers
This software is licensed under the MIT License.

jasmine-browser-runner's People

Contributors

bicarbon8 avatar chadlwilson avatar dobromirtwogears avatar holgerjeromin avatar joeyparrish avatar kylefox avatar sgravrock avatar wraiford avatar ylecuyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jasmine-browser-runner's Issues

Running remote grid tests in parallel?

I'm trying to run tests on multiple platforms/browsers in parallel on Sauce (useRemoteSeleniumGrid === true). If I call runSpecs() multiple times without allowing it to finish, I understandably get:

Error: listen EADDRINUSE: address already in use :::5555

And if I try to specify a different port for each platform/browser combo, I get:

Error: Can't specify a port when browser.useSauce or browser.useRemoteSeleniumGrid is true

Is there any way to run multiple platforms/browsers in parallel? Apologies if I'm missing something obvious.

Running multiple browsers in parallel

We are trying to replace Karma. With Karma, we can run tests on multiple local or remote browsers in parallel. I would like to make this possible in jasmine-browser-runner. Please let me know what you think of the rough outline below, which I am 100% ready to contribute to if the maintainers are open to this.

Config

As far as the configuration, my first thought is that the "browser" config could be expanded to be an array. Or if the type confusion is too great for that (string, or object, or array of strings or objects...), we could mark "browser" as deprecated and switch to "browsers" (plural) that is always an array of objects.

I would tend to prefer "browsers" with a clear type of array of objects. The only required field on those objects would be "name". So the simplest config:

"browser": "firefox"

Converts to something not much longer:

"browsers": [ {"name": "firefox"} ]

We could continue to provide backward compatibility indefinitely by reading and interpreting "browser" and converting it internally. We could also choose to issue a warning in that case and request that users update their configs, if we ever intend to remove the original field.

The default could remain local Firefox only.

Launching

I propose that the array of browsers be turned into an array of webdriver instances via buildWebdriver, and that this array be passed to RunnerClass in index.js instead of a single instance. Instead of await runTillEnd, the runner could do something like await Promise.all(webdrivers.map(driver => runTillEnd(driver, reporters))).

Reporting

Some work may be needed to clarify which browser is reporting what results.

How to configure web server for binary file fetching?

Hi,
Probably I'm missing something but I couldn't find documentation for what is the best practice for solving it.
I'm using jasmine-browser-runner and I need to load external binary file in order to test application functionality.
Where should I place this file so that the web server jasmine is running with would be able to serve it?
How should I configure support.json for this file?
I've tried putting it srcDir but I couldn't access it from inside the spec.

Thank you very much!

Can Jasmine-browser-runner specs interact with a webapp?

I'm sure this title is confusing so let me explain my use case:

My product only has a frontend--a single page app. I already use jasmine for the unit tests. But for the integration/end to end tests, I use testcafe. The problem is, testcafe is very slow so I'm looking for alternatives. Since my product is 100% frontend, I don't need to serve my pages. I think that gives me an opportunity that doesn't normally exist.

In theory (I think?), I should be able to render my product in the same HTML page as the test runner. Then, my specs could interact with my product and assert on the HTML. I'm assuming if I could figure out how to do that, the tests would run much faster than they do with testcafe.

If this is sound reasoning (please tell me if it's not), here's my question: how do I use a custom html test runner? I'd need to merge my product's html with the test runner html, so they both exist on the same page.

README says to run the wrong command

Since the package is renamed on npm, the README and probably the actual script itself should be renamed to match. The current jasmine-browser command does not use this package.

jasmine-browser-runner do not support absolute paths for src and spec dirs

I spent quite some time figuring out why my tests were not found in the runner, I discovered that srcDir and specDir are joined with the project baseDir when finding the files...

In the server.js file, the userJs method, it uses getUrl that will always join this.projectBaseDir with the arguments...

It breaks when I pass absolute paths in the config file.

Would be nice to support them.
Thanks

init command

It would be nice to have an init command, like the other Jasmine runners have, to set up an initial environment including a basic valid config file.

npx jasmine-browser-runner runSpecs doesn't use the port from the configuration file

const portRequest = useSauce ? 5555 : 0;

Most of the CSS, js, and static content for my tests are served from a third-party server, which has a specific CORS configuration, and every time I run the tests I need them to run on the same PORT. There is a "port" option in the jasmine-browser.json but it works only for the "npx jasmine-browser-runner serve" command and not working for "npx jasmine-browser-runner runSpecs". Can you update the code above to read the port from the configuration if is set?

spec files in coffeescript

I have a rails 6 project that is using the asset pipeline. We have our spec files in coffeescript and have been using jasmine-gem that just supported coffescript specs since version 2(https://github.com/jasmine/jasmine-gem/blob/main/release_notes/v2.0.0.md).

Since the jasmine-gem is being deprecated we are migrating to jasmine-browser-runner as recommended in https://github.com/jasmine/jasmine-gem#deprecated but it seems that we cannot just specify our specFiles to be coffeescipt in jasmine-browser.json.

Is there a way to get coffeescript specs running with jasmine-browser-runner?

How to use external library loaded into the global scope?

Hi,
I'm now trying jasmine in browser to test library that can run only in browser.

My question:
In rollup and other build environments, there is an option to indicate usage of global libraries that are loaded using <script> tag in the webpage.
How can I include such a global in the spec so it would be loaded by the jasmine into the webpage during the spec running?

ES module testing and import maps

tl;dr

Is there an existing mechanism that I'm not seeing for import maps specifically? Or is there a more generic way to inject code into the run.html.ejs file?

context

I'm looking to build multiple packages and exploring options to try to minimize complexity. Currently I have jasmine working with testing ES modules in both node and in the browser in my base package with no imports with bare references. But as soon as I try to consume my base package in another package and test, I am unable to do so in the browser context (it works in node jasmine) since the browser does not know how to resolve the reference.

import { clone } from 'ts-gib';

succeeds in node jasmine but produces an error in the browser:

Uncaught TypeError: Failed to resolve module specifier "ts-gib". Relative references must start with either "/", "./", or "../".

workaround

If I manually modify my node_modules/jasmine-browser-runner/run.html.ejs to include an importmap script tag and then execute the jasmine-browser-runner (either runSpecs or serve), it works as expected.

<script type="importmap">
  {
    "imports": {
      "ts-gib": "https://unpkg.com/[email protected]/dist/browser/index.mjs"
    }
  }
</script>
...other script tags

Started
.
1 spec, 0 failures

additional comments

As an aside, with so much movement towards ES modules (even TypeScript v5 will be using them internally), I think this could be a huge opportunity going forward for whoever makes testing in both node and browsers with ES modules the easiest. The landscape is ever changing of course, but at the very least import maps seem to have been standardized in most browsers.

Unable to find the Google Chrome binary - macOS Ventura 13.5

With Chrome + chromedriver version 115 (and earlier I presume) on Ventura 13.5 - this has been repeated by multiple other users with the same environment. The runSpecs command fails with the following trace:

Running tests in the browser...
WebDriverError: unknown error: cannot find Chrome binary
    at Object.throwDecodedError (/Users/username/rails/project/node_modules/selenium-webdriver/lib/error.js:524:15)
    at parseHttpResponse (/Users/username/rails/project/node_modules/selenium-webdriver/lib/http.js:601:13)
    at Executor.execute (/Users/username/rails/project/node_modules/selenium-webdriver/lib/http.js:529:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  remoteStacktrace: '0   chromedriver                        0x0000000104616924 chromedriver + 4303140\n' +
    '1   chromedriver                        0x000000010460f050 chromedriver + 4272208\n' +
    '2   chromedriver                        0x0000000104243328 chromedriver + 291624\n' +
    '3   chromedriver                        0x000000010426ba7c chromedriver + 457340\n' +
    '4   chromedriver                        0x000000010426affc chromedriver + 454652\n' +
    '5   chromedriver                        0x00000001042aa040 chromedriver + 712768\n' +
    '6   chromedriver                        0x00000001042a980c chromedriver + 710668\n' +
    '7   chromedriver                        0x00000001042748d4 chromedriver + 493780\n' +
    '8   chromedriver                        0x000000010427571c chromedriver + 497436\n' +
    '9   chromedriver                        0x00000001045d77dc chromedriver + 4044764\n' +
    '10  chromedriver                        0x00000001045dbd20 chromedriver + 4062496\n' +
    '11  chromedriver                        0x00000001045e1f40 chromedriver + 4087616\n' +
    '12  chromedriver                        0x00000001045dc824 chromedriver + 4065316\n' +
    '13  chromedriver                        0x00000001045b4d1c chromedriver + 3902748\n' +
    '14  chromedriver                        0x00000001045f8414 chromedriver + 4178964\n' +
    '15  chromedriver                        0x00000001045f856c chromedriver + 4179308\n' +
    '16  chromedriver                        0x0000000104608830 chromedriver + 4245552\n' +
    '17  libsystem_pthread.dylib             0x00000001aab7bfa8 _pthread_start + 148\n' +
    '18  libsystem_pthread.dylib             0x00000001aab76da0 thread_start + 8\n'
}
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Other browsers work fine.

I've tracked it down to here:

return webdriverBuilder
        .forBrowser('chrome')
        .withCapabilities(caps)
        .build();

If I pass chrome options like so, it works as expected:

return webdriverBuilder
        .forBrowser('chrome')
        .setChromeOptions(new chrome.Options().setChromeBinaryPath('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome').headless())
        .withCapabilities(caps)
        .build();

I've tried reinstalling chrome, to no avail.

Support for running firefox headless

It'd be great to have better support for running Firefox headless out of the box with jasmine-browser-runner (similar to Chrome), or short of that an extension point to allow configuring Selenium Webdriver with the requisite firefox options.

I believe this would just require a call to .setFirefoxOptions(new firefox.Options().headless()) on the webdriver builder, so can take a look if there is interest.

Coverage reports

I am migrating to jasmine-browser-runner from teaspoon and missing the coverage option. I have been trying to generate coverage reports with nyc an c8 and failing. Any recommendations?

runSpecs producing unexplained "cyclic object value" on Firefox

Not sure if this is in the right place to report, but when running batch/CI mode with runSpecs on Firefox jasmine-browser-runner fails with

$ jasmine-browser-runner runSpecs --config=spec/javascripts/support/jasmine-browser.js
Jasmine server is running here: http://localhost:56034
Jasmine tests are here:         /Users/chad/Projects/community/gocd/gocd/server/src/main/webapp/WEB-INF/rails
Source files are here:          /Users/chad/Projects/community/gocd/gocd/server/src/main/webapp/WEB-INF/rails/public/assets
Running tests in the browser...
JavascriptError: Cyclic object value
    at Object.throwDecodedError (/Users/chad/Projects/community/gocd/gocd/server/src/main/webapp/WEB-INF/rails/node_modules/selenium-webdriver/lib/error.js:522:15)
    at parseHttpResponse (/Users/chad/Projects/community/gocd/gocd/server/src/main/webapp/WEB-INF/rails/node_modules/selenium-webdriver/lib/http.js:549:13)
    at Executor.execute (/Users/chad/Projects/community/gocd/gocd/server/src/main/webapp/WEB-INF/rails/node_modules/selenium-webdriver/lib/http.js:475:28)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async thenableWebDriverProxy.execute (/Users/chad/Projects/community/gocd/gocd/server/src/main/webapp/WEB-INF/rails/node_modules/selenium-webdriver/lib/webdriver.js:735:17) {
  remoteStacktrace: 'WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:183:5\n' +
    'JavaScriptError@chrome://remote/content/shared/webdriver/Errors.jsm:362:5\n' +
    'evaluate.assertAcyclic@chrome://remote/content/marionette/evaluate.js:52:11\n' +
    'evaluate.toJSON@chrome://remote/content/marionette/evaluate.js:323:14\n' +
    'receiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:177:31\n'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It seems to work perfectly fine with

  • Firefox and jasmine-browser-runner serve --config=spec/javascripts/support/jasmine-browser.js
  • runSpecs via Chrome (headless and non-headless)

I'm not sure what is different other than reporters, or how to debug further - any tips appreciated.

Environment

Question/Issue: Does jasmine-browser-runner support with selenium-webdriver 4.3+ well ?

Hi Team,
I saw the jasmine-browser-runner with package.json lock the selenium-webdriver at ^4.1.0.
In my project I try to install and use the selenium-webdriver from 4.3+, I got the problem the runner can not connect to jasmine-server and got a Timeout error message.

A summary of some investigations into the issue is provided below.

For Selenium-webdriver:
v4.2 will connect to the node server through 127.0.0.1 with Port
v4.3 will connect to the node server through the loopback address localhost with Port, somehow the node request can not connect to the loopback address, it will wait until timeout. And that is why we got the Timeout error message.

After trying deeper code changes of v4.2 and v4.3, I saw the code change like the picture below
image

Any suggestions on how to solve these issues would be greatly appreciated.

Regards,

Backslashes fix didn't make it to 0.5.0

Thank you for this tool!
I just switched from Mac to Win and I ran into the issue. I can see from the sourcecode that you already have a fix in place but it's not in 0.5.0. Can you release a new version with the fix please?

Add a watch mode?

When in "serve" mode, I would like my tests to be executed again when my code is updated.

In my scenario, the option specFiles is set to an array with just 1 webpack bundled file. Any update to that file should trigger a refresh so tests are executed again.

Is TLS supported?

I need to test software that uses APIs only available in a browser over HTTPS connections. Is there a way to provide TLS configuration to express to support this?

random: false has no effect to "serve" task (options ignored)

When running

npx jasmine-browser-runner serve --verbose --no-random

and using the following configuration at spec/support/jasmine-browser.json:

{
  "srcDir": ".",
  "srcFiles": [
    "src/**/*.?(m)js",
  ],
  "specDir": "spec",
  "specFiles": [
    "**/*[Ss]pec.?(m)js"
  ],
  "helpers": [
    "helpers/**/*.?(m)js"
  ],
  "random": false,
  "browser": "headlessChrome"
}

I get the following output:

$ npx jasmine-browser-runner serve --verbose --no-random
Jasmine server is running here: http://localhost:8888
Jasmine tests are here:         /home/me/project/spec
Source files are here:          /home/me/project/src

The option random: false has no effect.

I expect, that the URI in line 2 should include the option as parameter:

Jasmine server is running here: http://localhost:8888/?random=false

And I expect the same behaviour for the other options as well, if set.

Otherwise i always have to add that parameter manually, before opening the URI inside the browser.

[question] Can I inject library code into the test runner?

I'm trying to add jasmine to a legacy project but I have not been able to find if it's possible or how to inject library code into the test runner page.

I see that each file in my srcDir is included on the page served on localhost:8888.
Our client codebase expects underscore.js and jQuery but where do I define them as globally available when we do not have a package system or use ESM?

I would like to use jasmine for our nodejs express code as well so using the Standalone version would probably mean that we will have to maintain two versions of Jasmine until we have time to rewrite our project (which could benefit hugely from having unit-tests in that process).

The beginning of the test page:

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Jasmine suite</title>
<link rel="shortcut icon" type="image/png" href="/__images__/jasmine_favicon.png">
 
<link rel="stylesheet" href="/__jasmine__/jasmine.css" type="text/css" media="screen"/>
 
 
<script src="/__jasmine__/jasmine.js" type="text/javascript"></script>
 
<script src="/__jasmine__/jasmine-html.js" type="text/javascript"></script>
 
<script src="/__jasmine__/json2.js" type="text/javascript"></script>
 
<script src="/__boot__/boot.js" type="text/javascript"></script>
 
<script src="/__support__/loadEsModule.js" type="text/javascript"></script>
 
 
<!-- Start: import of my code  -->
<script src="/__src__/blocks/f-progress-stretch.js" type="text/javascript"></script>
<!-- ect... -->

jasmine-browser.json

{
  "srcDir": "public/js",
  "srcFiles": [
    "**/*.?(m)js"
  ],
  "specDir": "spec",
  "specFiles": [
    "**/*[sS]pec.?(m)js"
  ],
  "helpers": [
    "helpers/**/*.?(m)js"
  ],
  "random": true,
  "env": {},
  "browser": {
    "name": "firefox"
  }
}

nodejs: v14.17.3
jasmine: 3.8.0
jasmine-browser-runner: 0.7.0

Code Coverage

Hello, is there any way to integrate a code coverage for the browser code? I can't find any resource mentioning jasmine-browser.

Help text doesn't wrap correctly

The output of jasmine-browser --help should wrap to <= 80 columns (or better yet, the actual width of the terminal) but it's a bit wider than that. Specifically, the line that describes the --reporter option is 82 columns wide.

Running without webdriver.executeScript()

In our test lab, we have partial WebDriver implementations for some consumer electronics devices (TVs, Xbox, etc) that do not support executeScript().

With Karma, we didn't need executeScript(). Communication from the jasmine environment back to the runner was done through a WebSocket.

I would like to explore removing the getBatch() function in lib/runner.js, which is based on executeScript(). This will allow us to use jasmine-browser-runner on all our lab devices. I believe we could open a web socket back to jasmine-browser-runner's express-based web server for reporting, instead of dumping batches of events with executeScript().

ability to specify a configuration filename other than jasmine-browser.json

Request:

a way of specifying the filename of the jasmine-browser.json config file to be used

Purpose:

  • running with different browser configurations based on different environments
  • running with multiple, different browser configurations concurrently (both using headless, local browsers as well as when using a remote selenium grid)

Additional Notes:

  • while it would be possible to swap in separate files similar to how Angular builds swap in production vs. dev environment configuration files, this would not work when running tests concurrently which would force running sequentially against each browser. when the application needs to be tested in current and current minus 1 versions of all major browsers this would result in a large increase in the test execution time.
  • for my purposes, the location of the configuration file is not as important as simply being able to specify the name, but I could see value in allowing a full path to the file to be specified as this might make for cleaner root directories when using multiple configuration files

Cannot locate source files in spec - Error during loading: Uncaught Error: An error occurred while loading /__spec__/...

When running a spec I receive the following error:

GET http://localhost:8888/__spec__/browser.mjs net::ERR_ABORTED 404 (Not Found)
GET http://localhost:8888/__spec__/background.mjs net::ERR_ABORTED 404 (Not Found)
caught Error: An error occurred while loading /__spec__/browser_spec.mjs. Check the browser console for details.
    at HTMLScriptElement.<anonymous> (loadEsModule.js:15:11)

This appears due to its inability to find the two source files in the spec:

browser_spec.mjs

import { Browser } from './browser.mjs';
import { Background } from './background.mjs';

describe('Browser', function() {
...

jasmine-browser.json

{
  "srcDir": "source",
  "srcFiles": [],
  "specDir": "spec/unit/browser",
  "specFiles": [
    "**/*[sS]pec.?(m)js"
  ],
  "helpers": [
    "helpers/**/*.?(m)js"
  ],
  "env": {
    "stopSpecOnExpectationFailure": false,
    "stopOnSpecFailure": false,
    "random": false
  },
  "browser": {
    "name": "chrome"
  }
}

Node: v16.19.1
"jasmine-browser-runner": "^1.3.1"
"jasmine-core": "^4.6.0"

I've not used jasmine-browser-runner previously, so this is likely something really idiotic on my part.

Get browser information in reporter

I wonder if there is any interface (or maybe a dirty tunnel ;)) that would allow me to get information about the browser running the tests into my custom reporter. Any advice would be appreciated :)

Error running tests in Firefox on ubuntu-latest via GH Actions

I'm hitting what I believe is this issue SeleniumHQ/selenium#13169 when trying to run jasmine-browser-runner via GitHub Actions on Ubuntu >= 22.0.4. From my understanding, it is due to Firefox snap being the new default on Ubuntu, but it is installed in a different location.

Jasmine server is running here: http://localhost:9876
Jasmine tests are here:         /home/runner/work/dnt-helper/dnt-helper/tests/dist
Source files are here:          /home/runner/work/dnt-helper/dnt-helper/tests/dist
Running tests in the browser...
InvalidArgumentError: binary is not a Firefox executable
    at Object.throwDecodedError (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/error.js:521:15)
    at parseHttpResponse (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/http.js:514:13)
    at Executor.execute (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/http.js:446:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  remoteStacktrace: ''
}
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^
InvalidArgumentError: binary is not a Firefox executable
    at Object.throwDecodedError (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/error.js:521:15)
    at parseHttpResponse (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/http.js:514:13)
    at Executor.execute (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/http.js:446:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  remoteStacktrace: ''
}

This is a basic GitHub action template that can reproduce the issue:

name: "CI"
on:
  pull_request:
    branches:
    - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: "Install framebuffer (xvfb), Firefox and Chromium"
        run: |
          sudo apt-get update
          sudo apt-get install chromium-browser firefox xvfb
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - name: "Install JS dependencies"
        run: npm ci
      - name: "Run JS tests"
        run: xvfb-run npm test

From the issue I linked to it does not look like this is something Selenium will fix, since it supports passing alternate paths to the driver/executable already. However given that, I'm not quite sure how I can tell jasmine-browser-runner to instruct Selenium to use a different browser/driver path?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.