-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
474be00
commit e60117d
Showing
7 changed files
with
255 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { Klass } from 'klassy'; | ||
import { _setupAJAXHooks, _teardownAJAXHooks } from './wait'; | ||
import { setContext, unsetContext } from './test-context'; | ||
|
||
import Ember from 'ember'; | ||
|
||
export default Klass.extend({ | ||
init(description, options) { | ||
this.description = description; | ||
this.callbacks = options || {}; | ||
|
||
this.initSetupSteps(); | ||
this.initTeardownSteps(); | ||
}, | ||
|
||
setup(assert) { | ||
return this.invokeSteps(this.setupSteps, this, assert).then(() => { | ||
this.contextualizeCallbacks(); | ||
return this.invokeSteps(this.contextualizedSetupSteps, this.context, assert); | ||
}); | ||
}, | ||
|
||
teardown(assert) { | ||
return this.invokeSteps(this.contextualizedTeardownSteps, this.context, assert).then(() => { | ||
return this.invokeSteps(this.teardownSteps, this, assert); | ||
}).then(() => { | ||
this.cache = null; | ||
this.cachedCalls = null; | ||
}); | ||
}, | ||
|
||
initSetupSteps() { | ||
this.setupSteps = []; | ||
this.contextualizedSetupSteps = []; | ||
|
||
if (this.callbacks.beforeSetup) { | ||
this.setupSteps.push( this.callbacks.beforeSetup ); | ||
delete this.callbacks.beforeSetup; | ||
} | ||
|
||
this.setupSteps.push(this.setupContext); | ||
this.setupSteps.push(this.setupTestElements); | ||
this.setupSteps.push(this.setupAJAXListeners); | ||
|
||
if (this.callbacks.setup) { | ||
this.contextualizedSetupSteps.push( this.callbacks.setup ); | ||
delete this.callbacks.setup; | ||
} | ||
}, | ||
|
||
invokeSteps(steps, context, assert) { | ||
steps = steps.slice(); | ||
|
||
function nextStep() { | ||
var step = steps.shift(); | ||
if (step) { | ||
// guard against exceptions, for example missing components referenced from needs. | ||
return new Ember.RSVP.Promise((resolve) => { | ||
resolve(step.call(context, assert)); | ||
}).then(nextStep); | ||
} else { | ||
return Ember.RSVP.resolve(); | ||
} | ||
} | ||
return nextStep(); | ||
}, | ||
|
||
contextualizeCallbacks() { | ||
|
||
}, | ||
|
||
initTeardownSteps() { | ||
this.teardownSteps = []; | ||
this.contextualizedTeardownSteps = []; | ||
|
||
if (this.callbacks.teardown) { | ||
this.contextualizedTeardownSteps.push( this.callbacks.teardown ); | ||
delete this.callbacks.teardown; | ||
} | ||
|
||
this.teardownSteps.push(this.teardownContext); | ||
this.teardownSteps.push(this.teardownTestElements); | ||
this.teardownSteps.push(this.teardownAJAXListeners); | ||
|
||
if (this.callbacks.afterTeardown) { | ||
this.teardownSteps.push( this.callbacks.afterTeardown ); | ||
delete this.callbacks.afterTeardown; | ||
} | ||
}, | ||
|
||
setupTestElements() { | ||
if (Ember.$('#ember-testing').length === 0) { | ||
Ember.$('<div id="ember-testing"/>').appendTo(document.body); | ||
} | ||
}, | ||
|
||
setupContext(options) { | ||
var config = Ember.merge({ | ||
dispatcher: null, | ||
inject: {} | ||
}, options); | ||
|
||
setContext(config); | ||
}, | ||
|
||
setupAJAXListeners() { | ||
_setupAJAXHooks(); | ||
}, | ||
|
||
teardownAJAXListeners() { | ||
_teardownAJAXHooks(); | ||
}, | ||
|
||
teardownTestElements() { | ||
Ember.$('#ember-testing').empty(); | ||
|
||
// Ember 2.0.0 removed Ember.View as public API, so only do this when | ||
// Ember.View is present | ||
if (Ember.View && Ember.View.views) { | ||
Ember.View.views = {}; | ||
} | ||
}, | ||
|
||
teardownContext() { | ||
var context = this.context; | ||
this.context = undefined; | ||
unsetContext(); | ||
|
||
if (context && context.dispatcher && !context.dispatcher.isDestroyed) { | ||
Ember.run(function() { | ||
context.dispatcher.destroy(); | ||
}); | ||
} | ||
} | ||
}); |
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 AbstractTestModule from './abstract-test-module'; | ||
import Ember from 'ember'; | ||
import { getContext } from './test-context'; | ||
|
||
export default AbstractTestModule.extend({ | ||
setupContext() { | ||
this._super({ application: this.createApplication() }); | ||
}, | ||
|
||
teardownContext() { | ||
Ember.run(() => { | ||
getContext().application.destroy(); | ||
}); | ||
|
||
this._super(); | ||
}, | ||
|
||
createApplication() { | ||
let { Application, config } = this.callbacks; | ||
let application; | ||
|
||
Ember.run(() => { | ||
application = Application.create(config); | ||
application.setupForTesting(); | ||
application.injectTestHelpers(); | ||
}); | ||
|
||
return application; | ||
} | ||
}); |
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,72 @@ | ||
import Ember from 'ember'; | ||
import { TestModuleForAcceptance } from 'ember-test-helpers'; | ||
import test from 'tests/test-support/qunit-test'; | ||
import qunitModuleFor from 'tests/test-support/qunit-module-for'; | ||
import Resolver, { setResolverRegistry } from 'tests/test-support/resolver'; | ||
import { getContext } from 'ember-test-helpers/test-context'; | ||
|
||
function moduleForAcceptance(description, callbacks) { | ||
qunitModuleFor(new TestModuleForAcceptance(description, callbacks)); | ||
} | ||
|
||
let Application = Ember.Application.extend({ | ||
rootElement: '#ember-testing', | ||
Resolver | ||
}); | ||
|
||
moduleForAcceptance('TestModuleForAcceptance | Lifecycle', { | ||
Application, | ||
|
||
beforeSetup(assert) { | ||
assert.expect(6); | ||
assert.strictEqual(getContext(), undefined); | ||
|
||
setResolverRegistry({ | ||
'router:main': Ember.Router.extend({ location: 'none' }) | ||
}); | ||
}, | ||
|
||
setup(assert) { | ||
assert.ok(getContext().application instanceof Ember.Application); | ||
}, | ||
|
||
teardown(assert) { | ||
assert.ok(getContext().application instanceof Ember.Application); | ||
}, | ||
|
||
afterTeardown(assert) { | ||
assert.strictEqual(getContext(), undefined); | ||
assert.strictEqual(Ember.$('#ember-testing').children().length, 0); | ||
} | ||
}); | ||
|
||
test('Lifecycle is correct', function() { | ||
ok(true); | ||
}); | ||
|
||
moduleForAcceptance('TestModuleForAcceptance | Basic acceptance tests', { | ||
Application, | ||
|
||
beforeSetup() { | ||
setResolverRegistry({ | ||
'router:main': Ember.Router.extend({ location: 'none' }), | ||
'template:index': Ember.Handlebars.compile('This is the index page.') | ||
}); | ||
} | ||
}); | ||
|
||
test('Basic acceptance test using instance test helpers', function() { | ||
this.application.testHelpers.visit('/'); | ||
|
||
this.application.testHelpers.andThen(function() { | ||
equal(Ember.$('#ember-testing').text(), 'This is the index page.'); | ||
}); | ||
}); | ||
|
||
test('Basic acceptance test using global test helpers', function() { | ||
window.visit('/'); | ||
|
||
window.andThen(function() { | ||
equal(Ember.$('#ember-testing').text(), 'This is the index page.'); | ||
}); | ||
}); |
Oops, something went wrong.