Giter Site home page Giter Site logo

jasmine-browser-runner's Introduction

A JavaScript Testing Framework

Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, Node.js projects, or anywhere that JavaScript can run.

Upgrading from Jasmine 4.x? Check out the upgrade guide.

Contributing

Please read the contributors' guide.

Installation

There are several different ways to install Jasmine, depending on your environment and how you'd like to use it. See the Getting Started page for details.

Usage

See the documentation site, particularly the Your First Suite tutorial for information on writing specs, and the FAQ.

Supported environments

Jasmine tests itself across popular browsers (Safari, Chrome, Firefox, and Microsoft Edge) as well as Node.

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

For evergreen browsers, each version of Jasmine 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 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.

Maintainers

Maintainers Emeritus

Copyright (c) 2008-2019 Pivotal Labs
Copyright (c) 2008-2023 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jasmine-browser-runner's Issues

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

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.

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.

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.

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?

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.

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.

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

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 :)

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.

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.

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.

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,

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.

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?

[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

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.

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?

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().

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?

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!

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.

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.

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.

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?

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

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?

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.