{"id":23280970,"url":"https://github.com/nicholaswmin/polymer-rtc-testing","last_synced_at":"2026-03-20T01:05:57.096Z","repository":{"id":78088810,"uuid":"148292319","full_name":"nicholaswmin/polymer-rtc-testing","owner":"nicholaswmin","description":"Guide on unit-testing WebRTC Polymer 1.0 elements.","archived":false,"fork":false,"pushed_at":"2018-09-11T11:37:24.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T20:56:07.730Z","etag":null,"topics":["opentok","polymer","web-rtc"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicholaswmin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-11T09:21:43.000Z","updated_at":"2023-03-08T02:33:14.000Z","dependencies_parsed_at":"2023-05-03T10:47:18.066Z","dependency_job_id":null,"html_url":"https://github.com/nicholaswmin/polymer-rtc-testing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nicholaswmin/polymer-rtc-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Fpolymer-rtc-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Fpolymer-rtc-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Fpolymer-rtc-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Fpolymer-rtc-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicholaswmin","download_url":"https://codeload.github.com/nicholaswmin/polymer-rtc-testing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Fpolymer-rtc-testing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28602175,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T10:46:13.255Z","status":"ssl_error","status_checked_at":"2026-01-20T10:42:51.865Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["opentok","polymer","web-rtc"],"created_at":"2024-12-19T23:39:47.684Z","updated_at":"2026-01-20T11:03:58.726Z","avatar_url":"https://github.com/nicholaswmin.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# polymer-rtc-testing\nGuide on unit-testing [OpenTok][opentok] WebRTC Polymer 1.0 elements.\n\n## Overview\n\nTesting WebRTC-enabled components is a special case when doing unit-testing.\n\nWe need 2 (or more) parallel test instances in order to simulate multi-party\ncalls and we also need to suppress browser-level \"Share your mic/camera\"-type\nof dialog boxes, otherwise the tests will fail.\n\nThis guide focuses on unit-testing OpenTok Polymer 1.0 elements, where\nthe element needs to be tested using 2 WCT instances running in parallel.\n\nWhile it focuses on OpenTok's Web SDK, it's general concepts should be\napplicable to standard/vendorless WebRTC implementations.\n\n### View the sample \u003crtc-element\\\u003e\n\n[![Build Status rtc-element](https://travis-ci.org/nicholaswmin/polymer-rtc-testing.svg?branch=master)](https://travis-ci.org/nicholaswmin/polymer-rtc-testing)\n\nThere's a sample Polymer element in `/rtc-element` with unit-tests which are\nrun with the strategy illustrated in this guide.\n\nAdd your own [TokBox][tokbox] account credentials in the `credentials` property\nof `rtc-element/rtc-element.html`, like so:\n\n```javascript\ncredentials: {\n  type: Object,\n  value: function() {\n    return {\n      // Replace with your actual TokBox account credentials.\n      api_key: 1234,\n      token: 'foo-token',\n      session_id: 'foo-session-id'\n    }\n  },\n  observer: '_initSession'\n}\n```\n\nand then:\n\n```bash\n$ cd rtc-element\n$ npm install -g polymer-cli mocha\n$ npm install \u0026\u0026 bower install\n$ npm test\n```\n\n## Guide\n\n### Add important [WCT][wct] configuration\n\nAdd the following `wct.conf.json` in your element's directory.\n\n```javascript\n{\n  \"expanded\": true,\n  \"suites\": [\"test/*.html\"],\n  \"plugins\": {\n    \"local\": {\n      \"browsers\": [\n        \"chrome\"\n      ],\n      \"browserOptions\": {\n        \"chrome\": [\n          \"auto-select-desktop-capture-source='Entire screen'\",\n          \"use-fake-device-for-media-stream\",\n          \"use-fake-ui-for-media-stream\"\n        ]\n      }\n    }\n  }\n}\n```\n\nThis tells WCT to:\n\n- Ignore `.js` files in `test/` since we are going to add a MochaJS test script\n  there.\n- Prevent pop-up of \"Do you want to share your mic/camera?\" dialogs.\n\n### Run tests using [Mocha][mocha] instead of the polymer-cli\n\nYou should still write the actual unit-tests as `test-1.html`, `test-2.html`\netc in `tests/`, but instead of running them all with `$ polymer test` we are\ngoing to use a Mocha script which executes `$ polymer test` test runs\nof them, in-parallel.\n\nIn your element:\n\n```bash\n# Specify `$ mocha test/run.js` when prompted for a test script.\n$ npm init\n$ npm install --save-dev mocha\n```\n\nThe following script spawns 2 [WCT][wct] instances, running in-parallel.\n\n`test/run.js`:\n\n```javascript\n'use strict'\n\nconst spawn = require('child_process').spawn\n\n// @NOTE\n// Helper function that spawns N `$ polymer test` instances and returns\n// a Promise which resolves if all instances have exited with 0,\n// rejects otherwise.\nconst spawnPolymerTest = ({ times = 2 }) =\u003e {\n  const tasks = Array.from({ length: times }, () =\u003e ['polymer', ['test']])\n    .map(args =\u003e {\n      return new Promise(resolve =\u003e {\n        spawn(args[0], args[1], { stdio: 'inherit' }).on('exit', resolve)\n      })\n    })\n\n  return Promise.all(tasks)\n    .then(exitCodes =\u003e {\n      if (!exitCodes.every(result =\u003e result === 0))\n        throw new Error('Some tests have failed')\n\n      return\n    })\n}\n\ndescribe('Test Suite', () =\u003e {\n  it ('Runs OK under normal network conditions', function() {\n    this.timeout(60000)\n\n    return spawnPolymerTest({ times: 2 })\n  })\n\n  // ... add more tests as you see fit.\n})\n```\n\nThen run:\n\n```bash\n$ mocha test/run.js\n```\n\nto run your tests.\n\n### Sample unit-test\n\nA sample unit-test that tests a video call between 2 parties:\n\n```javascript\n\nsuite('rtc-element', function() {\n  test('Starts a call', function(done) {\n    // @NOTE Allow ample timeout as calls might take a while to connect,\n    // esp. under bad network conditions.\n    this.timeout(10000)\n\n    const element = fixture('basic')\n\n    element.session.on('streamCreated', e =\u003e {\n      element.session.getSubscribersForStream(e.stream)\n        .forEach(subscriber =\u003e {\n          subscriber.on('videoElementCreated', e =\u003e {\n            // @NOTE\n            // Opentok.js swallows errors in event handlers (eventing.js),\n            // so we have to call `done(err)` ourselves, using `try/catch`.\n            try {\n              const publisherVideoElem = Polymer.dom(element.root)\n                .querySelector('#publisher')\n                .querySelectorAll('.OT_root')\n\n              const subscriberVideoElem = Polymer.dom(element.root)\n                .querySelector('#subscriber')\n                .querySelectorAll('.OT_root')\n\n              assert.lengthOf(Array.from(publisherVideoElem), 2)\n              assert.lengthOf(Array.from(subscriberVideoElem), 1)\n\n              // @NOTE\n              // Wait for the other client to create his video element\n              // and run his tests before moving on.\n              setTimeout(() =\u003e done(), 3000)\n            } catch (err) {\n              done(err)\n            }\n          })\n        })\n    })\n\n    element.startCall().catch(done)\n  })\n})\n```\n\n## Simulating bad network conditions\n\nYou should aim to test how your element fares under bad network conditions.\n\nThe [sitespeedio/throttle][sitespeedio/throttle] package is a tool that allows\nsystem-wide throttling of network connections. It can also be used as a\nNode.js module so you can easily include it in `test/run.js` to run\ntests under (simulated) bad network conditions.\n\nHowever it needs `sudo` permissions before it runs, runs only on Linux/MacOS\nand requires that you explicitly stop it when the tests are done.\n\n## Building on TravisCI\n\nSample `.travis.yml` file:\n\n```yaml\nlanguage: node_js\nsudo: required\nbefore_script:\n  - npm install -g bower polymer-cli mocha\n  - sudo mv /usr/bin/google-chrome /usr/bin/google-chrome-old\n  - sudo mv /usr/bin/google-chrome-beta /usr/bin/google-chrome\nnode_js: stable\naddons:\n  firefox: latest\n  apt:\n    sources:\n      - google-chrome\n    packages:\n      - google-chrome-beta\nscript:\n  - npm install\n  - bower install\n  - xvfb-run npm test\ndist: trusty\n```\n\n## Todos\n\nSee: https://github.com/nicholaswmin/polymer-rtc-testing/issues/1.\n\n## Resources\n\n- [Automated Testing for OpenTok Applications in the Browser][automated-testing-opentok]\n- [WebRTC - Testing][webrtc.org:testing]\n\n## Authors\n\n- [Nicholas Kyriakides, @nicholaswmin][nicholaswmin]\n\n[opentok]: https://github.com/opentok\n[wct]: https://github.com/Polymer/web-component-tester\n[automated-testing-opentok]: https://tokbox.com/blog/automated-testing-for-opentok-applications-in-the-browser/\n[nicholaswmin]: https://github.com/nicholaswmin\n[sitespeedio/throttle]: https://github.com/sitespeedio/throttle\n[mocha]: https://mochajs.org/\n[webrtc.org:testing]: https://webrtc.org/testing/\n[tokbox]: https://tokbox.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicholaswmin%2Fpolymer-rtc-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicholaswmin%2Fpolymer-rtc-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicholaswmin%2Fpolymer-rtc-testing/lists"}