This repository has been archived by the owner on Jul 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup test-runner & component-test blueprint
Shamelessly stolen from implementation in emberjs/ember.js#15934
- Loading branch information
1 parent
029a952
commit ae866b4
Showing
8 changed files
with
127 additions
and
17 deletions.
There are no files selected for viewing
39 changes: 23 additions & 16 deletions
39
blueprints/component-test/files/tests/__testType__/__path__/__test__.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 |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import { module, test } from 'qunit'; | ||
import { <% if (testType === 'integration' ) { %> setupRenderingTest <% } else if(testType === 'unit') { %> setupTest <% } %> } from 'ember-qunit'; | ||
<% if (testType === 'integration') { %>import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('<%= friendlyTestDescription %>', function(hooks) { | ||
<% if (testType === 'integration' ) { %> setupRenderingTest(hooks); <% } else if(testType === 'unit') { %> setupTest(hooks); <% } %> | ||
setupRenderingTest(hooks); | ||
|
||
// use hooks.before/after/beforeEach/afterEach for test setup | ||
|
||
test('it renders', async function(assert) {<% if (testType === 'integration' ) { %> | ||
test('it renders', async function(assert) { | ||
// Set any properties with this.set('myProperty', 'value'); | ||
// Handle any actions with this.on('myAction', function(val) { ... }); | ||
// Handle any actions with this.set('myAction', function(val) { ... }); | ||
|
||
await this.render(hbs`{{<%= componentPathName %>}}`); | ||
await render(hbs`{{<%= componentPathName %>}}`); | ||
|
||
assert.equal(this.$().text().trim(), ''); | ||
assert.equal(this.element.textContent.trim(), ''); | ||
|
||
// Template block usage: | ||
await this.render(hbs` | ||
await render(hbs` | ||
{{#<%= componentPathName %>}} | ||
template block text | ||
{{/<%= componentPathName %>}} | ||
`); | ||
|
||
assert.equal(this.$().text().trim(), 'template block text');<% } else if(testType === 'unit') { %> | ||
// Creates the component instance | ||
let Factory = this.owner.factoryFor('component:<%= componentPathName %>'); | ||
let subject = Factory.create({}); | ||
assert.ok(subject);<% } %> | ||
assert.equal(this.element.textContent.trim(), 'template block text'); | ||
}); | ||
});<% } else if (testType === 'unit') { %>import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
|
||
module('<%= friendlyTestDescription %>', function(hooks) { | ||
setupTest(hooks); | ||
|
||
test('it exists', function(assert) { | ||
let component = this.owner.factoryFor('component:<%= componentPathName %>').create(); | ||
assert.ok(component); | ||
}); | ||
}); | ||
});<% } %> | ||
|
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,40 @@ | ||
'use strict'; | ||
|
||
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); | ||
const setupTestHooks = blueprintHelpers.setupTestHooks; | ||
const emberNew = blueprintHelpers.emberNew; | ||
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy; | ||
const modifyPackages = blueprintHelpers.modifyPackages; | ||
|
||
const chai = require('ember-cli-blueprint-test-helpers/chai'); | ||
const expect = chai.expect; | ||
|
||
const fixture = require('../helpers/fixture'); | ||
|
||
describe('Blueprint: component-test', function() { | ||
setupTestHooks(this); | ||
|
||
describe('in app', function() { | ||
beforeEach(function() { | ||
return emberNew(); | ||
}); | ||
|
||
describe('with [email protected]', function() { | ||
|
||
it('component-test x-foo', function() { | ||
return emberGenerateDestroy(['component-test', 'x-foo'], _file => { | ||
expect(_file('tests/integration/components/x-foo-test.js')) | ||
.to.equal(fixture('component-test/rfc232.js')); | ||
}); | ||
}); | ||
|
||
it('component-test x-foo --unit', function() { | ||
return emberGenerateDestroy(['component-test', 'x-foo', '--unit'], _file => { | ||
expect(_file('tests/unit/components/x-foo-test.js')) | ||
.to.equal(fixture('component-test/rfc232-unit.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,11 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
|
||
module('Unit | Component | x foo', function(hooks) { | ||
setupTest(hooks); | ||
|
||
test('it exists', function(assert) { | ||
let component = this.owner.factoryFor('component:x-foo').create(); | ||
assert.ok(component); | ||
}); | ||
}); |
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,26 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('Integration | Component | x foo', function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it renders', async function(assert) { | ||
// Set any properties with this.set('myProperty', 'value'); | ||
// Handle any actions with this.set('myAction', function(val) { ... }); | ||
|
||
await render(hbs`{{x-foo}}`); | ||
|
||
assert.equal(this.element.textContent.trim(), ''); | ||
|
||
// Template block usage: | ||
await render(hbs` | ||
{{#x-foo}} | ||
template block text | ||
{{/x-foo}} | ||
`); | ||
|
||
assert.equal(this.element.textContent.trim(), 'template block text'); | ||
}); | ||
}); |
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,8 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const file = require('ember-cli-blueprint-test-helpers/chai').file; | ||
|
||
module.exports = function(filePath) { | ||
return file(path.join(__dirname, '../fixtures', filePath)); | ||
}; |
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 glob = require('glob'); | ||
var Mocha = require('mocha'); | ||
|
||
var mocha = new Mocha({ | ||
timeout: 5000, | ||
reporter: 'spec' | ||
}); | ||
|
||
mocha.files = glob.sync('node-tests/{blueprints,acceptance,unit}/**/*-test.js'); | ||
|
||
mocha.run(function(failures) { | ||
process.on('exit', function() { | ||
process.exit(failures); | ||
}); | ||
}); |
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