Ghost Inspector Node.js Bindings
The official Node.js package and CLI for interacting with Ghost Inspector's API.
Jump to...
- Installation
- Quick Start
- CLI Usage
- Node.js Client Usage
- Contributing
Installation
Our official Node.js package is available from npm, you can install it with the following command:
npm install ghost-inspectorIn order to use the CLI, install the package globally:
npm install -g ghost-inspectorQuick Start
const GhostInspector = require('ghost-inspector')('[api-key]')
// execute a test
try {
const [results, passing, screenshotPassing] = await GhostInspector.executeTest(
'[test-id]',
options,
)
console.log('Passing: ', passing)
} catch (err) {
console.error(err)
}CLI Usage
CLI quickstart:
❯ ghost-inspector test execute <testId> \
--browser firefox \
--ngrokTunnel localhost:8000 \
--myVariable "some variable" \
--errorOnFailExit status control for CI systems
Under an automated build environment it makes sense to have a command return a non-success status when things are failing. By default the CLI will always return a success (0) status when executing tests or suites, however you can have the command fail for a non-passing test or suite status (--errorOnFail), a non-passing screenshot status (--errorOnScreenshotFail) or both when waiting for a result:
# exit with error code when failing
❯ ghost-inspector test execute <testId> --errorOnFail
# exit with error code when screenshot failing (will ignore `passing`)
❯ ghost-inspector test execute <testId> --errorOnScreenshotFail
# exit with error code if `passing` or `screenshotComparePassing` is `false`
❯ ghost-inspector test execute <testId> --errorOnFail --errorOnScreenshotFail