-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert acceptance tests to use destroyApp().
Introduced in Ember CLI 1.13.9.
- Loading branch information
Showing
22 changed files
with
534 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
var Watson = require('../../index'); | ||
var watson = new Watson(); | ||
|
||
module.exports = { | ||
name: 'watson:use-destroy-app-helper', | ||
description: 'Use destroy-app helper after acceptance tests.', | ||
works: 'insideProject', | ||
anonymousOptions: [ | ||
'<path>' | ||
], | ||
run: function(commandOptions, rawArgs) { | ||
var path = rawArgs[0] || 'tests/acceptance'; | ||
watson.transformTestToUseDestroyApp(path); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
var isImportFor = require('./helpers/is-import-for'); | ||
var parseAst = require('../helpers/parse-ast'); | ||
var recast = require('recast'); | ||
var types = recast.types.namedTypes; | ||
var builders = recast.types.builders; | ||
|
||
var addDefaultImport = require('./helpers/add-default-import'); | ||
|
||
function isEmberCall(node) { | ||
return types.MemberExpression.check(node.callee) && | ||
node.callee.object.name === 'Ember'; | ||
} | ||
|
||
function isLegacyDestroy(node) { | ||
return types.MemberExpression.check(node.callee) && | ||
node.callee.object.name === 'Ember' && | ||
node.callee.property.name === 'run' && | ||
node.arguments[1].value === 'destroy'; | ||
} | ||
|
||
function isStartAppAssignment(node) { | ||
return types.CallExpression.check(node.right) && | ||
node.right.callee.name === 'startApp'; | ||
} | ||
|
||
module.exports = function transform(source) { | ||
var ast = parseAst(source); | ||
var appName = null; | ||
var addDestroyAppImport = false; | ||
var removeEmberImport = true; | ||
var emberImport = null; | ||
|
||
recast.visit(ast, { | ||
visitCallExpression: function(path) { | ||
var node = path.node; | ||
|
||
if(isLegacyDestroy(node)) { | ||
if (addDestroyAppImport !== true) { | ||
addDestroyAppImport = true; | ||
} | ||
|
||
path.replace(builders.callExpression( | ||
builders.identifier('destroyApp'), | ||
[appName] | ||
)); | ||
} else if (isEmberCall(node)) { | ||
removeEmberImport = false; | ||
} | ||
|
||
this.traverse(path); | ||
}, | ||
visitImportDeclaration: function(path) { | ||
if (isImportFor('ember', path.node)) { | ||
emberImport = path; | ||
} | ||
|
||
this.traverse(path); | ||
}, | ||
visitAssignmentExpression: function(path) { | ||
if (isStartAppAssignment(path.node)) { | ||
appName = path.node.left; | ||
} | ||
|
||
this.traverse(path); | ||
} | ||
}); | ||
|
||
if (addDestroyAppImport) { | ||
addDefaultImport(ast, '../helpers/destroy-app', 'destroyApp'); | ||
} | ||
|
||
if (removeEmberImport && emberImport) { | ||
emberImport.prune(); | ||
} | ||
|
||
return recast.print(ast, { tabWidth: 2, quote: 'single' }).code; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var Watson = require('../index.js'); | ||
var fs = require('fs'); | ||
var astEquality = require('./helpers/ast-equality'); | ||
var recast = require('recast'); | ||
|
||
describe('convert acceptance tests to use destroy-app helper', function() { | ||
it('makes the correct transformations - qunit', function() { | ||
var source = fs.readFileSync('./tests/fixtures/destroy-app-transform/old-default-qunit.js'); | ||
var watson = new Watson(); | ||
var newSource = watson._transformDestroyApp(source); | ||
|
||
astEquality(newSource, fs.readFileSync('./tests/fixtures/destroy-app-transform/new-default-qunit.js')); | ||
}); | ||
|
||
it('makes the correct transformations - mocha', function() { | ||
var source = fs.readFileSync('./tests/fixtures/destroy-app-transform/old-default-mocha.js'); | ||
var watson = new Watson(); | ||
var newSource = watson._transformDestroyApp(source); | ||
|
||
astEquality(newSource, fs.readFileSync('./tests/fixtures/destroy-app-transform/new-default-mocha.js')); | ||
}); | ||
|
||
it('does not remove ember import if otherwise used in test - qunit', function() { | ||
var source = fs.readFileSync('./tests/fixtures/destroy-app-transform/old-with-ember-usage-qunit.js'); | ||
var watson = new Watson(); | ||
var newSource = watson._transformDestroyApp(source); | ||
|
||
astEquality(newSource, fs.readFileSync('./tests/fixtures/destroy-app-transform/new-with-ember-usage-qunit.js')); | ||
}); | ||
|
||
it('does not remove ember import if otherwise used in test - mocha', function() { | ||
var source = fs.readFileSync('./tests/fixtures/destroy-app-transform/old-with-ember-usage-mocha.js'); | ||
var watson = new Watson(); | ||
var newSource = watson._transformDestroyApp(source); | ||
|
||
astEquality(newSource, fs.readFileSync('./tests/fixtures/destroy-app-transform/new-with-ember-usage-mocha.js')); | ||
}); | ||
|
||
it('can handle a non-standard application name - qunit', function() { | ||
var source = fs.readFileSync('./tests/fixtures/destroy-app-transform/old-crazy-app-name-qunit.js'); | ||
var watson = new Watson(); | ||
var newSource = watson._transformDestroyApp(source); | ||
|
||
astEquality(newSource, fs.readFileSync('./tests/fixtures/destroy-app-transform/new-crazy-app-name-qunit.js')); | ||
}); | ||
|
||
it('can handle a non-standard application name - mocha', function() { | ||
var source = fs.readFileSync('./tests/fixtures/destroy-app-transform/old-crazy-app-name-mocha.js'); | ||
var watson = new Watson(); | ||
var newSource = watson._transformDestroyApp(source); | ||
|
||
astEquality(newSource, fs.readFileSync('./tests/fixtures/destroy-app-transform/new-crazy-app-name-mocha.js')); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
tests/fixtures/destroy-app-transform/new-crazy-app-name-mocha.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import destroyApp from '../helpers/destroy-app'; | ||
/* jshint expr:true */ | ||
import { | ||
describe, | ||
it, | ||
beforeEach, | ||
afterEach | ||
} from 'mocha'; | ||
import { expect } from 'chai'; | ||
import startApp from '../helpers/start-app'; | ||
|
||
describe('Acceptance: Index', function() { | ||
var cahRayZeeName; | ||
|
||
beforeEach(function() { | ||
cahRayZeeName = startApp(); | ||
}); | ||
|
||
afterEach(function() { | ||
destroyApp(cahRayZeeName); | ||
}); | ||
|
||
it('can visit /index', function() { | ||
visit('/index'); | ||
|
||
andThen(function() { | ||
expect(currentPath()).to.equal('index'); | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
tests/fixtures/destroy-app-transform/new-crazy-app-name-qunit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import destroyApp from '../helpers/destroy-app'; | ||
import { module, test } from 'qunit'; | ||
import startApp from 'ember-cli-example-app-for-github/tests/helpers/start-app'; | ||
|
||
module('Acceptance | index', { | ||
beforeEach: function() { | ||
this.fooBarBazQux = startApp(); | ||
}, | ||
|
||
afterEach: function() { | ||
destroyApp(this.fooBarBazQux); | ||
} | ||
}); | ||
|
||
test('visiting /index', function(assert) { | ||
visit('/index'); | ||
|
||
andThen(function() { | ||
assert.equal(currentURL(), '/index'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import destroyApp from '../helpers/destroy-app'; | ||
/* jshint expr:true */ | ||
import { | ||
describe, | ||
it, | ||
beforeEach, | ||
afterEach | ||
} from 'mocha'; | ||
import { expect } from 'chai'; | ||
import startApp from '../helpers/start-app'; | ||
|
||
describe('Acceptance: Index', function() { | ||
var application; | ||
|
||
beforeEach(function() { | ||
application = startApp(); | ||
}); | ||
|
||
afterEach(function() { | ||
destroyApp(application); | ||
}); | ||
|
||
it('can visit /index', function() { | ||
visit('/index'); | ||
|
||
andThen(function() { | ||
expect(currentPath()).to.equal('index'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.