Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Auto-tag components #26

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
npm-debug.log*
testem.log
22 changes: 18 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
---
language: node_js
node_js:
- "0.12"
- "4"

sudo: false

cache:
directories:
- node_modules

env:
- EMBER_TRY_SCENARIO=ember-1.13
- EMBER_TRY_SCENARIO=ember-lts-2.4
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary

matrix:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- npm config set spin false
- npm install -g bower
- bower --version
- npm install phantomjs-prebuilt
- phantomjs --version
- node_modules/phantomjs-prebuilt/bin/phantomjs --version

install:
- npm install
- bower install

script:
- npm run-script test
- npm run-script jshint
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup
- npm run mocha

notifications:
email: false
Expand Down
26 changes: 26 additions & 0 deletions addon/initializers/add-test-selectors-to-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Ember from 'ember';

const { getPrototypeOf } = Object;
const { computed, Component, get } = Ember;

const nameOfComponent = function nameOfComponent(component, config) {
let templateName = component._renderNode.lastResult.template.meta.moduleName;
templateName = templateName.replace(/\.hbs$/, '');
templateName = templateName.replace(new RegExp(`${config.modulePrefix}\/templates\/components\/`), '');
return templateName;
}

export default function addTestSelectorsToComponents(config) {
Component.reopen({
init() {
let attributeBinding = `-data-test-component-selector:data-test-component`;
this.attributeBindings = (this.attributeBindings || []).concat([attributeBinding]);

return this._super(...arguments);
},

'-data-test-component-selector': computed(function() {
return nameOfComponent(this, config);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps I'm just not following, but I don't see anywhere to add custom selectors. This seems to only add a selector based upon the component name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for now I want to support attributes with the component name and then for all data-test-* attributes afterwards.

})
});
}
9 changes: 9 additions & 0 deletions app/initializers/ember-test-selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import addTestSelectorsToComponents from 'ember-test-selectors/initializers/add-test-selectors-to-components';
import config from '../config/environment';

export default {
name: 'ember-test-selectors',
initialize: function() {
addTestSelectorsToComponents(config);
}
};
5 changes: 2 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "ember-test-selectors",
"dependencies": {
"ember": "~2.7.0",
"ember-cli-shims": "0.1.1",
"ember-qunit-notifications": "0.1.0"
"ember": "~2.9.0",
"ember-cli-shims": "0.1.3"
}
}
12 changes: 11 additions & 1 deletion config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*jshint node:true*/
module.exports = {
useVersionCompatibility: true,
scenarios: [
{
name: 'ember-1.13',
Expand All @@ -13,6 +12,17 @@ module.exports = {
}
}
},
{
name: 'ember-lts-2.4',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-4'
},
resolutions: {
'ember': 'lts-2-4'
}
}
},
{
name: 'ember-release',
bower: {
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*jshint node:true*/
/* jshint node:true */
'use strict';

var _includes = require('lodash/includes');

module.exports = {
name: 'test-selectors',
name: 'ember-test-selectors',

setupPreprocessorRegistry: function(type, registry) {
var appOptions = registry.app.options || {};
Expand Down
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
{
"name": "ember-test-selectors",
"version": "0.0.5",
"description": "Enabling better Test selectors in Ember.js applications",
"description": "Enabling better Test selectors in Ember.js applications.",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"test": "ember try:each",
"jshint": "mocha"
"build": "ember build",
"start": "ember server",
"test": "ember try:each"
},
"repository": "https://github.com/simplabs/ember-test-selectors",
"engines": {
"node": ">= 0.10.0"
"node": ">= 0.12.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.2",
"ember-ajax": "^2.0.1",
"ember-cli": "2.7.0",
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-jshint": "^1.0.0",
"ember-cli-qunit": "^2.0.0",
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^2.4.1",
"ember-cli": "2.9.1",
"ember-cli-app-version": "^2.0.0",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-htmlbars": "^1.0.10",
"ember-cli-htmlbars-inline-precompile": "^0.3.3",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-jshint": "^1.0.4",
"ember-cli-qunit": "^3.0.1",
"ember-cli-release": "^0.2.9",
"ember-cli-sri": "^2.1.0",
"ember-cli-test-loader": "^1.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.7.0",
"ember-data": "^2.9.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-export-application-global": "^1.0.5",
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"loader.js": "^4.0.1",
"loader.js": "^4.0.10",
"mocha": "^1.21.4",
"mocha-jshint": "^2.3.1"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.5",
"lodash": "^4.0.0"
"ember-cli-babel": "^5.1.7",
"lodash": "^4.0.0"
},
"ember-addon": {
"configPath": "tests/dummy/config",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Ember from 'ember';

export default Ember.Component.extend();
3 changes: 3 additions & 0 deletions tests/dummy/app/components/test-component-with-impl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Ember from 'ember';

export default Ember.Component.extend();
4 changes: 0 additions & 4 deletions tests/dummy/app/templates/components/data-test.hbs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2>Nested Test Component with implementation</h2>

<blockquote>
<p>"Please disperse. Nothing to see here." - Frank Drebin</p>
</blockquote>

<p>
This component only exists so we can convenietly use
<code>moduleForComponent</code> for the tests which check that
<code>data-test-*</code> attributes are stripped.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2>Nested Test Component without implementation</h2>

<blockquote>
<p>"Please disperse. Nothing to see here." - Frank Drebin</p>
</blockquote>

<p>
This component only exists so we can convenietly use
<code>moduleForComponent</code> for the tests which check that
<code>data-test-*</code> attributes are stripped.
</p>
11 changes: 11 additions & 0 deletions tests/dummy/app/templates/components/test-component-with-impl.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2>Test Component with implementation</h2>

<blockquote>
<p>"Please disperse. Nothing to see here." - Frank Drebin</p>
</blockquote>

<p>
This component only exists so we can convenietly use
<code>moduleForComponent</code> for the tests which check that
<code>data-test-*</code> attributes are stripped.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2>Test Component without implementation</h2>

<blockquote>
<p>"Please disperse. Nothing to see here." - Frank Drebin</p>
</blockquote>

<p>
This component only exists so we can convenietly use
<code>moduleForComponent</code> for the tests which check that
<code>data-test-*</code> attributes are stripped.
</p>
7 changes: 7 additions & 0 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{test-component-with-impl}}

{{test-component-without-impl}}

{{nesting-level/test-component-with-impl}}

{{nesting-level/test-component-without-impl}}
4 changes: 4 additions & 0 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module.exports = function(environment) {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false
}
},

Expand Down
2 changes: 1 addition & 1 deletion tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{{content-for "body"}}
{{content-for "test-body"}}

<script src="{{rootURL}}testem.js" integrity=""></script>
<script src="/testem.js" integrity=""></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/test-support.js"></script>
<script src="{{rootURL}}assets/dummy.js"></script>
Expand Down