Skip to content

Commit

Permalink
Add blueprint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Mar 11, 2018
1 parent 27eee0c commit 2a632cd
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 7 deletions.
14 changes: 12 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ module.exports = {
'config/**/*.js',
'tests/dummy/config/**/*.js',
'lib/feature-parser.js',
'blueprints/*.js'
'blueprints/*.js',
'node-tests/**/*.js'
],
excludedFiles: [
'app/**',
'addon/**',
'tests/dummy/app/**'
'tests/dummy/app/**',
'node-tests/fixtures/**'
],
parserOptions: {
sourceType: 'script',
Expand All @@ -52,6 +54,14 @@ module.exports = {
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
},
{
files: [
'node-tests/**/*.js'
],
env: {
mocha: true
}
}
]
};
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/bower_components
/config/ember-try.js
/dist
/tests
/tmp
**/.gitkeep
.bowerrc
.editorconfig
.ember-cli
.eslintrc.js
Expand All @@ -19,3 +17,4 @@ testem.js
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
/node-tests
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ env:
- EMBER_TRY_SCENARIO=ember-release ANNOTATIONS=acceptance,smoke
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=node-tests

matrix:
fast_finish: true
Expand Down
7 changes: 7 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ module.exports = function() {
npm: {
devDependencies: {}
}
},
{
name: 'node-tests',
command: 'npm run nodetest',
npm: {
devDependencies: {}
}
}
]
};
Expand Down
47 changes: 47 additions & 0 deletions node-tests/blueprints/feature-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'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 expect = require('ember-cli-blueprint-test-helpers/chai').expect;

const fixture = require('../helpers/fixture');

describe('Acceptance: ember generate and destroy feature', function() {
setupTestHooks(this);

beforeEach(function() {
return emberNew();
});

[
'qunit',
'mocha'
].forEach((testFramework) => {

describe(testFramework, function() {

if (testFramework === 'mocha') {
beforeEach(function() {
return modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true }
]);
});
}

it('feature foo', function() {
let args = ['feature', 'foo'];

// pass any additional command line options in the arguments array
return emberGenerateDestroy(args, (file) => {
expect(file('tests/acceptance/foo.feature')).to.equal(fixture('acceptance/foo.feature'));
expect(file('tests/acceptance/steps/foo-steps.js')).to.equal(fixture(`acceptance/${testFramework}/foo-steps.js`));
});
});
});
});
});
53 changes: 53 additions & 0 deletions node-tests/blueprints/main-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
const setupTestHooks = blueprintHelpers.setupTestHooks;
const emberNew = blueprintHelpers.emberNew;
const emberGenerate = blueprintHelpers.emberGenerate;
const modifyPackages = blueprintHelpers.modifyPackages;

const chai = require('ember-cli-blueprint-test-helpers/chai');
const expect = chai.expect;
const file = chai.file;

const fixture = require('../helpers/fixture');

describe('Acceptance: ember generate ember-cli-yadda', function() {
setupTestHooks(this);

beforeEach(function() {
return emberNew();
});

[
'qunit',
'mocha'
].forEach((testFramework) => {

describe(testFramework, function() {

if (testFramework === 'mocha') {
beforeEach(function() {
return modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true }
]);
});
}

it('adds required files', function() {
let args = ['ember-cli-yadda'];

let fixtureFiles = [
'helpers/yadda.js',
'helpers/yadda-annotations.js',
// 'unit/steps/steps.js',
'acceptance/steps/steps.js',
];

return emberGenerate(args)
.then(() => fixtureFiles.forEach((fileName) => expect(file(`tests/${fileName}`)).to.equal(fixture(`main/${testFramework}/${fileName}`))));
});
});
});
});
7 changes: 7 additions & 0 deletions node-tests/fixtures/acceptance/foo.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: foo

Scenario: the one where I type ember g feature

Given I type "Ember g feature make-feature"
When I look in the folder
Then I should find a file
12 changes: 12 additions & 0 deletions node-tests/fixtures/acceptance/mocha/foo-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import steps from './steps';

// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file

export default function() {
return steps()
.then('I should find a file', function(next) {
// Add your own assert library
next();
});
}
12 changes: 12 additions & 0 deletions node-tests/fixtures/acceptance/qunit/foo-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import steps from './steps';

// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file

export default function(assert) {
return steps(assert)
.then('I should find a file', function(next) {
assert.ok(true, this.step);
next();
});
}
14 changes: 14 additions & 0 deletions node-tests/fixtures/main/mocha/acceptance/steps/steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import yadda from '../../helpers/yadda';

