# metadata-regression-testing

> 🔄 Metadata Regression Testing Tool 🔄

Latest version **1.2.1** (published 2018-06-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install metadata-regression-testing
pnpm add metadata-regression-testing
yarn add metadata-regression-testing
bun add metadata-regression-testing
```

Provides the command `mrt`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2018-06-26 |
| First published | 2018-01-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.2.0 |
| Dependencies | 8 |
| Unpacked size | 5.5 MB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 6 |
| Author | “Dimitri Harding |
| Maintainers | dimitriharding |
| Keywords | metadata, regression, testing, html, meta, tag |

## Links

- npm: https://www.npmjs.com/package/metadata-regression-testing
- Repository: https://github.com/dimitriharding/metadata-regression-testing
- Homepage: https://github.com/dimitriharding/metadata-regression-testing#readme
- Issues: https://github.com/dimitriharding/metadata-regression-testing/issues
- npm.io page: https://npm.io/package/metadata-regression-testing

## Dependencies (8)

- [xa](https://npm.io/package/xa.md) ^1.0.6
- [pug](https://npm.io/package/pug.md) ^2.0.3
- [meow](https://npm.io/package/meow.md) ^4.0.0
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [moment](https://npm.io/package/moment.md) ^2.22.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^5.0.0
- [json-diff](https://npm.io/package/json-diff.md) ^0.5.2
- [html-metadata](https://npm.io/package/html-metadata.md) ^1.6.3

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2018-06-26
- 1.2.0 — 2018-06-08
- 1.1.1 — 2018-05-25
- 1.1.0 — 2018-05-25
- 1.0.0 — 2018-05-23
- 0.2.1 — 2018-02-02
- 0.2.0 — 2018-01-29
- 0.1.1 — 2018-01-15
- 0.1.0 — 2018-01-15

## README

<p align="center">
  <img src="https://raw.githubusercontent.com/dimitriharding/metadata-regression-testing/master/media/logo.png" alt="MRT - Metadata Regression Testing" width="50%">
</p>

> Simple HTML Metadata Regression Testing Tool  [Usage](https://github.com/dimitriharding/metadata-regression-testing#usage) | [API](https://github.com/dimitriharding/metadata-regression-testing#api) | [CLI](https://github.com/dimitriharding/metadata-regression-testing#cli) | [Reporter](https://github.com/dimitriharding/metadata-regression-testing#reporter)

[![Build Status](https://travis-ci.org/dimitriharding/metadata-regression-testing.svg?branch=master)](https://travis-ci.org/dimitriharding/metadata-regression-testing)
[![Coverage Status](https://coveralls.io/repos/github/dimitriharding/metadata-regression-testing/badge.svg?branch=master)](https://coveralls.io/github/dimitriharding/metadata-regression-testing?branch=master)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fdimitriharding%2Fmetadata-regression-testing.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fdimitriharding%2Fmetadata-regression-testing?ref=badge_shield)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)


Useful for when you want to ensure that metadata remains the same for a certain page. 
>HTML metadata is important and this tool aims to help ensure that existing metadata 
remains the same throughout different scenarios where its data can be removed or edited. 
Since viewing page source can be such an eye swore and there is the chance of you missing the 
small details. MRT (metadata-regression-testing) will scrape your metadata and show the difference if any is found overtime. 

## Install

```
$ npm install --save metadata-regression-testing
```

## Usage
```js
const { mrt } = require('metadata-regression-testing');
const opts = {};

mrt(opts, 'https://github.com').then(isExpected => {
    console.log(isExpected)
    //=> true
    //   See ./tests/metadata-regression/expected/_homepage.json
});

opts.path = 'tests/updated';
opts.keysOnly = true;

mrt(opts, 'https://www.google.com', 'https://github.com').then(isExpected => {
    console.log(isExpected)
    //=> false
    //   See ./tests/updated/diffs/www.google.com_VS_github.com_homepage.json
    //   Check console for differences between google and github metadata keys (example only)
});
```

*Note*: Files are generated in the following folder structure vy default (override is possible).
```
project_folder
|_ tests/
    |_metadata-regression/
        |_actual/
        |   *.json
        |_diffs/
        |   *.txt
        |_expected/
            *.json
```

## API
<a name="mrt"></a>

## mrt(opts, testUrl, [refUrl]) ⇒ <code>Boolean</code>
Scrapes given URL/s for HTML metadata and performs a regression test

**Returns**: <code>Boolean</code> - whether or not a match was found

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| opts | <code>Object</code> |  | JSON object with desired options |
| [opts.path] | <code>String</code> | <code>&#x27;tests/metadata-regression&#x27;</code> | If defined, data files will be stored at dir |
| [opts.keysOnly] | <code>Boolean</code> | <code>false</code> | If set to true, values will not be asserted |
| testUrl | <code>String</code> |  | Web page endpoint to scrape metadata from and test |
| [refUrl] | <code>String</code> |  | Web page endpoint to use as reference for the metadata |

## CLI
```console
$   npm install metadata-regression-testing -g
$   mrt --help

    Usage
        $ mrt <testUrl> [refUrl]

        Options
        --keys-only, -k   Only compare keys in metadata object
        --diff-board, -b  Generates an HTML report to view results
        --path, -p        Defines where the data/results should be stored


        Examples
        $ mrt https://mrtoverflow.com
        
        $ mrt https://mrtoverflow.com --keys-only
        
        $ mrt https://qa-mrtoverflow.com https://dev-mrtoverflow.com
        
        $ mrt https://qa-mrtoverflow.com https://dev-mrtoverflow.com --keys-only
```

### Console examples
<img align="left" src="./media/diffinconsole.png" alt="MRT diff output in console" width="47%"/>
<img align="right" src="./media/diffandsuccessinconsole.png" alt="MRT diff and success output in console" width="47%"/>

![First Run Terminal Output](https://raw.githubusercontent.com/dimitriharding/metadata-regression-testing/master/media/first_run_mrt.png)

## Reporter

Diffboard is a HTML report that helps to visualize tests so issues can be easily spotted outside of the console. 

### Features
<img align="right" src="./media/diffboard.png" alt="Diffboard Report for MRT" width="50%" />

* Diff highlighting
* Hide/Show unwanted tabs for falied tests
* Different view types for failed tests
* Filters/Search to only display the tests you want
* Offline viewing

This reporter is best used in the `after` hook of the test runner. The path to the reporter will be printed in the console. 

### Available Options
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | <code>Object</code> |  |  |
| [options.diffboardTitle] | <code>String</code> | <code>&#x27;Diffboard&#x27;</code> | The name that will be displayed in the header |
| [options.path] | <code>String</code> | <code>MRT defualt path</code> | Dir of results created by MRT |
| [options.filename] | <code>String</code> | <code>&#x27;diffboard&#x27;</code> | Filename of saved report </br> <em>Applies to the generated html and json files.</em> |

## Tests

`npm test`

## Additional Info

This is not a test runner, it only returns a value that can be asserted within a test runner of your choice ([ava](https://github.com/avajs/ava), [mocha](https://github.com/mochajs/mocha), etc.). 

It automatically creates an expected JSON on the first run of any URL. These JSON files are named based on the URL path after the domain. A `_homepage` file is created from the homepage whether or not `/` is added to the domain. 

Review [html-metadata](https://github.com/wikimedia/html-metadata) to see what is being scrapped. 

## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fdimitriharding%2Fmetadata-regression-testing.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fdimitriharding%2Fmetadata-regression-testing?ref=badge_large)

---
_Source: https://npm.io/package/metadata-regression-testing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
