Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
dependency_cache:
docker:
- image: circleci/node:14-browsers
- image: circleci/node:16-browsers
steps:
- checkout
- restore_cache:
Expand All @@ -16,7 +16,7 @@ jobs:
- ./node_modules
node-v14-latest:
docker:
- image: circleci/node:14-browsers
- image: circleci/node:16-browsers
steps:
- checkout
- restore_cache:
Expand All @@ -33,7 +33,7 @@ jobs:
when: on_success
analysis:
docker:
- image: circleci/node:14-browsers
- image: circleci/node:16-browsers
steps:
- checkout
- restore_cache:
Expand Down
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

17 changes: 17 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
mocha: true
},
extends: [
'standard'
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
rules: {
}
}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
16
106 changes: 54 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[tests]: https://img.shields.io/circleci/project/github/shellscape/mocha-chrome.svg
[tests]: https://img.shields.io/circleci/project/github/shellscape/mocha-chrome.svg
[tests-url]: https://circleci.com/gh/shellscape/mocha-chrome

[size]: https://packagephobia.now.sh/badge?p=mocha-chrome
[size-url]: https://packagephobia.now.sh/result?p=mocha-chrome

Expand All @@ -14,7 +13,7 @@

## Requirements

`mocha-chrome` requires Node v8.0.0 or higher.
`mocha-chrome` requires Node v16.0.0 or higher.