export default function() {
return yadda.localisation.English.library()
.given('I type "Ember g feature make-feature"', function(next) {
visit('/');
// Add your own assert library
andThen(() => next());
})
.when('I look in the folder', function(next) {
// Add your own assert library
next();
});
}
61 changes: 61 additions & 0 deletions node-tests/fixtures/main/mocha/helpers/yadda-annotations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import ENV from '../../config/environment';
import { describe } from 'mocha';
import Ember from 'ember';

// this logic could be anything, but in this case...
// if @ignore, then return skip (for backwards compatibility)
// if no annotations are set in the config, run everything without an annotation (for backwards compatibility)
// if have annotations in config, then only run those that have a matching annotation
function checkAnnotations(annotations) {

// if ignore is set then we want to skip for backwards compatibility
if (annotations.ignore) {
return ignoreIt;
}

// if have annotations set in config, the only run those that have a matching annotation
if (ENV.annotations && ENV.annotations.length >= 0) {

for (let annotation in annotations) {
if (ENV.annotations.indexOf(annotation) >= 0) {
// have match, so test it
return 'testIt'; // return something other than a function
}
}

// no match, so don't run it
return logIt;

} else {
// no annotations set, so run it for backwards compatibility
// unless it has annotations, then don't run it
if (Object.keys(annotations).length) {
// has annotation, so don't run it
return logIt;
} else {
// no annotations, so test it
return 'testIt'; // return something other than a function
}
}
}

// call back functions
function ignoreIt(testElement) {
describe.skip(`${testElement.title}`, () => {});
}

function logIt(testElement) {
// change this to do what you need it to do
Ember.Logger.info(`Not running or skipping: "${testElement.title}"`);
}

// exported functions
function runFeature(annotations) {
return checkAnnotations(annotations);
}

function runScenario(featureAnnotations, scenarioAnnotations) {
return checkAnnotations(scenarioAnnotations);
}

export { runFeature, runScenario };
2 changes: 2 additions & 0 deletions node-tests/fixtures/main/mocha/helpers/yadda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import yadda from 'npm:yadda';
export default yadda;
14 changes: 14 additions & 0 deletions node-tests/fixtures/main/qunit/acceptance/steps/steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import yadda from '../../helpers/yadda';

export default function(assert) {
return yadda.localisation.English.library()
.given('I type "Ember g feature make-feature"', function(next) {
visit('/');
assert.ok(true, this.step);
andThen(() => next());
})
.when('I look in the folder', function(next) {
assert.ok(true, this.step);
next();
});
}
60 changes: 60 additions & 0 deletions node-tests/fixtures/main/qunit/helpers/yadda-annotations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import ENV from '../../config/environment';
import { skip } from 'ember-qunit';
import Ember from 'ember';

// this logic could be anything, but in this case...
// if @ignore, then return skip (for backwards compatibility)
// if no annotations are set in the config, run everything without an annotation (for backwards compatibility)
// if have annotations in config, then only run those that have a matching annotation
function checkAnnotations(annotations) {

// if ignore is set then we want to skip for backwards compatibility
if (annotations.ignore) {
return ignoreIt;
}

// if have annotations set in config, the only run those that have a matching annotation
if (ENV.annotations && ENV.annotations.length >= 0) {

for (let annotation in annotations) {
if (ENV.annotations.indexOf(annotation) >= 0) {
// have match, so test it
return 'testIt'; // return something other than a function
}
}

// no match, so don't run it
return logIt;

} else {
// no annotations set, so run it for backwards compatibility
// unless it has annotations, then don't run it
if (Object.keys(annotations).length) {
// has annotation, so don't run it
return logIt;
} else {
// no annotations, so test it
return 'testIt'; // return something other than a function
}
}
}

// call back functions
function ignoreIt(testElement) {
skip(`${testElement.title}`, function(assert) {});
}

function logIt(testElement) {
Ember.Logger.info(`Not running or skipping: "${testElement.title}"`);
}

// exported functions
function runFeature(annotations) {
return checkAnnotations(annotations);
}

function runScenario(featureAnnotations, scenarioAnnotations) {
return checkAnnotations(scenarioAnnotations);
}

export { runFeature, runScenario };
2 changes: 2 additions & 0 deletions node-tests/fixtures/main/qunit/helpers/yadda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import yadda from 'npm:yadda';
export default yadda;
13 changes: 13 additions & 0 deletions node-tests/fixtures/main/qunit/unit/steps/steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import yadda from '../../helpers/yadda';

export default function(assert) {
return yadda.localisation.English.library()
.given('I type "Ember g feature make-feature"', function(next){
assert.ok(true, this.step);
next();
})
.when('I look in the folder', function(next){
assert.ok(true, this.step);
next();
});
}
8 changes: 8 additions & 0 deletions node-tests/helpers/fixture.js
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));
};
Loading

0 comments on commit 2a632cd

Please sign in to comment.