├── .gitignore ├── jest-tests ├── truthy.test.js ├── true.test.js ├── false.test.js ├── before-each.test.js ├── regex.test.js ├── not-regex.test.js ├── not.test.js ├── after-each.test.js ├── deep-equal.test.js ├── not-deep-equal.test.js ├── is.test.js └── falsy.test.js ├── ava-tests ├── truthy.test.js ├── true.test.js ├── false.test.js ├── before-each.test.js ├── regex.test.js ├── not.test.js ├── not-regex.test.js ├── after-each.test.js ├── deep-equal.test.js ├── not-deep-equal.test.js ├── is.test.js └── falsy.test.js ├── src ├── remove-ava-import.js ├── utils.js ├── remove-t-parameter.js ├── replace-after-each.js ├── replace-before-each.js ├── replace-t-dot-falsy.js ├── replace-t-dot-truthy.js ├── replace-t-dot-true.js ├── replace-t-dot-false.js ├── replace-t-dot-is.js ├── replace-t-dot-regex.js ├── replace-t-dot-deep-equal.js ├── replace-t-dot-not.js ├── replace-t-dot-not-regex.js └── replace-t-dot-not-deep-equal.js ├── package.json ├── transform.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /jest-tests/truthy.test.js: -------------------------------------------------------------------------------- 1 | test('expected variable', () => { 2 | const abc = 'a' + 'b' + 'c' 3 | expect(abc).toBeTruthy() 4 | }) 5 | -------------------------------------------------------------------------------- /ava-tests/truthy.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected variable', (t) => { 4 | const abc = 'a' + 'b' + 'c' 5 | t.truthy(abc) 6 | }) 7 | -------------------------------------------------------------------------------- /jest-tests/true.test.js: -------------------------------------------------------------------------------- 1 | test('expected variable true', () => { 2 | const abc = true 3 | expect(abc).toBe(true) 4 | }) 5 | 6 | test('expected variable math calculation', () => { 7 | const abc = 2 > 1 8 | expect(abc).toBe(true) 9 | }) 10 | -------------------------------------------------------------------------------- /jest-tests/false.test.js: -------------------------------------------------------------------------------- 1 | test('expected variable false', () => { 2 | const abc = false 3 | expect(abc).toBe(false) 4 | }) 5 | 6 | test('expected variable math calculation', () => { 7 | const abc = 1 > 2 8 | expect(abc).toBe(false) 9 | }) 10 | -------------------------------------------------------------------------------- /ava-tests/true.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected variable true', (t) => { 4 | const abc = true 5 | t.true(abc) 6 | }) 7 | 8 | test('expected variable math calculation', (t) => { 9 | const abc = 2 > 1 10 | t.true(abc) 11 | }) 12 | -------------------------------------------------------------------------------- /ava-tests/false.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected variable false', (t) => { 4 | const abc = false 5 | t.false(abc) 6 | }) 7 | 8 | test('expected variable math calculation', (t) => { 9 | const abc = 1 > 2 10 | t.false(abc) 11 | }) 12 | -------------------------------------------------------------------------------- /jest-tests/before-each.test.js: -------------------------------------------------------------------------------- 1 | let count = 0 2 | 3 | beforeEach(() => { 4 | count += 1 5 | }) 6 | 7 | test('beforeEach has run', () => { 8 | expect(count).toBe(1) 9 | }) 10 | 11 | test('beforeEach has run', () => { 12 | expect(count).toBe(2) 13 | }) 14 | -------------------------------------------------------------------------------- /jest-tests/regex.test.js: -------------------------------------------------------------------------------- 1 | test('expected literal', () => { 2 | const abc = 'abc' 3 | expect(abc).toMatch(/abc/) 4 | }) 5 | 6 | test('expected variable', () => { 7 | const abc = 'a' + 'b' + 'c' 8 | const expected = /abc/ 9 | expect(abc).toMatch(expected) 10 | }) 11 | -------------------------------------------------------------------------------- /ava-tests/before-each.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | let count = 0 4 | 5 | test.beforeEach(() => { 6 | count += 1 7 | }) 8 | 9 | test('beforeEach has run', (t) => { 10 | t.is(count, 1) 11 | }) 12 | 13 | test('beforeEach has run', (t) => { 14 | t.is(count, 2) 15 | }) 16 | -------------------------------------------------------------------------------- /jest-tests/not-regex.test.js: -------------------------------------------------------------------------------- 1 | test('expected literal', () => { 2 | const abc = 'abc' 3 | expect(abc).not.toMatch(/xyz/) 4 | }) 5 | 6 | test('expected variable', () => { 7 | const abc = 'a' + 'b' + 'c' 8 | const expected = /xyz/ 9 | expect(abc).not.toMatch(expected) 10 | }) 11 | -------------------------------------------------------------------------------- /jest-tests/not.test.js: -------------------------------------------------------------------------------- 1 | test('expected literal', () => { 2 | const abc = 'a' + 'b' + 'c' 3 | expect(abc).not.toBe('xyz') 4 | }) 5 | 6 | test('expected variable', () => { 7 | const abc = 'a' + 'b' + 'c' 8 | const expected = 'xyz' 9 | expect(abc).not.toBe(expected) 10 | }) 11 | -------------------------------------------------------------------------------- /ava-tests/regex.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected literal', (t) => { 4 | const abc = 'abc' 5 | t.regex(abc, /abc/) 6 | }) 7 | 8 | test('expected variable', (t) => { 9 | const abc = 'a' + 'b' + 'c' 10 | const expected = /abc/ 11 | t.regex(abc, expected) 12 | }) 13 | -------------------------------------------------------------------------------- /ava-tests/not.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected literal', (t) => { 4 | const abc = 'a' + 'b' + 'c' 5 | t.not(abc, 'xyz') 6 | }) 7 | 8 | test('expected variable', (t) => { 9 | const abc = 'a' + 'b' + 'c' 10 | const expected = 'xyz' 11 | t.not(abc, expected) 12 | }) 13 | -------------------------------------------------------------------------------- /src/remove-ava-import.js: -------------------------------------------------------------------------------- 1 | const removeAvaImport = (j, root) => { 2 | const avaImportCall = root.find(j.ImportDeclaration, { 3 | source: { 4 | value: 'ava' 5 | } 6 | }) 7 | 8 | avaImportCall.forEach(p => { 9 | j(p).remove() 10 | }) 11 | } 12 | 13 | export default removeAvaImport -------------------------------------------------------------------------------- /ava-tests/not-regex.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected literal', (t) => { 4 | const abc = 'abc' 5 | t.notRegex(abc, /xyz/) 6 | }) 7 | 8 | test('expected variable', (t) => { 9 | const abc = 'a' + 'b' + 'c' 10 | const expected = /xyz/ 11 | t.notRegex(abc, expected) 12 | }) 13 | -------------------------------------------------------------------------------- /jest-tests/after-each.test.js: -------------------------------------------------------------------------------- 1 | let count = 0 2 | 3 | afterEach(() => { 4 | count += 1 5 | }) 6 | 7 | test('afterEach has run', () => { 8 | expect(count).toBe(0) 9 | }) 10 | 11 | test('afterEach has run', () => { 12 | expect(count).toBe(1) 13 | }) 14 | 15 | test('afterEach has run', () => { 16 | expect(count).toBe(2) 17 | }) 18 | -------------------------------------------------------------------------------- /ava-tests/after-each.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | let count = 0 4 | 5 | test.afterEach(() => { 6 | count += 1 7 | }) 8 | 9 | test('afterEach has run', (t) => { 10 | t.is(count, 0) 11 | }) 12 | 13 | test('afterEach has run', (t) => { 14 | t.is(count, 1) 15 | }) 16 | 17 | test('afterEach has run', (t) => { 18 | t.is(count, 2) 19 | }) 20 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | const getValue = (j, node) => { 2 | switch (node.type) { 3 | case 'Literal': 4 | return [j.identifier(node.raw)] 5 | case 'Identifier': 6 | return [j.identifier(node.name)] 7 | case 'ObjectExpression': 8 | return [j.objectExpression(node.properties)] 9 | } 10 | } 11 | 12 | export default { 13 | getValue 14 | } -------------------------------------------------------------------------------- /ava-tests/deep-equal.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected object literal', (t) => { 4 | const abc = { a: 'a', b: 'b', c: 'c' } 5 | t.deepEqual(abc, {a: 'a', b: 'b', c: 'c'}) 6 | }) 7 | 8 | test('expected object variable', (t) => { 9 | const abc = { a: 'a', b: 'b', c: 'c' } 10 | const expected = { a: 'a', b: 'b', c: 'c' } 11 | t.deepEqual(abc, expected) 12 | }) 13 | -------------------------------------------------------------------------------- /jest-tests/deep-equal.test.js: -------------------------------------------------------------------------------- 1 | test('expected object literal', () => { 2 | const abc = { a: 'a', b: 'b', c: 'c' } 3 | expect(abc).toEqual({ 4 | a: 'a', 5 | b: 'b', 6 | c: 'c' 7 | }) 8 | }) 9 | 10 | test('expected object variable', () => { 11 | const abc = { a: 'a', b: 'b', c: 'c' } 12 | const expected = { a: 'a', b: 'b', c: 'c' } 13 | expect(abc).toEqual(expected) 14 | }) 15 | -------------------------------------------------------------------------------- /ava-tests/not-deep-equal.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected object literal', (t) => { 4 | const abc = { a: 'a', b: 'b', c: 'c' } 5 | t.notDeepEqual(abc, {a: 'x', b: 'y', c: 'z'}) 6 | }) 7 | 8 | test('expected object variable', (t) => { 9 | const abc = { a: 'a', b: 'b', c: 'c' } 10 | const expected = { a: 'x', b: 'y', c: 'z' } 11 | t.notDeepEqual(abc, expected) 12 | }) 13 | -------------------------------------------------------------------------------- /jest-tests/not-deep-equal.test.js: -------------------------------------------------------------------------------- 1 | test('expected object literal', () => { 2 | const abc = { a: 'a', b: 'b', c: 'c' } 3 | expect(abc).not.toEqual({ 4 | a: 'x', 5 | b: 'y', 6 | c: 'z' 7 | }) 8 | }) 9 | 10 | test('expected object variable', () => { 11 | const abc = { a: 'a', b: 'b', c: 'c' } 12 | const expected = { a: 'x', b: 'y', c: 'z' } 13 | expect(abc).not.toEqual(expected) 14 | }) 15 | -------------------------------------------------------------------------------- /jest-tests/is.test.js: -------------------------------------------------------------------------------- 1 | test('expected literal', () => { 2 | const abc = 'a' + 'b' + 'c' 3 | expect(abc).toBe('abc') 4 | }) 5 | 6 | test('expected literal without arrow function parameter brackets', () => { 7 | const abc = 'a' + 'b' + 'c' 8 | expect(abc).toBe('abc') 9 | }) 10 | 11 | test('expected variable', () => { 12 | const abc = 'a' + 'b' + 'c' 13 | const expected = 'abc' 14 | expect(abc).toBe(expected) 15 | }) 16 | -------------------------------------------------------------------------------- /ava-tests/is.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected literal', (t) => { 4 | const abc = 'a' + 'b' + 'c' 5 | t.is(abc, 'abc') 6 | }) 7 | 8 | test('expected literal without arrow function parameter brackets', t => { 9 | const abc = 'a' + 'b' + 'c' 10 | t.is(abc, 'abc') 11 | }) 12 | 13 | test('expected variable', (t) => { 14 | const abc = 'a' + 'b' + 'c' 15 | const expected = 'abc' 16 | t.is(abc, expected) 17 | }) 18 | -------------------------------------------------------------------------------- /src/remove-t-parameter.js: -------------------------------------------------------------------------------- 1 | const _removeTParameter = testFunction => { 2 | testFunction.value.arguments.forEach(argument => { 3 | if (argument.type === 'ArrowFunctionExpression') { 4 | // Drop the 't' parameter for AVA's arrow function 5 | argument.params = [] 6 | } 7 | }) 8 | } 9 | 10 | const removeTParameter = (j, root) => { 11 | const testFunctions = root.find(j.CallExpression, { 12 | callee: { 13 | name: 'test' 14 | } 15 | }) 16 | testFunctions.forEach(_removeTParameter) 17 | } 18 | 19 | export default removeTParameter -------------------------------------------------------------------------------- /ava-tests/falsy.test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test('expected variable false', (t) => { 4 | const abc = false 5 | t.falsy(abc) 6 | }) 7 | 8 | test('expected variable 0', (t) => { 9 | const abc = 0 10 | t.falsy(abc) 11 | }) 12 | 13 | test('expected variable empty string', (t) => { 14 | const abc = '' 15 | t.falsy(abc) 16 | }) 17 | 18 | test('expected variable null', (t) => { 19 | const abc = null 20 | t.falsy(abc) 21 | }) 22 | 23 | test('expected variable undefined', (t) => { 24 | const abc = undefined 25 | t.falsy(abc) 26 | }) 27 | 28 | test('expected variable NaN', (t) => { 29 | const abc = NaN 30 | t.falsy(abc) 31 | }) 32 | -------------------------------------------------------------------------------- /jest-tests/falsy.test.js: -------------------------------------------------------------------------------- 1 | test('expected variable false', () => { 2 | const abc = false 3 | expect(abc).toBeFalsy() 4 | }) 5 | 6 | test('expected variable 0', () => { 7 | const abc = 0 8 | expect(abc).toBeFalsy() 9 | }) 10 | 11 | test('expected variable empty string', () => { 12 | const abc = '' 13 | expect(abc).toBeFalsy() 14 | }) 15 | 16 | test('expected variable null', () => { 17 | const abc = null 18 | expect(abc).toBeFalsy() 19 | }) 20 | 21 | test('expected variable undefined', () => { 22 | const abc = undefined 23 | expect(abc).toBeFalsy() 24 | }) 25 | 26 | test('expected variable NaN', () => { 27 | const abc = NaN 28 | expect(abc).toBeFalsy() 29 | }) 30 | -------------------------------------------------------------------------------- /src/replace-after-each.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceAfterEach = (j, root) => { 4 | const afterEach = root.find(j.MemberExpression, { 5 | object: { 6 | name: 'test' 7 | }, 8 | property: { 9 | name: 'afterEach' 10 | } 11 | }) 12 | afterEach.forEach(node => { 13 | // Get the entire 'test.afterEach([title], implementation)' expression 14 | const expression = node.parentPath 15 | const implementation = expression.value.arguments.length > 1 16 | ? expression.value.arguments[1] 17 | : expression.value.arguments[0] 18 | 19 | const newExpression = j.callExpression( 20 | j.identifier('afterEach'), 21 | [implementation] 22 | ) 23 | 24 | expression.replace(newExpression) 25 | }) 26 | } 27 | 28 | export default replaceAfterEach 29 | -------------------------------------------------------------------------------- /src/replace-before-each.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceBeforeEach = (j, root) => { 4 | const beforeEach = root.find(j.MemberExpression, { 5 | object: { 6 | name: 'test' 7 | }, 8 | property: { 9 | name: 'beforeEach' 10 | } 11 | }) 12 | beforeEach.forEach(node => { 13 | // Get the entire 'test.beforeEach([title], implementation)' expression 14 | const expression = node.parentPath 15 | const implementation = expression.value.arguments.length > 1 16 | ? expression.value.arguments[1] 17 | : expression.value.arguments[0] 18 | 19 | const newExpression = j.callExpression( 20 | j.identifier('beforeEach'), 21 | [implementation] 22 | ) 23 | 24 | expression.replace(newExpression) 25 | }) 26 | } 27 | 28 | export default replaceBeforeEach 29 | -------------------------------------------------------------------------------- /src/replace-t-dot-falsy.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotFalsy = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'falsy' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.falsy(expected)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const newExpect = j.callExpression( 17 | j.identifier('expect'), 18 | actualValue 19 | ) 20 | const newActual = j.callExpression( 21 | j.identifier('toBeFalsy'), 22 | [] 23 | ) 24 | const newExpression = j.memberExpression( 25 | newExpect, newActual 26 | ) 27 | expectationExpression.replace(newExpression) 28 | }) 29 | } 30 | 31 | export default replaceTdotFalsy -------------------------------------------------------------------------------- /src/replace-t-dot-truthy.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotTruthy = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'truthy' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.truthy(expected)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const newExpect = j.callExpression( 17 | j.identifier('expect'), 18 | actualValue 19 | ) 20 | const newActual = j.callExpression( 21 | j.identifier('toBeTruthy'), 22 | [] 23 | ) 24 | const newExpression = j.memberExpression( 25 | newExpect, newActual 26 | ) 27 | expectationExpression.replace(newExpression) 28 | }) 29 | } 30 | 31 | export default replaceTdotTruthy -------------------------------------------------------------------------------- /src/replace-t-dot-true.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotTrue = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'true' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.true(expected)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const newExpect = j.callExpression( 17 | j.identifier('expect'), 18 | actualValue 19 | ) 20 | const newActual = j.callExpression( 21 | j.identifier('toBe'), 22 | [j.identifier('true')] 23 | ) 24 | const newExpression = j.memberExpression( 25 | newExpect, newActual 26 | ) 27 | expectationExpression.replace(newExpression) 28 | }) 29 | } 30 | 31 | export default replaceTdotTrue -------------------------------------------------------------------------------- /src/replace-t-dot-false.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotFalse = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'false' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.false(expected)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const newExpect = j.callExpression( 17 | j.identifier('expect'), 18 | actualValue 19 | ) 20 | const newActual = j.callExpression( 21 | j.identifier('toBe'), 22 | [j.identifier('false')] 23 | ) 24 | const newExpression = j.memberExpression( 25 | newExpect, newActual 26 | ) 27 | expectationExpression.replace(newExpression) 28 | }) 29 | } 30 | 31 | export default replaceTdotFalse -------------------------------------------------------------------------------- /src/replace-t-dot-is.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotIs = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'is' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.is(actual, expected)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const expectedValue = utils.getValue(j, expectationExpression.value.arguments[1]) 17 | const newExpect = j.callExpression( 18 | j.identifier('expect'), 19 | actualValue 20 | ) 21 | const newActual = j.callExpression( 22 | j.identifier('toBe'), 23 | expectedValue 24 | ) 25 | const newExpression = j.memberExpression( 26 | newExpect, newActual 27 | ) 28 | expectationExpression.replace(newExpression) 29 | }) 30 | } 31 | 32 | export default replaceTdotIs -------------------------------------------------------------------------------- /src/replace-t-dot-regex.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotRegex = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'regex' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.regex(contents, regex)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const expectedValue = utils.getValue(j, expectationExpression.value.arguments[1]) 17 | const newExpect = j.callExpression( 18 | j.identifier('expect'), 19 | actualValue 20 | ) 21 | const newActual = j.callExpression( 22 | j.identifier('toMatch'), 23 | expectedValue 24 | ) 25 | const newExpression = j.memberExpression( 26 | newExpect, newActual 27 | ) 28 | expectationExpression.replace(newExpression) 29 | }) 30 | } 31 | 32 | export default replaceTdotRegex -------------------------------------------------------------------------------- /src/replace-t-dot-deep-equal.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotDeepEqual = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'deepEqual' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.deepEqual(actual, expected)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const expectedValue = utils.getValue(j, expectationExpression.value.arguments[1]) 17 | const newExpect = j.callExpression( 18 | j.identifier('expect'), 19 | actualValue 20 | ) 21 | const newActual = j.callExpression( 22 | j.identifier('toEqual'), 23 | expectedValue 24 | ) 25 | const newExpression = j.memberExpression( 26 | newExpect, newActual 27 | ) 28 | expectationExpression.replace(newExpression) 29 | }) 30 | } 31 | 32 | export default replaceTdotDeepEqual -------------------------------------------------------------------------------- /src/replace-t-dot-not.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotNot = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'not' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.not(actual, expected)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const expectedValue = utils.getValue(j, expectationExpression.value.arguments[1]) 17 | const newExpect = j.callExpression( 18 | j.identifier('expect'), 19 | actualValue 20 | ) 21 | const not = j.identifier('not') 22 | const newExpectNot = j.memberExpression( 23 | newExpect, not 24 | ) 25 | const newActual = j.callExpression( 26 | j.identifier('toBe'), 27 | expectedValue 28 | ) 29 | const newExpression = j.memberExpression( 30 | newExpectNot, newActual 31 | ) 32 | expectationExpression.replace(newExpression) 33 | }) 34 | } 35 | 36 | export default replaceTdotNot -------------------------------------------------------------------------------- /src/replace-t-dot-not-regex.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotNotRegex = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'notRegex' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.notRegex(contents, regex)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const expectedValue = utils.getValue(j, expectationExpression.value.arguments[1]) 17 | const newExpect = j.callExpression( 18 | j.identifier('expect'), 19 | actualValue 20 | ) 21 | const not = j.identifier('not') 22 | const newExpectNot = j.memberExpression( 23 | newExpect, not 24 | ) 25 | const newActual = j.callExpression( 26 | j.identifier('toMatch'), 27 | expectedValue 28 | ) 29 | const newExpression = j.memberExpression( 30 | newExpectNot, newActual 31 | ) 32 | expectationExpression.replace(newExpression) 33 | }) 34 | } 35 | 36 | export default replaceTdotNotRegex -------------------------------------------------------------------------------- /src/replace-t-dot-not-deep-equal.js: -------------------------------------------------------------------------------- 1 | import utils from './utils' 2 | 3 | const replaceTdotNotDeepEqual = (j, root) => { 4 | const tDotIs = root.find(j.MemberExpression, { 5 | object: { 6 | name: 't' 7 | }, 8 | property: { 9 | name: 'notDeepEqual' 10 | } 11 | }) 12 | tDotIs.forEach(expectation => { 13 | // Get the entire 't.notDeepEqual(actual, expected)' expression 14 | const expectationExpression = expectation.parentPath 15 | const actualValue = utils.getValue(j, expectationExpression.value.arguments[0]) 16 | const expectedValue = utils.getValue(j, expectationExpression.value.arguments[1]) 17 | const newExpect = j.callExpression( 18 | j.identifier('expect'), 19 | actualValue 20 | ) 21 | const not = j.identifier('not') 22 | const newExpectNot = j.memberExpression( 23 | newExpect, not 24 | ) 25 | const newActual = j.callExpression( 26 | j.identifier('toEqual'), 27 | expectedValue 28 | ) 29 | const newExpression = j.memberExpression( 30 | newExpectNot, newActual 31 | ) 32 | expectationExpression.replace(newExpression) 33 | }) 34 | } 35 | 36 | export default replaceTdotNotDeepEqual -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jscodeshift-ava-to-jest", 3 | "version": "0.0.2", 4 | "description": "Transforms test files from AVA to Jest", 5 | "main": "transform.js", 6 | "scripts": { 7 | "cleanJestFiles": "rm -fr jest-tests/*", 8 | "prepareTestFiles": "npm run cleanJestFiles && cp ava-tests/* jest-tests/", 9 | "test": "ava && npm run transformTests && jest", 10 | "transformTests": "npm run prepareTestFiles && jscodeshift jest-tests" 11 | }, 12 | "ava": { 13 | "files": "ava-tests/**/*.test.js" 14 | }, 15 | "jest": { 16 | "testPathDirs": [ 17 | "/jest-tests" 18 | ] 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/mikenikles/jscodeshift-ava-to-jest.git" 23 | }, 24 | "keywords": [ 25 | "ava", 26 | "jest", 27 | "codemod", 28 | "jscodeshift" 29 | ], 30 | "author": "Mike Nikles", 31 | "license": "ISC", 32 | "bugs": { 33 | "url": "https://github.com/mikenikles/jscodeshift-ava-to-jest/issues" 34 | }, 35 | "homepage": "https://github.com/mikenikles/jscodeshift-ava-to-jest#readme", 36 | "devDependencies": { 37 | "ava": "0.16.0", 38 | "jest": "15.1.1", 39 | "jscodeshift": "0.3.28" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /transform.js: -------------------------------------------------------------------------------- 1 | import removeAvaImport from './src/remove-ava-import' 2 | import removeTParameter from './src/remove-t-parameter' 3 | import replaceBeforeEach from './src/replace-before-each' 4 | import replaceAfterEach from './src/replace-after-each' 5 | import replaceTdotTruthy from './src/replace-t-dot-truthy' 6 | import replaceTdotFalsy from './src/replace-t-dot-falsy' 7 | import replaceTdotTrue from './src/replace-t-dot-true' 8 | import replaceTdotFalse from './src/replace-t-dot-false' 9 | import replaceTdotIs from './src/replace-t-dot-is' 10 | import replaceTdotNot from './src/replace-t-dot-not' 11 | import replaceTdotDeepEqual from './src/replace-t-dot-deep-equal' 12 | import replaceTdotNotDeepEqual from './src/replace-t-dot-not-deep-equal' 13 | import replaceTdotRegex from './src/replace-t-dot-regex' 14 | import replaceTdotNotRegex from './src/replace-t-dot-not-regex' 15 | 16 | const transform = (fileInfo, api, options) => { 17 | const j = api.jscodeshift; 18 | const root = j(fileInfo.source); 19 | 20 | removeAvaImport(j, root) 21 | replaceBeforeEach(j, root) 22 | replaceAfterEach(j, root) 23 | 24 | // Transform each test 25 | removeTParameter(j, root) 26 | replaceTdotTruthy(j, root) 27 | replaceTdotFalsy(j, root) 28 | replaceTdotTrue(j, root) 29 | replaceTdotFalse(j, root) 30 | replaceTdotIs(j, root) 31 | replaceTdotNot(j, root) 32 | replaceTdotDeepEqual(j, root) 33 | replaceTdotNotDeepEqual(j, root) 34 | replaceTdotRegex(j, root) 35 | replaceTdotNotRegex(j, root) 36 | 37 | return root.toSource() 38 | } 39 | 40 | export default transform 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jscodeshift-ava-to-jest 2 | 3 | A [jscodeshift](https://github.com/facebook/jscodeshift) codemod that transforms test files from [AVA](https://github.com/avajs/ava) to [Jest](https://facebook.github.io/jest/). 4 | 5 | ## Deprecation Warning 6 | 7 | I no longer maintain this package. As a great, more feature complete alternative, I recommend https://github.com/skovhus/jest-codemods. 8 | 9 | ## Install 10 | 11 | Get `jscodeshift-ava-to-jest` from [NPM](https://www.npmjs.com/package/jscodeshift-ava-to-jest) 12 | 13 | ``` 14 | npm install --save-dev jscodeshift-ava-to-jest 15 | ``` 16 | 17 | ## Usage 18 | 19 | **TBD: Explain how this module can be used in an existing project.** 20 | 21 | ## Why? 22 | 23 | It all started with [a tweet](https://twitter.com/mikenikles/status/772234132436885504), 24 | followed by [a suggestion](https://twitter.com/cpojer/status/772239240683925504) by Christoph Pojer. 25 | 26 | ## Supported AVA Assertions 27 | 28 | - [ ] [`.pass([message])`](https://github.com/avajs/ava#passmessage) 29 | - [ ] [`.fail([message])`](https://github.com/avajs/ava#failmessage) 30 | - [x] [`.truthy(value, [message])`](https://github.com/avajs/ava#truthyvalue-message) 31 | - [x] [`.falsy(value, [message])`](https://github.com/avajs/ava#falsyvalue-message) 32 | - [x] [`.true(value, [message])`](https://github.com/avajs/ava#truevalue-message) 33 | - [x] [`.false(value, [message])`](https://github.com/avajs/ava#falsevalue-message) 34 | - [x] [`.is(value, expected, [message])`](https://github.com/avajs/ava#isvalue-expected-message) 35 | - [x] [`.not(value, expected, [message])`](https://github.com/avajs/ava#notvalue-expected-message) 36 | - [x] [`.deepEqual(value, expected, [message])`](https://github.com/avajs/ava#deepequalvalue-expected-message) 37 | - [x] [`.notDeepEqual(value, expected, [message])`](https://github.com/avajs/ava#notdeepequalvalue-expected-message) 38 | - [ ] [`.throws(function|promise, [error, [message]])`](https://github.com/avajs/ava#throwsfunctionpromise-error-message) 39 | - [ ] [`.notThrows(function|promise, [message])`](https://github.com/avajs/ava#notthrowsfunctionpromise-message) 40 | - [x] [`.regex(contents, regex, [message])`](https://github.com/avajs/ava#regexcontents-regex-message) 41 | - [x] [`.notRegex(contents, regex, [message])`](https://github.com/avajs/ava#notregexcontents-regex-message) 42 | - [ ] [`.ifError(error, [message])`](https://github.com/avajs/ava#iferrorerror-message) 43 | 44 | ## Contributing 45 | 46 | ### Project structure 47 | 48 | `ava-tests`: Contains tests written in AVA. 49 | 50 | `jest-tests`: Contains **generated** Jest files. 51 | 52 | `src`: Contains `jscodeshift` helper functions. 53 | 54 | `transform.js`: The entry point for `jscodeshift`. 55 | 56 | ### Run tests 57 | 58 | `npm test`: Transforms tests from AVA to Jest. In more detail: 59 | 60 | 1. Runs `ava` on all files in `ava-tests` to make sure the AVA tests are valid. 61 | 1. Deletes all files in `jest-tests`. 62 | 1. Copies all files from `ava-tests` to `jest-tests`. 63 | 1. Runs `jscodeshift` on all files in `jest-tests`. 64 | 1. Runs `jest` on all files in `jest-tests` to make sure the Jest tests are valid. 65 | --------------------------------------------------------------------------------