Skip to content

Commit

Permalink
prettier --write '**/*.{js,json,md}'
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Nov 22, 2020
1 parent 78e0ab3 commit 783e739
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"reporter": "spec",
"recursive": true,
"require": ["./bootstrap-unexpected-markdown", "unexpected-markdown"]
}
}
221 changes: 112 additions & 109 deletions lib/unexpectedMessy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,129 +1066,132 @@ module.exports = {
}
);

expect.exportAssertion('<messyRequestLine> to satisfy <string>', function (
expect,
subject,
value
) {
return expect(
subject,
'to [exhaustively] satisfy',
omitUndefinedProperties(
_.pick(new messy.RequestLine(value), messy.RequestLine.propertyNames)
)
);
});
expect.exportAssertion(
'<messyRequestLine> to satisfy <string>',
function (expect, subject, value) {
return expect(
subject,
'to [exhaustively] satisfy',
omitUndefinedProperties(
_.pick(
new messy.RequestLine(value),
messy.RequestLine.propertyNames
)
)
);
}
);

expect.exportAssertion('<messyRequestLine> to satisfy <object>', function (
expect,
subject,
value
) {
var promiseByKey = {};
Object.keys(value).forEach(function (key) {
promiseByKey[key] = expect.promise(function () {
if (key === 'query') {
var queryStr = subject.query;
if (
value.query &&
(typeof value.query === 'object' ||
typeof value.query === 'function')
) {
return expect(qs.parse(queryStr), 'to satisfy', value.query);
} else if (typeof value.query === 'undefined') {
expect(queryStr, 'to equal', '');
expect.exportAssertion(
'<messyRequestLine> to satisfy <object>',
function (expect, subject, value) {
var promiseByKey = {};
Object.keys(value).forEach(function (key) {
promiseByKey[key] = expect.promise(function () {
if (key === 'query') {
var queryStr = subject.query;
if (
value.query &&
(typeof value.query === 'object' ||
typeof value.query === 'function')
) {
return expect(qs.parse(queryStr), 'to satisfy', value.query);
} else if (typeof value.query === 'undefined') {
expect(queryStr, 'to equal', '');
} else {
return expect(queryStr, 'to equal', value.query);
}
} else {
return expect(queryStr, 'to equal', value.query);
return expect(subject[key], 'to satisfy', value[key]);
}
} else {
return expect(subject[key], 'to satisfy', value[key]);
}
});
});
});
return expect.promise.all(promiseByKey).caught(function () {
return expect.promise.settle(promiseByKey).then(function () {
expect.fail({
diff: function (output, diff, inspect, equal) {
if (typeof value !== 'object') {
value = new messy.RequestLine(value);
}
output.appendInspected(subject);
var error = output.clone().annotationBlock(function () {
if (
messy.RequestLine.propertyNames.some(function (propertyName) {
var type = typeof value[propertyName];
return (
type === 'function' ||
type === 'object' ||
isRegExp(value[propertyName])
);
})
) {
// Complex case: At least one property matched against an expect.it or regexp.
// Render the failing properties one by one, along with the associated diffs (if available):
Object.keys(promiseByKey).forEach(function (propertyName) {
var promise = promiseByKey[propertyName];
var error =
promise && promise.isRejected() && promise.reason();
if (error) {
this.error(propertyName).sp();
return expect.promise.all(promiseByKey).caught(function () {
return expect.promise.settle(promiseByKey).then(function () {
expect.fail({
diff: function (output, diff, inspect, equal) {
if (typeof value !== 'object') {
value = new messy.RequestLine(value);
}
output.appendInspected(subject);
var error = output.clone().annotationBlock(function () {
if (
messy.RequestLine.propertyNames.some(function (
propertyName
) {
var type = typeof value[propertyName];
if (
return (
type === 'function' ||
type === 'object' ||
isRegExp(value[propertyName])
) {
this.error('should satisfy')
.sp()
.appendInspected(value[propertyName]);
var diff = error.getDiff(output);
if (diff) {
this.nl(2).append(diff);
);
})
) {
// Complex case: At least one property matched against an expect.it or regexp.
// Render the failing properties one by one, along with the associated diffs (if available):
Object.keys(promiseByKey).forEach(function (propertyName) {
var promise = promiseByKey[propertyName];
var error =
promise && promise.isRejected() && promise.reason();
if (error) {
this.error(propertyName).sp();
var type = typeof value[propertyName];
if (
type === 'function' ||
type === 'object' ||
isRegExp(value[propertyName])
) {
this.error('should satisfy')
.sp()
.appendInspected(value[propertyName]);
var diff = error.getDiff(output);
if (diff) {
this.nl(2).append(diff);
}
} else {
this.error('should be')
.sp()
.appendInspected(value[propertyName]);
}
} else {
this.error('should be')
.sp()
.appendInspected(value[propertyName]);
}
}
}, this);
}, this);
} else {
// Simple case, render a regular diff
var shouldBeRequestLine = new messy.RequestLine(value);
this.error('should be')
.sp()
.append(inspect(shouldBeRequestLine))
.nl(2)
.append(
diff(
subject.toString(),
_.defaults(
shouldBeRequestLine.clone(),
_.pick(
subject,
messy.RequestLine.nonComputedPropertyNames
)
).toString()
)
);
}
});
if (
error.size().width + output.size().width + 1 >
output.preferredWidth
) {
output.nl();
} else {
// Simple case, render a regular diff
var shouldBeRequestLine = new messy.RequestLine(value);
this.error('should be')
.sp()
.append(inspect(shouldBeRequestLine))
.nl(2)
.append(
diff(
subject.toString(),
_.defaults(
shouldBeRequestLine.clone(),
_.pick(
subject,
messy.RequestLine.nonComputedPropertyNames
)
).toString()
)
);
output.sp();
}
});
if (
error.size().width + output.size().width + 1 >
output.preferredWidth
) {
output.nl();
} else {
output.sp();
}
output.append(error);
return output;
},
output.append(error);
return output;
},
});
});
});
});
});
}
);

expect.exportType({
name: 'messyHttpRequest',
Expand Down
81 changes: 41 additions & 40 deletions test/unexpectedMessy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,48 @@ describe('unexpected-messy', function () {
var expect = unexpected
.clone()
.use(require('../lib/unexpectedMessy'))
.addAssertion('<array> to produce a diff of <string>', function (
expect,
subject,
value
) {
expect.errorMode = 'bubble';
expect(expect.diff(subject[0], subject[1]).toString(), 'to equal', value);
})
.addAssertion('<any> to inspect as <string>', function (
expect,
subject,
value
) {
expect.errorMode = 'bubble';
expect(expect.inspect(subject).toString(), 'to equal', value);
})
.addAssertion('<any> when delayed a little bit <assertion>', function (
expect,
subject
) {
return expect.promise(function (run) {
setTimeout(
run(function () {
return expect.shift(subject);
}),
1
.addAssertion(
'<array> to produce a diff of <string>',
function (expect, subject, value) {
expect.errorMode = 'bubble';
expect(
expect.diff(subject[0], subject[1]).toString(),
'to equal',
value
);
});
})
.addAssertion('<Error> 2 have message <string>', function (
expect,
subject,
value
) {
expect.errorMode = 'nested';
expect(
subject._isUnexpected ? subject.output.toString() : subject.message,
'to equal',
value
);
});
}
)
.addAssertion(
'<any> to inspect as <string>',
function (expect, subject, value) {
expect.errorMode = 'bubble';
expect(expect.inspect(subject).toString(), 'to equal', value);
}
)
.addAssertion(
'<any> when delayed a little bit <assertion>',
function (expect, subject) {
return expect.promise(function (run) {
setTimeout(
run(function () {
return expect.shift(subject);
}),
1
);
});
}
)
.addAssertion(
'<Error> 2 have message <string>',
function (expect, subject, value) {
expect.errorMode = 'nested';
expect(
subject._isUnexpected ? subject.output.toString() : subject.message,
'to equal',
value
);
}
);

expect.output.preferredWidth = 80;

Expand Down

0 comments on commit 783e739

Please sign in to comment.