Skip to content

Commit

Permalink
Use unexpected-magicpen (FIXME: Release it properly).
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jun 21, 2016
1 parent cfbbf78 commit 1d85c44
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 232 deletions.
42 changes: 0 additions & 42 deletions lib/assertions.js
Expand Up @@ -775,48 +775,6 @@ module.exports = function (expect) {
}(subject));
});

expect.addAssertion('<Error> to have (ansi|html|text|) (message|diff) <any>', function (expect, subject, value) {
expect.errorMode = 'nested';
var format = expect.alternations[0] || 'text';
var useDiff = expect.alternations[1] === 'diff';
if (subject.isUnexpected) {
var subjectPen;
if (useDiff) {
var diff = subject.getDiff({ format: format });
if (diff) {
subjectPen = diff;
} else {
expect.fail('The UnexpectedError instance does not have a diff');
}
} else {
subjectPen = subject.getErrorMessage({ format: format });
}
var valueType = expect.argTypes[0];
if (valueType.is('magicpen')) {
expect(subjectPen, 'to equal', value);
} else if (valueType.is('function') && !valueType.is('expect.it')) {
var expectedOutput = expect.createOutput(format);
var returnValue = value.call(expectedOutput, subjectPen.toString());
if (!expectedOutput.isEmpty()) {
// If the function didn't generate any expected output, assume that it ran assertions based on the serialized message
expect(subjectPen, 'to equal', expectedOutput);
}
return returnValue;
} else {
return expect(subjectPen.toString(), 'to satisfy', value);
}
} else {
if (useDiff) {
expect.fail('Cannot get the diff from a non-Unexpected error');
}
if (format !== 'text') {
expect.fail('Cannot get the ' + format + ' representation of non-Unexpected error');
} else {
return expect(subject.message, 'to satisfy', value);
}
}
});

expect.addAssertion('<Error> to [exhaustively] satisfy <Error>', function (expect, subject, value) {
expect(subject.constructor, 'to be', value.constructor);
expect(subject, 'to have properties', expect.argTypes[0].unwrap(value));
Expand Down
99 changes: 0 additions & 99 deletions lib/styles.js
Expand Up @@ -245,105 +245,6 @@ module.exports = function (expect) {
});
});

expect.addStyle('magicPenLine', function (line, pen) {
line.forEach(function (lineEntry, j) {
if (j > 0) {
this.nl();
}
if (lineEntry.style === 'text') {
var styles = lineEntry.args.styles;
if (pen && styles.length === 1 && typeof pen[styles[0]] === 'function') {
// Text with a single style also available as a method on the pen being inspected:
this
.text('.')
.jsFunctionName(styles[0])
.text('(')
.singleQuotedString(lineEntry.args.content)
.text(')');
} else {
this
.text('.')
.jsFunctionName('text')
.text('(')
.singleQuotedString(lineEntry.args.content);
if (styles.length > 0) {
this
.text(', ')
.appendInspected(styles.length === 1 && Array.isArray(styles[0]) ? styles[0] : styles);
}
this.text(')');
}
} else if (lineEntry.style === 'raw') {
this
.text('.')
.jsFunctionName('raw')
.text('(')
.appendInspected(lineEntry.args.content())
.text(')');
} else {
// lineEntry.style === 'block'
this
.text('.')
.jsFunctionName('block').text('(').jsKeyword('function').text(' () {');
if (lineEntry.args && lineEntry.args.length > 0 && lineEntry.args[0] && lineEntry.args[0].length > 0) {
this
.nl()
.indentLines()
.i()
.magicPen(pen, lineEntry.args)
.outdentLines()
.nl();
}
this.text('})');
}
}, this);
});

expect.addStyle('magicPen', function (pen, lines) {
var isTopLevel = !lines;
lines = lines || pen.output;
this.block(function () {
if (isTopLevel) {
this.jsFunctionName('magicpen').text('(');
if (pen.format) {
this.singleQuotedString(pen.format);
}
this.text(')');
} else {
this.jsKeyword('this');
}
if (!pen.isEmpty()) {
var inspectOnMultipleLines = lines.length > 1 || lines[0].length > 1;
if (inspectOnMultipleLines) {
this
.nl()
.indentLines()
.i();
}
this.block(function () {
lines.forEach(function (line, i) {
if (i > 0) {
this.text('.').jsFunctionName('nl').text('()').nl();
}
this.magicPenLine(line, pen);
}, this);
if (!isTopLevel) {
this.text(';');
}
});
if (inspectOnMultipleLines) {
this.outdentLines();
}
}
});

// If we're at the top level of a non-empty pen compatible with the current output,
// render the output of the pen in a comment:
if (isTopLevel && !pen.isEmpty() && (pen.format === this.format || !pen.format)) {
this.sp().commentBlock(pen);
}
});

expect.addStyle('stringDiffFragment', function (ch, text, baseStyle, markUpSpecialCharacters) {
text.split(/\n/).forEach(function (line, i, lines) {
if (this.isAtStartOfLine()) {
Expand Down
24 changes: 0 additions & 24 deletions lib/types.js
Expand Up @@ -395,30 +395,6 @@ module.exports = function (expect) {
}
});

expect.addType({
name: 'magicpen',
identify: function (obj) {
return obj && obj.isMagicPen;
},
inspect: function (pen, depth, output) {
output.magicPen(pen);
},
equal: function (a, b) {
if (a.format !== b.format) {
return false;
}
if (a.format) {
// Both have the same format
return a.toString() === b.toString();
} else {
// Neither have a format, test all serializations
return a.toString() === b.toString() &&
a.toString('ansi') === b.toString('ansi') &&
a.toString('html') === b.toString('html');
}
}
});

expect.addType({
name: 'array-like',
base: 'object',
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -49,6 +49,7 @@
"rsvp": "3.0.18",
"serve": "*",
"unexpected-documentation-site-generator": "^4.0.0",
"unexpected-magicpen": "0.2.1",
"unexpected-markdown": "^1.4.0"
},
"jspm": {
Expand Down
5 changes: 5 additions & 0 deletions test/common.js
Expand Up @@ -4,6 +4,11 @@ unexpected = typeof weknowhow === 'undefined' ?
require('../lib/').clone() :
weknowhow.expect.clone();

unexpected.use(typeof weknowhow === 'undefined' ?
require('unexpected-magicpen') :
weknowhow.unexpectedMagicPen
);

unexpected.output.preferredWidth = 80;

unexpected.addAssertion('<any> to inspect as <string>', function (expect, subject, value) {
Expand Down
1 change: 1 addition & 0 deletions test/tests.tpl.html
Expand Up @@ -13,6 +13,7 @@
<script>mocha.setup('bdd')</script>

<script src="../unexpected.js"></script>
<script src="../vendor/unexpected-magicpen.min.js"></script>
<script src="common.js"></script>

<!-- test files -->
Expand Down
67 changes: 0 additions & 67 deletions test/types/magicpen-type.spec.js

This file was deleted.

1 change: 1 addition & 0 deletions vendor/unexpected-magicpen.min.js

0 comments on commit 1d85c44

Please sign in to comment.