Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swimlane/cy-dom-diff

Package Overview
Dependencies
Maintainers
40
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swimlane/cy-dom-diff - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

3

CHANGELOG.md

@@ -9,2 +9,5 @@ CHANGELOG

## 1.0.1 (2021-02-01)
* Fixed bug causing uncaught failures in Cypress 6
## 1.0.0 (2020-10-30)

@@ -11,0 +14,0 @@ * removed `html`

28

commands.js
import { clean, disambiguateArgs, getDom } from './lib/util';
import { chaiDomMatch } from './lib/assertion';
chai.use(chaiDomMatch);
function logDiff(name, state, $el, re, options) {
const Actual = clean(getDom($el), options);
const Expected = (re === null || re === void 0 ? void 0 : re.pattern) ? re.replace(re.pattern) : re;
const Difference = (re === null || re === void 0 ? void 0 : re.diff) ? re.diff(Actual) : undefined;
const logDiff = (name, state, $el, re, options) => {
const actual = clean(getDom($el), options);
const expected = (re === null || re === void 0 ? void 0 : re.pattern) ? re.replace(re.pattern) : re;
const difference = (re === null || re === void 0 ? void 0 : re.diff) ? re.diff(actual) : undefined;
if (state === undefined) {
state = Difference === '' ? 'passed' : 'failed';
state = difference === '' ? 'passed' : 'failed';
}

@@ -19,10 +19,14 @@ Cypress.log({

return {
// eslint-disable-next-line @typescript-eslint/naming-convention
Subject: $el,
Expected,
Actual,
Difference,
// eslint-disable-next-line @typescript-eslint/naming-convention
Expected: expected,
// eslint-disable-next-line @typescript-eslint/naming-convention
Actual: actual,
// eslint-disable-next-line @typescript-eslint/naming-convention
Difference: difference,
};
},
});
}
};
Cypress.Commands.add('domDiff', { prevSubject: 'element' }, ($el, re, options) => {

@@ -37,10 +41,8 @@ logDiff('domDiff', undefined, $el, re, options);

}
return err;
};
cy.wrap(subject, options).should((el) => {
cy.on('fail', onFail);
// @ts-ignore
return cy.wrap(subject, Object.assign(Object.assign({}, options), { onFail })).should((el) => {
expect(el).domMatch(re, message, options);
cy.removeListener('fail', onFail);
logDiff('domMatch', 'passed', subject, re, options);
});
});
import { clean } from './util';
import { createPatch } from 'diff';
function escape(source) {
const escape = (source) => {
if (source instanceof RegExp)
return source.source;
return source.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
function formatPatch(text) {
};
const formatPatch = (text) => {
return text

@@ -21,3 +21,3 @@ .replace(/^([^\n]+)\n([^\n]+)\n/m, '')

.trim();
}
};
export class PatternRegExp extends RegExp {

@@ -51,3 +51,3 @@ constructor(source, pattern, matchers) {

}
export function dom(strings, ...args) {
export const dom = (strings, ...args) => {
const result = [strings[0]];

@@ -62,2 +62,2 @@ args.forEach((arg, i) => {

return new PatternRegExp(`^${source}$`, pattern, args);
}
};
import { getDiffableHTML, } from '@open-wc/semantic-dom-diff/get-diffable-html';
import unindent from 'strip-indent';
const { isJquery, isElement } = Cypress.dom;
export function getDom($el) {
export const getDom = ($el) => {
if (isJquery($el)) {

@@ -12,10 +12,10 @@ return $el.html();

return $el; // TODO: errror?
}
};
const domparser = new DOMParser();
export function clean(html, options) {
export const clean = (html, options) => {
// Create a Node using DOMParser to avoid rendering in Cypress
const doc = domparser.parseFromString(`<diff-container>${html}</diff-container>`, 'text/html');
return unindent(getDiffableHTML(doc.body.firstChild, options));
}
export function disambiguateArgs(args) {
};
export const disambiguateArgs = (args) => {
if (args.length === 2) {

@@ -27,2 +27,2 @@ return args;

: [args[0], undefined];
}
};
{
"name": "@swimlane/cy-dom-diff",
"version": "1.0.0",
"version": "1.0.1",
"description": "matching chunks of DOM against HTML; including dynamic content.",

@@ -15,10 +15,11 @@ "main": "index.js",

"scripts": {
"clean": "trash lib ./*.js",
"build": "npm run clean && tsc",
"clean": "trash lib ./command.js ./index.js",
"build": "run-s clean && run-p build:module",
"build:module": "tsc -p tsconfig.json",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"fix:tslint": "tslint --fix --project .",
"fix:tslint": "eslint -c .eslintrc.js --ext .ts ./src/ --fix",
"test": "run-s test:*",
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
"test:lint": "tslint --project .",
"test:lint": "eslint -c .eslintrc.js --ext .ts ./src/",
"test:unit": "cypress run",

@@ -41,11 +42,19 @@ "open": "cypress open",

"@types/faker": "^5.1.2",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/eslint-plugin-tslint": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"chg": "^0.4.0",
"cypress": "^5.5.0",
"cypress": "^5.6.0",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^30.7.8",
"eslint-plugin-prefer-arrow": "^1.2.2",
"eslint-plugin-prettier": "^3.1.4",
"faker": "^5.1.0",
"np": "^6.5.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"prettier": "^2.2.0",
"trash-cli": "^3.1.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.0.3"

@@ -52,0 +61,0 @@ },

@@ -13,3 +13,3 @@ import { DiffOptions } from '@open-wc/semantic-dom-diff/get-diffable-html';

function logDiff(
const logDiff = (
name: string,

@@ -20,9 +20,9 @@ state: string | undefined,

options?: Options
) {
const Actual = clean(getDom($el), options);
const Expected = re?.pattern ? re.replace(re.pattern) : re;
const Difference = re?.diff ? re.diff(Actual) : undefined;
) => {
const actual = clean(getDom($el), options);
const expected = re?.pattern ? re.replace(re.pattern) : re;
const difference = re?.diff ? re.diff(actual) : undefined;
if (state === undefined) {
state = Difference === '' ? 'passed' : 'failed';
state = difference === '' ? 'passed' : 'failed';
}

@@ -38,10 +38,14 @@

return {
// eslint-disable-next-line @typescript-eslint/naming-convention
Subject: $el,
Expected,
Actual,
Difference,
// eslint-disable-next-line @typescript-eslint/naming-convention
Expected: expected,
// eslint-disable-next-line @typescript-eslint/naming-convention
Actual: actual,
// eslint-disable-next-line @typescript-eslint/naming-convention
Difference: difference,
};
},
});
}
};

@@ -69,9 +73,7 @@ Cypress.Commands.add(

}
return err;
};
cy.wrap(subject, options).should((el: any) => {
cy.on('fail', onFail);
// @ts-ignore
return cy.wrap(subject, { ...options, onFail }).should((el: any) => {
expect(el).domMatch(re, message, options);
cy.removeListener('fail', onFail);
logDiff('domMatch', 'passed', subject, re, options);

@@ -78,0 +80,0 @@ });

import { clean } from './util';
import { createPatch } from 'diff';
function escape(source: RegExp | string) {
const escape = (source: RegExp | string) => {
if (source instanceof RegExp) return source.source;
return source.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
};
function formatPatch(text: string) {
const formatPatch = (text: string) => {
return text

@@ -22,3 +22,3 @@ .replace(/^([^\n]+)\n([^\n]+)\n/m, '')

.trim();
}
};

@@ -60,6 +60,6 @@ export class PatternRegExp extends RegExp {

export function dom(
export const dom = (
strings: TemplateStringsArray,
...args: any[]
): PatternRegExp {
): PatternRegExp => {
const result = [strings[0]];

@@ -74,2 +74,2 @@ args.forEach((arg, i) => {

return new PatternRegExp(`^${source}$`, pattern, args);
}
};

@@ -10,3 +10,3 @@ import {

export function getDom($el: any) {
export const getDom = ($el: any) => {
if (isJquery($el)) {

@@ -19,7 +19,7 @@ return $el.html();

return $el; // TODO: errror?
}
};
const domparser = new DOMParser();
export function clean(html: string, options?: DiffOptions): string {
export const clean = (html: string, options?: DiffOptions): string => {
// Create a Node using DOMParser to avoid rendering in Cypress

@@ -31,9 +31,12 @@ const doc = domparser.parseFromString(

return unindent(getDiffableHTML(doc.body.firstChild as Node, options));
}
};
export function disambiguateArgs(
args: [string | object | undefined, object | undefined]
): [string | undefined, object | undefined] {
export const disambiguateArgs = (
args: [
string | Record<string, unknown> | undefined,
Record<string, unknown> | undefined
]
): [string | undefined, Record<string, unknown> | undefined] => {
if (args.length === 2) {
return args as [string | undefined, object | undefined];
return args as [string | undefined, Record<string, unknown> | undefined];
}

@@ -43,2 +46,2 @@ return typeof args[0] === 'object'

: [args[0], undefined];
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc