jasmine / jasmine-browser-runner Goto Github PK
View Code? Open in Web Editor NEWServe and run your Jasmine specs in a browser
Serve and run your Jasmine specs in a browser
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.
As discussed in #14, it's not obvious to everyone that interactive debugging should be done via the serve
subcommand. The introductory docs should mention that, both in the README here and on the docs site.
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.
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.
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)))
.
Some work may be needed to clarify which browser is reporting what results.
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?
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?
I'd like to get the logs from the browser console when running jasmine-browser-runner runSpecs
for chromeHeadless
.
How can I do that?
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().
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.
Currently this will also involve setting up argument parsing in general. In order to keep the list of runtime dependencies as small as possible, we don't currently want to pull in a third-party argument parser. We will probably want to use something basic like in jasmine-npm's command.
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!
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
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
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.
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.
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.
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?
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 "../".
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
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.
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 :)
I would like to generate static javascript files and run those tests myself using nginx.
I am trying to achieve something like this, https://scriptverse.academy/tutorials/jasmine-spec-browser.html but using modern dev tooling.
Do we have something like,
jasmine-browser-runner build
?
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.
Allowing users to add arbitrary Express middleware would cover the same use cases as #13 and #33 as well as others that we haven't thought of yet. See this comment for a proposed API.
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
http://localhost:8888/ redirects to https://localhost:8888/
This site can’t provide a secure connection
localhost sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
Not sure if this is my side or yours...
Using Chrome browser
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?
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.
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.
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
Any suggestions on how to solve these issues would be greatly appreciated.
Regards,
jasmine-browser-runner/index.js
Line 79 in 69a1896
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?
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.
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.
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
Is there any way to get custom reporter for jasmine (like https://www.npmjs.com/package/jasmine-reporters) configured to be used with jasmine-browser-runner.
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?
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?
Steps to reproduce:
npm install --save-dev jasmine-browser-runner
npx jasmine-browser init
npm ERR! could not determine executable to run
2021-08-01T16_06_44_991Z-debug.log
OS: Ubuntu 21.04 on Windows 10 WSL2
node: v14.17.3
npm: 7.20.3
Hello, is there any way to integrate a code coverage for the browser code? I can't find any resource mentioning jasmine-browser.
Hello!
Just wondering if there would be a property in the config that I can set to treat certain files as es modules.
For example for mozilla.org's repo - we name JS modules with *.es6.js
. If you feel like this could be a helpful change, I would also be more than happy to make a PR for this - if someone would be able to point me in the correct direction? Thanks!
a way of specifying the filename of the jasmine-browser.json
config file to be used
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.