@freshworks/ember-codemods
Advanced tools
Comparing version 0.3.2 to 0.3.3
{ | ||
"name": "@freshworks/ember-codemods", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "test": "codemod-cli test", |
import { expect } from 'chai'; | ||
import { describe, it, context } from 'mocha'; | ||
import { describe, it, context, beforeEach, afterEach } from 'mocha'; | ||
import { setupTest, setupWindowMock, setupApplicationTest } from '@freshdesk/test-helpers'; | ||
@@ -4,0 +4,0 @@ import { faker } from 'ember-cli-mirage'; |
it('Method with return expression', function() { | ||
expect(currentURL(), 'Url page', '/url/param'); | ||
expect(find(ref)[0]); | ||
expect(find('#element')); | ||
expect(findAll('.elements').length, 1); | ||
expect('[data-test-id="selector"]'.length, 0); | ||
expect(calledSpy.calledWith(ref)); | ||
}); | ||
// Input | ||
// it('Method with return expression', function() { | ||
// expect(currentURL(), 'Url page', '/url/param'); | ||
// expect(find(ref)[0]); | ||
// expect(find('#element')); | ||
// expect(findAll('.elements').length, 1); | ||
// expect('[data-test-id="selector"]'.length, 0); | ||
// expect(calledSpy.calledWith(ref)); | ||
// }); | ||
// Output | ||
// test('Method with return expression', function(assert) { | ||
// assert.equal(currentURL(), '/url/param', 'Url page'); | ||
// assert.ok(find(ref)[0]); | ||
// assert.ok(find('#element')); | ||
// assert.equal(findAll('.elements').length, 1); | ||
// assert.equal('[data-test-id="selector"]'.length, 0); | ||
// assert.ok(calledSpy.calledWith(ref)); | ||
// }); |
test('Method with return expression', function(assert) { | ||
expect(currentURL(), 'Url page', '/url/param'); | ||
assert.equal(currentURL(), '/url/param', 'Url page'); | ||
assert.ok(find(ref)[0]); | ||
assert.ok(find('#element')); | ||
assert.equal(findAll('.elements').length, 1); | ||
assert.equal('[data-test-id="selector"]'.length, 0); | ||
assert.ok(calledSpy.calledWith(ref)); | ||
}); | ||
// Input | ||
// it('Method with return expression', function() { | ||
// expect(currentURL(), 'Url page', '/url/param'); | ||
// expect(find(ref)[0]); | ||
// expect(find('#element')); | ||
// expect(findAll('.elements').length, 1); | ||
// expect('[data-test-id="selector"]'.length, 0); | ||
// expect(calledSpy.calledWith(ref)); | ||
// }); | ||
// Output | ||
// test('Method with return expression', function(assert) { | ||
// assert.equal(currentURL(), '/url/param', 'Url page'); | ||
// assert.ok(find(ref)[0]); | ||
// assert.ok(find('#element')); | ||
// assert.equal(findAll('.elements').length, 1); | ||
// assert.equal('[data-test-id="selector"]'.length, 0); | ||
// assert.ok(calledSpy.calledWith(ref)); | ||
// }); |
@@ -50,5 +50,9 @@ // Playground | ||
renameImports(renameImportImports, root, j); | ||
// transformer for moving it.skip, describe.skip, module.skip => skip and nested children to have skip | ||
transformSkippedTests(j, root); | ||
// Remove from beforeEach, afterEach mocha import etc. | ||
removeMochaImports(callbackHooks, j, root); | ||
root.find(j.FunctionExpression) | ||
@@ -98,2 +102,12 @@ .filter((path) => path.parent.node.callee && ['test', 'skip'].includes(path.parent.node.callee.name)) | ||
function removeMochaImports(callbackHooks, j, root) { | ||
callbackHooks.forEach((name) => { | ||
root.find(j.ImportSpecifier, { | ||
imported: { | ||
name | ||
} | ||
}).remove(); | ||
}); | ||
} | ||
function importSkip(root, j, name) { | ||
@@ -204,9 +218,10 @@ root.find(j.ImportDeclaration, { | ||
.forEach(({ name, matcher, transformer }) => { | ||
if (specialException(expression)) { | ||
console.log(` | ||
You may have test with bad assertions!!! | ||
Check if you are having an expect without an assertion | ||
`); | ||
throw BreakException; | ||
} else if (matcher(expression, path, j, root)) { | ||
// if (specialException(expression)) { | ||
// console.log(` | ||
// You may have test with bad assertions!!! | ||
// Check if you are having an expect without an assertion | ||
// `); | ||
// throw BreakException; | ||
// } else | ||
if (matcher(expression, path, j, root)) { | ||
matchedExpression = transformer(expression, path, j, root, BreakException); | ||
@@ -213,0 +228,0 @@ throw BreakException; |
const { hasValue, joinParams, extractExpect, constructDomExists, constructDomAssertions, findIdentifier } = require('./utils'); | ||
module.exports = [{ | ||
// This specific tranform is only applicable for the Freshdesk code base. | ||
// We need to remove this when given outside. or have it as part of a seperate transform statement | ||
name: 'expected-plain', | ||
matcher: function (expression, path, j) { | ||
return (expression.callee && expression.callee.name === 'expect'); | ||
}, | ||
transformer: function(expression, path, j) { | ||
var { | ||
assertArguments, | ||
assertArgument, | ||
assertMessage, | ||
assertArgumentSource | ||
} = extractExpect(path, j); | ||
var assertMethod = '', params = ''; | ||
if (assertArguments.length > 1) { | ||
let expectedValue = (assertArguments.length === 3) ? assertArguments[2] : ''; | ||
assertMethod = 'equal'; | ||
params = joinParams(assertArgumentSource, j(expectedValue).toSource(), assertMessage); | ||
} else { | ||
assertMethod = 'ok'; | ||
params = joinParams(assertArgumentSource); | ||
} | ||
return `assert.${assertMethod}(${params});`; | ||
} | ||
}, { | ||
name: 'expected-true-or-false', | ||
@@ -5,0 +32,0 @@ /* expect() |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
322746
71
2430
1