jest-environment-puppeteer
Advanced tools
Comparing version 3.3.1 to 3.4.0
@@ -6,2 +6,23 @@ # Change Log | ||
<a name="3.4.0"></a> | ||
# [3.4.0](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/compare/v3.3.1...v3.4.0) (2018-09-24) | ||
### Bug Fixes | ||
* support several instances of Jest in parallel ([#138](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/issues/138)) ([275bc71](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/commit/275bc71)) | ||
### Features | ||
* **jest-environment-puppeteer:** Add ability to connect to an already existing instance of Chrome ([9de05f0](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/commit/9de05f0)) | ||
* **jest-environment-puppeteer:** Add documentation of new `connect `options ([c6b0613](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/commit/c6b0613)) | ||
* **jest-environment-puppeteer:** Remove unneeded async config ([30a3daa](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/commit/30a3daa)) | ||
* **jest-environment-puppeteer:** Simplify getBrowser function ([8ccb0d0](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/commit/8ccb0d0)) | ||
* connect to an already existing instance of Chrome ([#100](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/issues/100)) ([3fcbaf8](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/commit/3fcbaf8)) | ||
<a name="3.3.1"></a> | ||
@@ -8,0 +29,0 @@ ## [3.3.1](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer/compare/v3.3.0...v3.3.1) (2018-08-17) |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,30 +7,10 @@ exports.__esModule = true; | ||
var _fs = require('fs'); | ||
var _jestDevServer = require("jest-dev-server"); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _puppeteer = _interopRequireDefault(require("puppeteer")); | ||
var _jestDevServer = require('jest-dev-server'); | ||
var _chalk = _interopRequireDefault(require("chalk")); | ||
var _mkdirp = require('mkdirp'); | ||
var _readConfig = _interopRequireDefault(require("./readConfig")); | ||
var _mkdirp2 = _interopRequireDefault(_mkdirp); | ||
var _rimraf = require('rimraf'); | ||
var _rimraf2 = _interopRequireDefault(_rimraf); | ||
var _puppeteer = require('puppeteer'); | ||
var _puppeteer2 = _interopRequireDefault(_puppeteer); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _readConfig = require('./readConfig'); | ||
var _readConfig2 = _interopRequireDefault(_readConfig); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -42,7 +22,12 @@ | ||
async function setup() { | ||
const config = await (0, _readConfig2.default)(); | ||
browser = await _puppeteer2.default.launch(config.launch); | ||
_mkdirp2.default.sync(_constants.DIR); | ||
_fs2.default.writeFileSync(_constants.WS_ENDPOINT_PATH, browser.wsEndpoint()); | ||
const config = await (0, _readConfig.default)(); | ||
if (config.connect) { | ||
browser = await _puppeteer.default.connect(config.connect); | ||
} else { | ||
browser = await _puppeteer.default.launch(config.launch); | ||
} | ||
process.env.PUPPETEER_WS_ENDPOINT = browser.wsEndpoint(); | ||
if (config.server) { | ||
@@ -54,12 +39,14 @@ try { | ||
console.log(''); | ||
console.error(_chalk2.default.red(error.message)); | ||
console.error(_chalk2.default.blue(`\n☝️ You can set "server.launchTimeout" in jest-puppeteer.config.js`)); | ||
console.error(_chalk.default.red(error.message)); | ||
console.error(_chalk.default.blue(`\n☝️ You can set "server.launchTimeout" in jest-puppeteer.config.js`)); | ||
process.exit(1); | ||
} | ||
if (error.code === _jestDevServer.ERROR_NO_COMMAND) { | ||
console.log(''); | ||
console.error(_chalk2.default.red(error.message)); | ||
console.error(_chalk2.default.blue(`\n☝️ You must set "server.command" in jest-puppeteer.config.js`)); | ||
console.error(_chalk.default.red(error.message)); | ||
console.error(_chalk.default.blue(`\n☝️ You must set "server.command" in jest-puppeteer.config.js`)); | ||
process.exit(1); | ||
} | ||
throw error; | ||
@@ -73,3 +60,2 @@ } | ||
await browser.close(); | ||
_rimraf2.default.sync(_constants.DIR); | ||
} |
@@ -1,33 +0,18 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
// eslint-disable-next-line | ||
var _jestEnvironmentNode = _interopRequireDefault(require("jest-environment-node")); | ||
var _puppeteer = _interopRequireDefault(require("puppeteer")); | ||
var _fs = require('fs'); | ||
var _chalk = _interopRequireDefault(require("chalk")); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _readConfig = _interopRequireDefault(require("./readConfig")); | ||
var _jestEnvironmentNode = require('jest-environment-node'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _jestEnvironmentNode2 = _interopRequireDefault(_jestEnvironmentNode); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var _puppeteer = require('puppeteer'); | ||
var _puppeteer2 = _interopRequireDefault(_puppeteer); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _readConfig = require('./readConfig'); | ||
var _readConfig2 = _interopRequireDefault(_readConfig); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const handleError = error => { | ||
@@ -43,3 +28,3 @@ process.emit('uncaughtException', error); | ||
class PuppeteerEnvironment extends _jestEnvironmentNode2.default { | ||
class PuppeteerEnvironment extends _jestEnvironmentNode.default { | ||
// Jest is not available here, so we have to reverse engineer | ||
@@ -57,13 +42,15 @@ // the setTimeout function, see https://github.com/facebook/jest/blob/v23.1.0/packages/jest-runtime/src/index.js#L823 | ||
async setup() { | ||
const config = await (0, _readConfig2.default)(); | ||
const config = await (0, _readConfig.default)(); | ||
this.global.puppeteerConfig = config; | ||
const wsEndpoint = process.env.PUPPETEER_WS_ENDPOINT; | ||
const wsEndpoint = _fs2.default.readFileSync(_constants.WS_ENDPOINT_PATH, 'utf8'); | ||
if (!wsEndpoint) { | ||
throw new Error('wsEndpoint not found'); | ||
} | ||
this.global.browser = await _puppeteer2.default.connect(_extends({}, config.launch, { | ||
this.global.browser = await _puppeteer.default.connect(_extends({}, config.connect, config.launch, { | ||
browserWSEndpoint: wsEndpoint | ||
})); | ||
this.global.page = await this.global.browser.newPage(); | ||
if (config && config.exitOnPageError) { | ||
@@ -77,16 +64,20 @@ this.global.page.addListener('pageerror', handleError); | ||
// Set timeout to 4 days | ||
this.setTimeout(345600); | ||
// Run a debugger (in case Puppeteer has been launched with `{ devtools: true }`) | ||
this.setTimeout(345600); // Run a debugger (in case Puppeteer has been launched with `{ devtools: true }`) | ||
await this.global.page.evaluate(() => { | ||
// eslint-disable-next-line no-debugger | ||
debugger; | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log(_chalk2.default.blue('\n\n🕵️ Code is paused, press enter to resume')); | ||
// Run an infinite promise | ||
}); // eslint-disable-next-line no-console | ||
console.log(_chalk.default.blue('\n\n🕵️ Code is paused, press enter to resume')); // Run an infinite promise | ||
return new Promise(resolve => { | ||
const { stdin } = process; | ||
const { | ||
stdin | ||
} = process; | ||
const onKeyPress = key => { | ||
if (key === KEYS.CONTROL_C || key === KEYS.CONTROL_D || key === KEYS.ENTER) { | ||
stdin.removeListener('data', onKeyPress); | ||
if (!listening) { | ||
@@ -96,6 +87,9 @@ stdin.setRawMode(false); | ||
} | ||
resolve(); | ||
} | ||
}; | ||
const listening = stdin.listenerCount('data') > 0; | ||
if (!listening) { | ||
@@ -106,2 +100,3 @@ stdin.setRawMode(true); | ||
} | ||
stdin.on('data', onKeyPress); | ||
@@ -117,4 +112,6 @@ }); | ||
} | ||
} | ||
exports.default = PuppeteerEnvironment; | ||
var _default = PuppeteerEnvironment; | ||
exports.default = _default; |
@@ -1,25 +0,19 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
var _fs = require('fs'); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _path = require('path'); | ||
var _util = require("util"); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _cwd = _interopRequireDefault(require("cwd")); | ||
var _util = require('util'); | ||
var _lodash = require("lodash"); | ||
var _cwd = require('cwd'); | ||
var _cwd2 = _interopRequireDefault(_cwd); | ||
var _lodash = require('lodash'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const exists = (0, _util.promisify)(_fs2.default.exists); | ||
const exists = (0, _util.promisify)(_fs.default.exists); | ||
const DEFAULT_CONFIG = { | ||
@@ -38,6 +32,7 @@ launch: {}, | ||
const defaultConfig = process.env.CI === 'true' ? DEFAULT_CONFIG_CI : DEFAULT_CONFIG; | ||
const hasCustomConfigPath = !!process.env.JEST_PUPPETEER_CONFIG; | ||
const configPath = process.env.JEST_PUPPETEER_CONFIG || 'jest-puppeteer.config.js'; | ||
const absConfigPath = _path2.default.resolve((0, _cwd2.default)(), configPath); | ||
const absConfigPath = _path.default.resolve((0, _cwd.default)(), configPath); | ||
const configExists = await exists(absConfigPath); | ||
@@ -51,9 +46,11 @@ | ||
return defaultConfig; | ||
} | ||
} // eslint-disable-next-line global-require, import/no-dynamic-require | ||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
const localConfig = require(absConfigPath); | ||
return (0, _lodash.merge)({}, defaultConfig, localConfig); | ||
} | ||
exports.default = readConfig; | ||
var _default = readConfig; | ||
exports.default = _default; |
{ | ||
"name": "jest-environment-puppeteer", | ||
"description": "Puppeteer environment for Jest.", | ||
"version": "3.3.1", | ||
"version": "3.4.0", | ||
"main": "index.js", | ||
@@ -19,3 +19,3 @@ "repository": "https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-environment-puppeteer", | ||
"prebuild": "rm -rf lib/", | ||
"build": "babel src -d lib --ignore \"*.test.js\"", | ||
"build": "babel --config-file ../../babel.config.js -d lib --ignore \"**/*.test.js\" src", | ||
"dev": "yarn build --watch", | ||
@@ -30,8 +30,6 @@ "prepublishOnly": "yarn build" | ||
"cwd": "^0.10.0", | ||
"jest-dev-server": "^3.3.0", | ||
"lodash": "^4.17.10", | ||
"mkdirp": "^0.5.1", | ||
"rimraf": "^2.6.2" | ||
"jest-dev-server": "^3.4.0", | ||
"lodash": "^4.17.11" | ||
}, | ||
"gitHead": "89e72b765bd69ea05dd5251f8d155899f13a19c4" | ||
"gitHead": "5c014f28a9a67b765dcc468471bc23a437903b18" | ||
} |
@@ -81,5 +81,8 @@ # jest-environment-puppeteer | ||
- `launch` <[object]> [All Puppeteer launch options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions) can be specified in config. Since it is JavaScript, you can use all stuff you need, including environment. | ||
- `connect` <[object]> [All Puppeteer connect options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerconnectoptions) can be specified in config. This is an alternative to `launch` config, allowing you to connect to an already running instance of Chrome. | ||
- `exitOnPageError` <[boolean]> Exits page on any global error message thrown. Defaults to `true`. | ||
- `server` <[Object]> Server options allowed by [jest-dev-server](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-dev-server) | ||
#### Example 1 | ||
```js | ||
@@ -101,2 +104,23 @@ // jest-puppeteer.config.js | ||
#### Example 2 | ||
This example uses an already running instance of Chrome by passing the active web socket endpoint to `connect`. This is useful, for example, when you want to connect to Chrome running in the cloud. | ||
```js | ||
// jest-puppeteer.config.js | ||
const wsEndpoint = fs.readFileSync(endpointPath, 'utf8') | ||
module.exports = { | ||
connect: { | ||
browserWSEndpoint: wsEndpoint, | ||
}, | ||
server: { | ||
command: 'node server.js', | ||
port: 4444, | ||
launchTimeout: 10000, | ||
debug: true, | ||
}, | ||
} | ||
``` | ||
## Inspiration | ||
@@ -103,0 +127,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
20882
5
138
10
167
- Removedmkdirp@^0.5.1
- Removedrimraf@^2.6.2
Updatedjest-dev-server@^3.4.0
Updatedlodash@^4.17.11