extensions/snapshot/snapshot

Methods

(static) diff(snapshot, expected) → {string}

Compute diff between two contents. If no diff, it returns null
Source:
Parameters:
Name Type Description
snapshot string snapshot content
expected string expected content
Returns:
Type:
string
Diff message

(static) extractScenarios(file) → {Array.<string>}

Extract scenarios from a feature file
Source:
Parameters:
Name Type Description
file string Feature file path
Returns:
Type:
Array.<string>
- Scenarios names

(static) formatSnapshotFile(content) → {string}

For a snapshot file by add backticks and format it as js files with keys
Source:
Parameters:
Name Type Description
content object snapshots content
Returns:
Type:
string
formated snapshot file

(static) normalizeNewlines(string)

Normalize new lines to be \n only
Source:
Parameters:
Name Type Description
string string Content to normalize

(static) parseSnapshotFile(content) → {Object}

Extract keys / values from snapshot file
Source:
Parameters:
Name Type Description
content string Snapshot file content
Returns:
Type:
Object
- should follow the pattern {snapshot_name: snapshot_content}

(static) prefixSnapshots(scenarios) → {Object}

Create snapshots prefix that will be used for each snapshot step of a scenario For example if the scenario name is 'Scenario 1', then prefix will be 'Scenario 1 1' If then we have in the same file another scenario named 'Scenario 1', it's prefix will be 'Scenario 1 2' to avoid naming collisions Result will follow the pattern : { scenario_line: { name: scenario_name, line: scenario_line, prefix: scenario_snapshots_prefix }, scenario2_line: { name: scenario2_name, line: scenario2_line, prefix: scenario2_snapshots_prefix } ... }
Source:
Parameters:
Name Type Description
scenarios Array.<string> Scenarios names
Returns:
Type:
Object
- Read above for result format

(static) readSnapshotFile(file) → {Object}

Read a snapshot file and parse it. For each feature file, we have one snapshot file
Source:
Parameters:
Name Type Description
file string snapshot file path
Returns:
Type:
Object
- Return follows the pattern : {snapshot_name: snapshot_content}

(static) snapshotsPath(featureFile, opts)

Get snapshot file path base on feature file path
Source:
Parameters:
Name Type Description
featureFile string Feature file path
opts Object
Name Type Attributes Default Description
snaphotsDirname Object <optional>
'__snapshots__' Snapshots dirname
snapshotsFileExtension Object <optional>
'snap' Snapshots files extension

(static) wrapWithBacktick(str) → {string}

Add backticks to wrap snapshot content and replace backticks
Source:
Parameters:
Name Type Description
str string snapshot content
Returns:
Type:
string
wrapped content

(static) writeSnapshotFile(file, content)

Format and write a snapshot file content
Source:
Parameters:
Name Type Description
file string file path
content Object snapshot file content following the pattern : {snapshot_name: snapshot_content}