Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to static Chromy functions #621

Merged
merged 3 commits into from
Jan 4, 2018
Merged
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,21 @@ An example config below...
}
```

### Using Chromy static functions
To access use of Chromys static functions (such as addCustomDevice) the static chromy reference is sent as the fifth parameter to your onBefore/onReady scripts.

Example usage:

```
module.exports = function (chromy, scenario, vp, isReference, chromyStatic) {
if(vp.label === "phone") {
chromyStatic.addCustomDevice({ name: "some-phone", /.../ });
chromy.emulate("some-phone");
}
}
```
For more info, see the [Chromy script documentation](https://github.com/OnetapInc/chromy).

### Integration options (local install)

TLDR; run the example here...
Expand Down
2 changes: 1 addition & 1 deletion core/command/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var commands = commandNames
promise.catch(function (error) {
var perf = (new Date() - config.perf[command.name].started) / 1000;
logger.error('Command `' + command.name + '` ended with an error after [' + perf + 's]');
// logger.error(error);
logger.error(error);
});

return promise.then(function (result) {
Expand Down
5 changes: 3 additions & 2 deletions core/util/runChromy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function (args) {
const runId = args.id;
const scenarioLabelSafe = makeSafe(scenario.label);
const variantOrScenarioLabelSafe = scenario._parent ? makeSafe(scenario._parent.label) : scenarioLabelSafe;

return processScenarioView(scenario, variantOrScenarioLabelSafe, scenarioLabelSafe, viewport, config, runId);
};

Expand Down Expand Up @@ -171,7 +172,7 @@ function processScenarioView (scenario, variantOrScenarioLabelSafe, scenarioLabe
if (onBeforeScript) {
var beforeScriptPath = path.resolve(engineScriptsPath, onBeforeScript);
if (fs.existsSync(beforeScriptPath)) {
require(beforeScriptPath)(chromy, scenario, viewport, isReference);
require(beforeScriptPath)(chromy, scenario, viewport, isReference, Chromy);
} else {
console.warn(PORT, ' WARNING: script not found: ' + beforeScriptPath);
}
Expand Down Expand Up @@ -246,7 +247,7 @@ function processScenarioView (scenario, variantOrScenarioLabelSafe, scenarioLabe
if (onReadyScript) {
var readyScriptPath = path.resolve(engineScriptsPath, onReadyScript);
if (fs.existsSync(readyScriptPath)) {
require(readyScriptPath)(chromy, scenario, viewport, isReference);
require(readyScriptPath)(chromy, scenario, viewport, isReference, Chromy);
} else {
console.warn(PORT, 'WARNING: script not found: ' + readyScriptPath);
}
Expand Down