Permalink
Browse files

Add in expect assertion cases (#25)

* Add in expect assertion cases

* Remove unsupported

* Rename to plan case
  • Loading branch information...
1 parent 7ab2359 commit cc47c14e8d7257f951dc44a051752812c448cd02 @browniefed browniefed committed with Dec 15, 2016
Showing with 24 additions and 19 deletions.
  1. +0 −2 README.md
  2. +10 −1 src/transformers/ava.js
  3. +2 −12 src/transformers/ava.test.js
  4. +10 −1 src/transformers/tape.js
  5. +2 −3 src/transformers/tape.test.js
View
@@ -94,7 +94,6 @@ Usage of `proxyquire` is replaced with Jest mocks.
Warnings for unsupported AVA features:
- `t.skip`
- - `t.plan`
Warnings for unsupported Tape features:
- `t.timeoutAfter`
@@ -105,7 +104,6 @@ Warnings for unsupported Tape features:
- `t.notLooseEqual`
- `t.notLooseEquals`
- `t.skip`
- - `t.plan`
- `test.createStream`
- `test.onFinish`
@@ -17,6 +17,7 @@ import proxyquireTransformer from '../utils/proxyquire';
const SPECIAL_THROWS_CASE = '(special throws case)';
const SPECIAL_BOOL = '(special bool case)';
+const SPECIAL_PLAN_CASE = '(special plan case)';
const tPropertiesMap = {
ok: 'toBeTruthy',
@@ -37,6 +38,7 @@ const tPropertiesMap = {
notRegex: 'not.toMatch',
ifError: 'toBeFalsy',
error: 'toBeFalsy',
+ plan: SPECIAL_PLAN_CASE,
};
const tPropertiesNotMapped = new Set([
@@ -84,7 +86,6 @@ export default function avaToJest(fileInfo, api) {
const args = p.node.arguments;
const oldPropertyName = p.value.callee.property.name;
const newPropertyName = tPropertiesMap[oldPropertyName];
-
if (typeof newPropertyName === 'undefined') {
logWarning(`"t.${oldPropertyName}" is currently not supported`, p);
return null;
@@ -96,6 +97,14 @@ export default function avaToJest(fileInfo, api) {
j.identifier('toBe'),
[j.identifier(oldPropertyName)]
);
+ } else if (newPropertyName === SPECIAL_PLAN_CASE) {
+ const condition = (
+ j.memberExpression(
+ j.identifier('expect'),
+ j.callExpression(j.identifier('assertions'), [args[0]])
+ )
+ );
+ return j(p).replaceWith(condition);
} else if (newPropertyName === SPECIAL_THROWS_CASE) {
if (args.length === 1) {
newCondition = j.callExpression(
@@ -66,6 +66,7 @@ test('mapping', (t) => {
t.regex(abc, /abc/)
t.ifError(abc)
t.error(abc)
+ t.plan(3)
})
`,
`
@@ -93,6 +94,7 @@ it('mapping', () => {
expect(abc).toMatch(/abc/)
expect(abc).toBeFalsy()
expect(abc).toBeFalsy()
+ expect.assertions(3)
});
`);
@@ -302,18 +304,6 @@ test('not supported warnings: skipping test setup/teardown hooks', () => {
]);
});
-test('not supported warnings: t.plan', () => {
- wrappedPlugin(`
- import test from 'ava';
- test(t => {
- t.plan(1);
- });
- `);
- expect(consoleWarnings).toEqual([
- 'jest-codemods warning: (test.js line 4) "t.plan" is currently not supported',
- ]);
-});
-
test('not supported warnings: unmapped t property', () => {
wrappedPlugin(`
import test from 'ava';
@@ -12,6 +12,7 @@ import logger from '../utils/logger';
import proxyquireTransformer from '../utils/proxyquire';
const SPECIAL_THROWS_CASE = '(special throws case)';
+const SPECIAL_PLAN_CASE = '(special plan case)';
const tPropertiesMap = {
ok: 'toBeTruthy',
@@ -57,6 +58,7 @@ const tPropertiesMap = {
throws: SPECIAL_THROWS_CASE,
doesNotThrow: SPECIAL_THROWS_CASE,
+ plan: SPECIAL_PLAN_CASE,
};
const tPropertiesNotMapped = new Set([
@@ -78,7 +80,6 @@ const tPropertiesUnsupported = new Set([
'notLooseEquals',
'skip',
- 'plan',
]);
const unsupportedTestFunctionProperties = new Set([
@@ -166,6 +167,14 @@ export default function tapeToJest(fileInfo, api) {
[args[1]]
);
}
+ } else if (newPropertyName === SPECIAL_PLAN_CASE) {
+ const condition = (
+ j.memberExpression(
+ j.identifier('expect'),
+ j.callExpression(j.identifier('assertions'), [args[0]])
+ )
+ );
+ return j(p).replaceWith(condition);
} else {
const hasSecondArgument = PROP_WITH_SECONDS_ARGS.indexOf(newPropertyName) >= 0;
const conditionArgs = hasSecondArgument ? [args[1]] : [];
@@ -102,6 +102,7 @@ test((t) => {
t.isInequivalent(1, 2, 'msg');
// t.skip('msg');
+ t.plan(3);
t.throws(1, 'msg');
t.doesNotThrow(1, 'msg');
t.comment('this is a comment...');
@@ -152,6 +153,7 @@ it(done => {
expect(1).not.toEqual(2);
// t.skip('msg');
+ expect.assertions(3);
expect(1).toThrow();
expect(1).not.toThrow();
console.log('this is a comment...');
@@ -449,7 +451,4 @@ test('graciously warns about unknown destructured assertions', () => {
plan('msg');
});
`);
- expect(consoleWarnings).toEqual([
- 'jest-codemods warning: (test.js) "t.plan" is currently not supported',
- ]);
});

0 comments on commit cc47c14

Please sign in to comment.