`mocha-chrome` is a development tool, which means you can use tools like [NVM](https://github.com/creationix/nvm) and [nodenv](https://github.com/nodenv/nodenv) to manage your installed versions, and temporarily switch to v8+ to run tests on your machine. Most modern CI environments also support specifying the version of Node to run.

Expand All @@ -35,18 +34,19 @@ $ npm install mocha --save-dev
To run the tests, you'll need an HTML file with some basics:

```html
<!doctype>
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="utf-8">
<meta charset="utf-8" />
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/chai/chai.js"></script>
</head>
<body>
<div id="mocha"></div>
<script>
mocha.setup("bdd");
expect = chai.expect;

// add tests here
Expand All @@ -55,7 +55,6 @@ To run the tests, you'll need an HTML file with some basics:
</script>
</body>
</html>

```

You can then add your tests either through an external script file or inline within a `<script>` tag. Running the tests is easy, either with the CLI binary, or programmatically.
Expand Down Expand Up @@ -97,53 +96,58 @@ Example usage can be found in both [test.js](test/test.js) and [bin/mocha-chrome

#### `config`

Fired to indicate that `mocha-chrome` should configure mocha.
Fired to indicate that `mocha-chrome` should configure mocha.

#### `ended`

Fired when all tests have ended.
Fired when all tests have ended.

##### Parameters
`stats` : `object` - A Mocha stats object. eg:

```js
{
suites: 1,
tests: 1,
passes: 1,
pending: 0,
failures: 0,
start: '2017-08-03T02:12:02.007Z',
end: '2017-08-03T02:12:02.017Z',
duration: 10
}
```

`stats` : `object` - A Mocha stats object. eg:

```js
{
suites: 1,
tests: 1,
passes: 1,
pending: 0,
failures: 0,
start: '2017-08-03T02:12:02.007Z',
end: '2017-08-03T02:12:02.017Z',
duration: 10
}
```

#### `ready`

Fired to indicate that the mocha script in the client has been loaded.
Fired to indicate that the mocha script in the client has been loaded.

#### `resourceFailed`

Fired when a resource fails to load.
Fired when a resource fails to load.

##### Parameters

##### Parameters
`data` : `object` - An object containing information about the resource. eg:
`data` : `object` - An object containing information about the resource. eg:

```js
{ url, method, reason }
```
```js
{
url, method, reason;
}
```

#### `started`

Fired when a resource fails to load.
Fired when a resource fails to load.

##### Parameters
`tests` : `number` - The number of tests being run.
##### Parameters

`tests` : `number` - The number of tests being run.

#### `width`

Fired to indicate that `mocha-chrome` should inform mocha of the width of the current console/terminal.
Fired to indicate that `mocha-chrome` should inform mocha of the width of the current console/terminal.

## Limitations

Expand All @@ -160,22 +164,22 @@ Third party reporters are not currently supported, but support is planned. Contr
Chrome has long-since disabled cookies for files loaded via the `file://` protocol. The once-available `--enable-file-cookies` has been removed and we're left with few options. If you're in need of cookie support for your local-file test, you may use the following snippet, which will shim `document.cookie` with _very basic_ support:

```js
Object.defineProperty(document, 'cookie', {
get: function () {
return this.value || '';
},
set: function (cookie) {
cookie = cookie || '';

const cutoff = cookie.indexOf(';');
const pair = cookie.substring(0, cutoff >= 0 ? cutoff : cookie.length);
const cookies = this.value ? this.value.split('; ') : [];

cookies.push(pair);

return this.value = cookies.join('; ');
}
});
Object.defineProperty(document, "cookie", {
get: function () {
return this.value || "";
},
set: function (cookie) {
cookie = cookie || "";

const cutoff = cookie.indexOf(";");
const pair = cookie.substring(0, cutoff >= 0 ? cutoff : cookie.length);
const cookies = this.value ? this.value.split("; ") : [];

cookies.push(pair);

return (this.value = cookies.join("; "));
},
});
```

## Continuous Integration
Expand All @@ -190,9 +194,7 @@ Please refer to the _"Running it all on Travis CI"_ portion of the guide on [Aut
Google. Though the article primarily addresses Karma, the setup for Travis CI is
identical.

As of January 8th, 2018, Travis CI has upgraded from Trusty -> Xenial to address the [Meltdown](https://en.wikipedia.org/wiki/Meltdown_(security_vulnerability)) security vulnerability. There are issues with Chrome in Xenial that can currently be worked around with `sudo: required`. At some point this workaround may be removable. For the near term, please add `sudo: required` to Travis CI configuration files. See [travis-ci/travis-ci#8836](travis-ci/travis-ci#8836). Credit: [@smalls](https://github.com/shellscape/mocha-chrome/pull/21).


As of January 8th, 2018, Travis CI has upgraded from Trusty -> Xenial to address the [Meltdown](<https://en.wikipedia.org/wiki/Meltdown_(security_vulnerability)>) security vulnerability. There are issues with Chrome in Xenial that can currently be worked around with `sudo: required`. At some point this workaround may be removable. For the near term, please add `sudo: required` to Travis CI configuration files. See [travis-ci/travis-ci#8836](travis-ci/travis-ci#8836). Credit: [@smalls](https://github.com/shellscape/mocha-chrome/pull/21).

## Testing mocha-chrome

Expand Down
17 changes: 13 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/usr/bin/env node

const debug = require('debug')('mocha-chrome');
const importLocal = require('import-local');
import { fileURLToPath } from 'url'

import importLocal from 'import-local'

import debug from 'debug'

import { run } from './lib/cli.js'

const nsDebug = debug('mocha-chrome')

const __filename = fileURLToPath(import.meta.url)

// Prefer the local installation of AVA
if (importLocal(__filename)) {
debug('Using local install of mocha-chrome');
nsDebug('Using local install of mocha-chrome')
} else {
// eslint-disable-next-line global-require
require('./lib/cli');
run()
}
20 changes: 0 additions & 20 deletions client/.eslintrc

This file was deleted.

12 changes: 6 additions & 6 deletions client/event-bus.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(function eventBus(root) {
(function eventBus (root) {
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
root._eventbus = {
emit(name, data = '') {
const json = JSON.stringify({ name, data });
emit (name, data = '') {
const json = JSON.stringify({ name, data })

window.localStorage.setItem('mocha-chrome-bus', json);
window.localStorage.setItem('mocha-chrome-bus', json)
}
};
})(window);
}
})(window)
Loading