├── .bowerrc ├── .editorconfig ├── .ember-cli ├── .eslintrc.js ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── .watchmanconfig ├── LICENSE.md ├── README.md ├── addon └── .gitkeep ├── app ├── instance-initializers │ └── ember-devtools.js └── services │ └── ember-devtools.js ├── config ├── ember-try.js └── environment.js ├── ember-cli-build.js ├── index.js ├── package.json ├── testem.js └── tests ├── .eslintrc.js ├── .jshintrc ├── acceptance └── devtools-test.js ├── dummy ├── app │ ├── app.js │ ├── components │ │ ├── .gitkeep │ │ └── test-component.js │ ├── controllers │ │ ├── .gitkeep │ │ └── foo.js │ ├── helpers │ │ └── .gitkeep │ ├── index.html │ ├── models │ │ └── .gitkeep │ ├── resolver.js │ ├── router.js │ ├── routes │ │ ├── .gitkeep │ │ ├── bar.js │ │ └── foo.js │ ├── styles │ │ └── app.css │ └── templates │ │ ├── application.hbs │ │ ├── components │ │ └── .gitkeep │ │ └── foo.hbs ├── config │ ├── environment.js │ └── targets.js └── public │ ├── crossdomain.xml │ └── robots.txt ├── helpers ├── destroy-app.js ├── module-for-acceptance.js ├── resolver.js └── start-app.js ├── index.html ├── integration └── components │ └── test-component-test.js ├── test-helper.js └── unit ├── .gitkeep └── services └── devtools-test.js /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "bower_components", 3 | "analytics": false 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.js] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.hbs] 21 | insert_final_newline = false 22 | indent_style = space 23 | indent_size = 2 24 | 25 | [*.css] 26 | indent_style = space 27 | indent_size = 2 28 | 29 | [*.html] 30 | indent_style = space 31 | indent_size = 2 32 | 33 | [*.{diff,md}] 34 | trim_trailing_whitespace = false 35 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | ecmaVersion: 2017, 5 | sourceType: 'module' 6 | }, 7 | extends: 'eslint:recommended', 8 | env: { 9 | browser: true 10 | }, 11 | rules: { 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/* 15 | /libpeerconnection.log 16 | npm-debug.log* 17 | testem.log 18 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "document", 4 | "window", 5 | "-Promise" 6 | ], 7 | "browser": true, 8 | "boss": true, 9 | "curly": false, 10 | "debug": false, 11 | "devel": true, 12 | "eqeqeq": true, 13 | "evil": true, 14 | "forin": false, 15 | "immed": false, 16 | "laxbreak": true, 17 | "newcap": true, 18 | "noarg": true, 19 | "noempty": false, 20 | "nonew": false, 21 | "nomen": false, 22 | "onevar": false, 23 | "plusplus": false, 24 | "regexp": false, 25 | "undef": true, 26 | "sub": true, 27 | "strict": false, 28 | "white": false, 29 | "eqnull": true, 30 | "esnext": true, 31 | "unused": true 32 | } 33 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /bower_components 2 | /config/ember-try.js 3 | /dist 4 | /tests 5 | /tmp 6 | **/.gitkeep 7 | .bowerrc 8 | .editorconfig 9 | .ember-cli 10 | .gitignore 11 | .eslintrc.js 12 | .watchmanconfig 13 | .travis.yml 14 | bower.json 15 | ember-cli-build.js 16 | testem.js 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - "6" 5 | 6 | sudo: false 7 | 8 | cache: 9 | directories: 10 | - $HOME/.npm 11 | 12 | env: 13 | # we recommend testing LTS's and latest stable release (bonus points to beta/canary) 14 | - EMBER_TRY_SCENARIO=ember-lts-2.4 15 | - EMBER_TRY_SCENARIO=ember-lts-2.8 16 | - EMBER_TRY_SCENARIO=ember-release 17 | - EMBER_TRY_SCENARIO=ember-beta 18 | - EMBER_TRY_SCENARIO=ember-canary 19 | - EMBER_TRY_SCENARIO=ember-default 20 | 21 | matrix: 22 | fast_finish: true 23 | allow_failures: 24 | - env: EMBER_TRY_SCENARIO=ember-canary 25 | 26 | before_install: 27 | - npm config set spin false 28 | - npm install -g phantomjs-prebuilt 29 | - phantomjs --version 30 | 31 | install: 32 | - npm install 33 | 34 | script: 35 | # Usually, it's ok to finish the test scenario without reverting 36 | # to the addon's original dependency state, skipping "cleanup". 37 | - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup 38 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Build Status](https://travis-ci.org/aexmachina/ember-devtools) 2 | 3 | # ember-devtools 4 | 5 | A collection of useful functions for developing Ember apps. Best served from the console. 6 | 7 | ## Usage 8 | 9 | ember-devtools is an `Ember.Service` that is most useful when available in the devtools 10 | console. The simplest was access this from the console is using 11 | a global variable (eww!) which can be defined in `config/environment.js`. 12 | 13 | ```js 14 | var ENV = { 15 | 'ember-devtools': { 16 | global: true, 17 | enabled: environment === 'development' 18 | } 19 | } 20 | ``` 21 | 22 | Setting `global` will allow access to the `devTools` functions globally (eg. you can 23 | run `routes()` in the console). If you'd prefer these functions to be under a prefix 24 | set `global: 'devTools'` for `devTools.routes()`. 25 | 26 | The `enabled` option will enable the addon. By default, this addon will only be included in the `development` environment. 27 | 28 | Alternatively you can use `Ember.inject.service('ember-devtools')` or `appInstance.lookup('service:ember-devtools')`. 29 | 30 | ## Functions 31 | 32 | ### `app([name])` 33 | 34 | Returns the named application. `name` defaults to `main`. 35 | 36 | ### `routes()` 37 | 38 | Returns the names of all routes. 39 | 40 | ### `route([name])` 41 | 42 | Returns the named route. `name` defaults to the current route. 43 | 44 | ### `router([name])` 45 | 46 | Returns the named router instance. `name` defaults to `main`. 47 | 48 | ### `model([name])` 49 | 50 | Returns the model for the named controller. `name` defaults to the the current route. 51 | 52 | ### `service(name)` 53 | 54 | Performs a lookup for the named service in the `owner` (using `'service:' + name`). 55 | 56 | ### `controller([name])` 57 | 58 | Returns the named controller. `name` defaults to the current route. 59 | 60 | ### `log(promise[, property[, getEach]])` 61 | 62 | Resolves the `promise` and logs the resolved value using `console.log`. 63 | Also sets `window.$E` to the resolved value so you can access it in the dev 64 | tools console. 65 | 66 | If `property` is specified then `$E.get(property)` will be logged. 67 | 68 | If `getEach` is true then `$E.getEach(property)` will be logged. 69 | 70 | #### Examples: 71 | 72 | ``` 73 | > log(store.find('organisation')) => undefined 74 | > $E.get('length') => 3 75 | > log(store.find('organisation'), 'length') => 3 76 | > log(store.find('organisation'), 'name', true) => array of names 77 | ``` 78 | 79 | ### `lookup(name)` 80 | 81 | Performs a lookup for the named entry in the `owner`, which will in turn 82 | ask its `resolver` if it's not found. 83 | 84 | ### `resolveRegistration(name)` 85 | 86 | Performs a lookup for the named factory in the `registry`. 87 | 88 | ### `ownerNameFor(obj)` 89 | 90 | Searches the `owner` to find the name for the specified object (if any). 91 | 92 | ### `inspect` 93 | 94 | Does what it says, in a manner of speaking. Alias to `Ember.inspect`. 95 | 96 | ### `logResolver(bool = true)` 97 | 98 | Switch logging for the resolver on or off. 99 | 100 | ### `logAll(bool = true)` 101 | 102 | Switch logging for all the things on/off. 103 | 104 | ### `logRenders()` 105 | 106 | Logs the rendering duration (in milliseconds) of each component, view and helper. 107 | 108 | ### `globalize()` 109 | 110 | Attach all of these useful functions to the `window` object (eww!) - useful 111 | for accessing in the console. 112 | 113 | ### `getOwner(obj = this)` 114 | 115 | The owner of the service or specified `obj`. 116 | 117 | ### `config()` 118 | 119 | Returns the Application config 120 | 121 | ## Properties 122 | 123 | ### `owner` 124 | 125 | The owner of the service. n.b. this is not globalised (to avoid conflict with `window.owner`), use `getOwner()` instead. 126 | 127 | ### `store` 128 | 129 | The Ember Data `Store`. 130 | 131 | ### `typeMaps` 132 | 133 | The Ember Data 'type map'. 134 | 135 | ## Installation 136 | 137 | ### Ember CLI 138 | 139 | npm install ember-devtools --save-dev 140 | 141 | ### Upgrading From v2.0 142 | 143 | ember-devtools is now dependent on ember-cli. 144 | 145 | ## Changelog 146 | 147 | - v6: `container` and `containerNameFor` are now `owner` and `ownerNameFor` 148 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonexmachina/ember-devtools/6b28190278f0907eee56cee63f4bcde86e6a794c/addon/.gitkeep -------------------------------------------------------------------------------- /app/instance-initializers/ember-devtools.js: -------------------------------------------------------------------------------- 1 | /* global window */ 2 | import config from '../config/environment'; 3 | 4 | export default { 5 | initialize(appInstance) { 6 | var devToolsConfig = config['ember-devtools'] || {}; 7 | let enabled = devToolsConfig.enabled; 8 | if (enabled === undefined) { 9 | enabled = /(development|test)/.test(config.environment); 10 | } 11 | if (!enabled) return; 12 | var service = 'service:ember-devtools'; 13 | var devTools = appInstance.lookup ? appInstance.lookup(service) 14 | // backwards compatibility < 2.1 15 | : appInstance.container.lookup(service); 16 | if (devToolsConfig.global === true) { 17 | devTools.globalize(); 18 | } 19 | else if (devToolsConfig.global) { 20 | window[devToolsConfig.global] = devTools; 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /app/services/ember-devtools.js: -------------------------------------------------------------------------------- 1 | /* global DS */ 2 | import Ember from 'ember'; 3 | var { 4 | Service 5 | } = Ember; 6 | 7 | export default Service.extend({ 8 | renderedComponents: {}, 9 | init() { 10 | this.global = this.global || window; 11 | this.console = this.console || window.console; 12 | if (Ember.getOwner) { // for ember > 2.3 13 | Object.defineProperty(this, 'owner', { 14 | get() { 15 | return Ember.getOwner(this); 16 | } 17 | }); 18 | } 19 | Object.defineProperty(this, 'store', { 20 | get() { 21 | return this.lookup('service:store') || 22 | this.lookup('store:main'); // for ember-data < 2 23 | } 24 | }); 25 | }, 26 | consoleLog() { 27 | this.console.log(...arguments); 28 | }, 29 | app(name = 'main') { 30 | return this.lookup(`application:${name}`); 31 | }, 32 | route(name) { 33 | name = name || this.currentRouteName(); 34 | return this.lookup(`route:${name}`); 35 | }, 36 | controller(name) { 37 | name = name || this.currentRouteName(); 38 | return this.lookup(`controller:${name}`); 39 | }, 40 | model(name) { 41 | var controller = this.controller(name); 42 | return controller && controller.get('model'); 43 | }, 44 | service(name) { 45 | return this.lookup(`service:${name}`); 46 | }, 47 | router(name = 'main') { 48 | return this.lookup(`router:${name}`).get('router'); 49 | }, 50 | routes() { 51 | return Object.keys(this.router().recognizer.names); 52 | }, 53 | currentRouteName() { 54 | return this.controller('application').get('currentRouteName'); 55 | }, 56 | currentPath() { 57 | return this.controller('application').get('currentPath'); 58 | }, 59 | log(promise, property, getEach) { 60 | return promise.then((value) => { 61 | this.global.$E = value; 62 | if (property) { 63 | value = value[getEach ? 'getEach' : 'get'].call(value, property); 64 | } 65 | this.consoleLog(value); 66 | }, (err) => { 67 | this.console.error(err); 68 | }); 69 | }, 70 | lookup(name) { 71 | return this.owner.lookup(name); 72 | }, 73 | resolveRegistration(name) { 74 | return this.owner.resolveRegistration 75 | // ember < 2.3.1 76 | ? this.owner.resolveRegistration(name) 77 | // previous ember versions 78 | : this.owner.lookupFactory(name); 79 | }, 80 | ownerNameFor(object) { 81 | var cache = 82 | // ember 2.3.1 83 | Ember.get(this.owner, '__container__.cache') 84 | // previous ember versions 85 | || Ember.get(this.owner, '_defaultContainer.cache') 86 | || this.owner.cache; 87 | var keys = Object.keys(cache); 88 | for (var i = 0; i < keys.length; i++) { 89 | if (cache[keys[i]] === object) return keys[i]; 90 | } 91 | }, 92 | inspect: Ember.inspect, 93 | logResolver(bool = true) { 94 | Ember.ENV.LOG_MODULE_RESOLVER = bool; 95 | }, 96 | logAll(bool = true) { 97 | var app = this.app(); 98 | app.LOG_ACTIVE_GENERATION = bool; 99 | app.LOG_VIEW_LOOKUPS = bool; 100 | app.LOG_TRANSITIONS = bool; 101 | app.LOG_TRANSITIONS_INTERNAL = bool; 102 | this.logResolver(bool); 103 | }, 104 | logRenders() { 105 | var self = this; 106 | 107 | Ember.subscribe('render', { 108 | before(name, start, payload) { 109 | return start; 110 | }, 111 | after(name, end, payload, start) { 112 | var id = payload.containerKey; 113 | if (!id) return; 114 | 115 | var duration = Math.round(end - start); 116 | var color = self.colorForRender(duration); 117 | var logId = `renderedComponents.${id}`; 118 | var ocurrences = self.get(logId); 119 | 120 | if (!ocurrences) { 121 | self.set(logId, []); 122 | } 123 | 124 | self.get(logId).push(duration); 125 | 126 | console.log('%c rendered ' + id + ' in ' + duration + 'ms', 'color: ' + color); 127 | } 128 | }); 129 | }, 130 | colorForRender(duration) { 131 | var ok = '#000000'; 132 | var warning = '#F1B178'; 133 | var serious = '#E86868'; 134 | 135 | if (duration < 300) return ok; 136 | if (duration < 600) return warning; 137 | 138 | return serious; 139 | }, 140 | environment() { 141 | Ember.deprecate('environment() has been deprecated, please use config() instead'); 142 | }, 143 | config() { 144 | return this.resolveRegistration('config:environment'); 145 | }, 146 | getOwner() { 147 | return this.owner; 148 | }, 149 | globalize() { 150 | var props = ['app', 'getOwner', 'store', 'typeMaps', 'route', 'controller', 'model', 151 | 'service', 'routes', 'view', 'currentRouteName', 'currentPath', 152 | 'log', 'lookup', 'resolveRegistration', 'ownerNameFor', 'inspect', 153 | 'logResolver', 'logAll', 'environment', 'config' 154 | ]; 155 | // don't stomp on pre-existing global vars 156 | var skipGlobalize = this.constructor.skipGlobalize; 157 | if (skipGlobalize === null) { 158 | skipGlobalize = this.constructor.skipGlobalize = props.filter( 159 | prop => !Ember.isNone(this.global[prop]) 160 | ); 161 | } 162 | var self = this; 163 | props.map(name => { 164 | if (skipGlobalize.indexOf(name) !== -1) return; 165 | var prop = this[name]; 166 | if (typeof prop === 'function') { 167 | prop = function() { // arguments variable is wrong if we use an arrow function here 168 | return self[name].apply(self, arguments); 169 | } 170 | } 171 | this.global[name] = prop; 172 | }); 173 | } 174 | }).reopenClass({ 175 | skipGlobalize: null 176 | }); 177 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | module.exports = { 3 | scenarios: [ 4 | { 5 | name: 'ember-lts-2.4', 6 | bower: { 7 | dependencies: { 8 | 'ember': 'components/ember#lts-2-4' 9 | }, 10 | resolutions: { 11 | 'ember': 'lts-2-4' 12 | } 13 | }, 14 | npm: { 15 | devDependencies: { 16 | 'ember-source': null 17 | } 18 | } 19 | }, 20 | { 21 | name: 'ember-lts-2.8', 22 | bower: { 23 | dependencies: { 24 | 'ember': 'components/ember#lts-2-8' 25 | }, 26 | resolutions: { 27 | 'ember': 'lts-2-8' 28 | } 29 | }, 30 | npm: { 31 | devDependencies: { 32 | 'ember-source': null 33 | } 34 | } 35 | }, 36 | { 37 | name: 'ember-release', 38 | bower: { 39 | dependencies: { 40 | 'ember': 'components/ember#release' 41 | }, 42 | resolutions: { 43 | 'ember': 'release' 44 | } 45 | }, 46 | npm: { 47 | devDependencies: { 48 | 'ember-source': null 49 | } 50 | } 51 | }, 52 | { 53 | name: 'ember-beta', 54 | bower: { 55 | dependencies: { 56 | 'ember': 'components/ember#beta' 57 | }, 58 | resolutions: { 59 | 'ember': 'beta' 60 | } 61 | }, 62 | npm: { 63 | devDependencies: { 64 | 'ember-source': null 65 | } 66 | } 67 | }, 68 | { 69 | name: 'ember-canary', 70 | bower: { 71 | dependencies: { 72 | 'ember': 'components/ember#canary' 73 | }, 74 | resolutions: { 75 | 'ember': 'canary' 76 | } 77 | }, 78 | npm: { 79 | devDependencies: { 80 | 'ember-source': null 81 | } 82 | } 83 | }, 84 | { 85 | name: 'ember-default', 86 | npm: { 87 | devDependencies: {} 88 | } 89 | } 90 | ] 91 | }; 92 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | /* jshint node:true */ 2 | var objectAssign = require('object-assign'); 3 | 4 | /** 5 | * Export the default config for ember-devtools. By default, enable only 6 | * in development. 7 | */ 8 | module.exports = function(environment, appConfig) { 9 | appConfig['ember-devtools'] = objectAssign({ 10 | enabled: environment === 'development', 11 | global: false 12 | }, appConfig['ember-devtools'] || {}); 13 | 14 | return { }; 15 | }; 16 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 3 | 4 | module.exports = function(defaults) { 5 | var app = new EmberAddon(defaults, { 6 | // Add options here 7 | }); 8 | 9 | /* 10 | This build file specifies the options for the dummy test app of this 11 | addon, located in `/tests/dummy` 12 | This build file does *not* influence how the addon or the app using it 13 | behave. You most likely want to be modifying `./index.js` or app's build file 14 | */ 15 | 16 | return app.toTree(); 17 | }; 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | module.exports = { 5 | name: 'ember-devtools' 6 | }; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-devtools", 3 | "version": "6.0.0", 4 | "description": "A collection of useful functions for developing Ember apps", 5 | "homepage": "https://github.com/aexmachina/ember-devtools", 6 | "repository": "aexmachina/ember-devtools", 7 | "bugs": { 8 | "url": "https://github.com/aexmachina/ember-devtools/issues" 9 | }, 10 | "keywords": [ 11 | "ember-addon" 12 | ], 13 | "license": "MIT", 14 | "author": "", 15 | "directories": { 16 | "doc": "doc", 17 | "test": "tests" 18 | }, 19 | "scripts": { 20 | "build": "ember build", 21 | "start": "ember server", 22 | "test": "ember try:each" 23 | }, 24 | "dependencies": { 25 | "ember-cli-babel": "^6.0.0", 26 | "object-assign": "^4.1.1" 27 | }, 28 | "devDependencies": { 29 | "broccoli-asset-rev": "^2.4.5", 30 | "ember-ajax": "^3.0.0", 31 | "ember-cli": "2.13.2", 32 | "ember-cli-dependency-checker": "^1.3.0", 33 | "ember-cli-eslint": "^3.0.0", 34 | "ember-cli-htmlbars": "^1.1.1", 35 | "ember-cli-htmlbars-inline-precompile": "^0.4.0", 36 | "ember-cli-inject-live-reload": "^1.4.1", 37 | "ember-cli-qunit": "^4.0.0", 38 | "ember-cli-shims": "^1.1.0", 39 | "ember-cli-sri": "^2.1.0", 40 | "ember-cli-uglify": "^1.2.0", 41 | "ember-data": "^2.13.1", 42 | "ember-disable-prototype-extensions": "^1.1.0", 43 | "ember-export-application-global": "^2.0.0", 44 | "ember-load-initializers": "^1.0.0", 45 | "ember-resolver": "^4.0.0", 46 | "ember-source": "~2.13.0", 47 | "ember-welcome-page": "^3.0.0", 48 | "loader.js": "^4.2.3" 49 | }, 50 | "engines": { 51 | "node": ">= 4" 52 | }, 53 | "ember-addon": { 54 | "configPath": "tests/dummy/config" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | module.exports = { 3 | "test_page": "tests/index.html?hidepassed", 4 | "disable_watching": true, 5 | "launch_in_ci": [ 6 | "PhantomJS" 7 | ], 8 | "launch_in_dev": [ 9 | "PhantomJS", 10 | "Chrome" 11 | ] 12 | }; 13 | -------------------------------------------------------------------------------- /tests/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | embertest: true 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /tests/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "document", 4 | "window", 5 | "location", 6 | "setTimeout", 7 | "$", 8 | "-Promise", 9 | "define", 10 | "console", 11 | "visit", 12 | "exists", 13 | "fillIn", 14 | "click", 15 | "keyEvent", 16 | "triggerEvent", 17 | "find", 18 | "findWithAssert", 19 | "wait", 20 | "DS", 21 | "andThen", 22 | "currentURL", 23 | "currentPath", 24 | "currentRouteName" 25 | ], 26 | "node": false, 27 | "browser": false, 28 | "boss": true, 29 | "curly": true, 30 | "debug": false, 31 | "devel": false, 32 | "eqeqeq": true, 33 | "evil": true, 34 | "forin": false, 35 | "immed": false, 36 | "laxbreak": false, 37 | "newcap": true, 38 | "noarg": true, 39 | "noempty": false, 40 | "nonew": false, 41 | "nomen": false, 42 | "onevar": false, 43 | "plusplus": false, 44 | "regexp": false, 45 | "undef": true, 46 | "sub": true, 47 | "strict": false, 48 | "white": false, 49 | "eqnull": true, 50 | "esnext": true, 51 | "unused": true 52 | } 53 | -------------------------------------------------------------------------------- /tests/acceptance/devtools-test.js: -------------------------------------------------------------------------------- 1 | /* global devTools */ 2 | import Ember from 'ember'; 3 | import { 4 | module, 5 | test 6 | } from 'qunit'; 7 | import startApp from '../helpers/start-app'; 8 | import config from "dummy/config/environment"; 9 | 10 | var app; 11 | 12 | module('Acceptance: ember-devtools', { 13 | beforeEach() { 14 | app = startApp(); 15 | }, 16 | afterEach() { 17 | Ember.run(app, 'destroy'); 18 | } 19 | }); 20 | 21 | test('ownerNameFor() returns the name of something in the container', function(assert) { 22 | visit('/'); 23 | andThen(function() { 24 | var route = devTools.route('foo'); 25 | assert.equal(devTools.ownerNameFor(route), 'route:foo'); 26 | }); 27 | }); 28 | 29 | test('route(name) returns named route', function(assert) { 30 | visit('/foo'); 31 | andThen(function() { 32 | var route = devTools.route('foo'); 33 | assert.ok(route instanceof Ember.Route); 34 | }); 35 | }); 36 | 37 | test('route() returns current route', function(assert) { 38 | visit('/foo'); 39 | andThen(() => { 40 | var route = devTools.route(); 41 | assert.ok(route === devTools.route('foo')); 42 | }); 43 | }); 44 | 45 | test('controller(name) returns named controller', function(assert) { 46 | visit('/foo'); 47 | andThen(function() { 48 | var controller = devTools.controller('foo'); 49 | assert.ok(controller instanceof Ember.Controller); 50 | }); 51 | }); 52 | 53 | test('controller() returns current controller', function(assert) { 54 | visit('/foo'); 55 | andThen(() => { 56 | var controller = devTools.controller(); 57 | assert.ok(controller === devTools.controller('foo')); 58 | }); 59 | }); 60 | 61 | test('model(name) returns model for named route', function(assert) { 62 | visit('/bar/baz'); 63 | andThen(function() { 64 | assert.equal(devTools.model('bar'), 'bar'); 65 | }); 66 | }); 67 | 68 | test('model() returns model for current route', function(assert) { 69 | visit('foo'); 70 | andThen(() => { 71 | assert.equal(devTools.model(), 'foo'); 72 | }); 73 | }); 74 | 75 | test('router() returns router', function(assert) { 76 | visit('/'); 77 | andThen(function() { 78 | var router = devTools.router(); 79 | assert.ok(router.hasRoute); 80 | }); 81 | }); 82 | 83 | test('routes() returns a list of route names', function(assert) { 84 | visit('/'); 85 | andThen(function() { 86 | var routes = devTools.routes(); 87 | assert.ok(~routes.indexOf('foo')); 88 | assert.ok(~routes.indexOf('bar')); 89 | }); 90 | }); 91 | 92 | // var componentType = 'test-component'; 93 | // test('component() returns a component for an element', function(assert) { 94 | // visit('/foo'); 95 | // andThen(function() { 96 | // var $el = Ember.$(`.${componentType}`); 97 | // var view = devTools.component($el.get(0), componentType); 98 | // assert.ok(view instanceof Ember.Component); 99 | // }); 100 | // }); 101 | // 102 | // test('component() returns a component for an element id', function(assert) { 103 | // visit('/foo'); 104 | // andThen(function() { 105 | // var $el = Ember.$(`.${componentType}`); 106 | // var view = devTools.component($el.attr('id'), componentType); 107 | // assert.ok(view instanceof Ember.Component); 108 | // }); 109 | // }); 110 | // 111 | test('config() returns application config', function(assert) { 112 | visit('/foo'); 113 | andThen(function() { 114 | let env = devTools.config(); 115 | assert.ok(env === config); 116 | }); 117 | }); 118 | 119 | test('currentRouteName() does what it says', function(assert) { 120 | visit('/bar/nested/quz'); 121 | andThen(function() { 122 | assert.equal(devTools.currentRouteName(), 'nested.quz'); 123 | }); 124 | }); 125 | 126 | test('currentPath() does what it says', function(assert) { 127 | visit('/bar/nested/quz'); 128 | andThen(function() { 129 | assert.equal(devTools.currentPath(), 'bar.nested.quz'); 130 | }); 131 | }); 132 | 133 | module('Acceptance: emberDevTools.global', { 134 | afterEach() { 135 | Ember.run(app, 'destroy'); 136 | } 137 | }); 138 | 139 | test('global: true', function(assert) { 140 | config['ember-devtools'] = { 141 | enabled: true, 142 | global: true 143 | }; 144 | app = startApp(); 145 | visit('/'); 146 | andThen(function() { 147 | assert.ok(typeof window.routes === 'function'); 148 | }); 149 | }); 150 | 151 | test('global: foo', function(assert) { 152 | config['ember-devtools'] = { 153 | enabled: true, 154 | global: 'foo' 155 | }; 156 | app = startApp(); 157 | visit('/'); 158 | andThen(function() { 159 | assert.ok(typeof window.foo.routes === 'function'); 160 | }); 161 | }); 162 | 163 | 164 | test('legacy emberDevTools.global: true', function(assert) { 165 | app = startApp({emberDevTools: {global: true}}); 166 | visit('/'); 167 | andThen(function() { 168 | assert.ok(typeof window.routes === 'function'); 169 | }); 170 | }); 171 | 172 | test('legacy emberDevTools.global: foo', function(assert) { 173 | app = startApp({emberDevTools: {global: 'foo'}}); 174 | visit('/'); 175 | andThen(function() { 176 | assert.ok(typeof window.foo.routes === 'function'); 177 | }); 178 | }); 179 | 180 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import Resolver from './resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from './config/environment'; 5 | 6 | let App; 7 | 8 | Ember.MODEL_FACTORY_INJECTIONS = true; 9 | 10 | App = Ember.Application.extend({ 11 | modulePrefix: config.modulePrefix, 12 | podModulePrefix: config.podModulePrefix, 13 | devTools: Ember.inject.service('ember-devtools'), 14 | Resolver 15 | }); 16 | 17 | loadInitializers(App, config.modulePrefix); 18 | 19 | export default App; 20 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonexmachina/ember-devtools/6b28190278f0907eee56cee63f4bcde86e6a794c/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/components/test-component.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | export default Ember.Component.extend({ 3 | classNames: 'test-component' 4 | }); 5 | -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonexmachina/ember-devtools/6b28190278f0907eee56cee63f4bcde86e6a794c/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/controllers/foo.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | export default Ember.Controller; 4 | -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonexmachina/ember-devtools/6b28190278f0907eee56cee63f4bcde86e6a794c/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonexmachina/ember-devtools/6b28190278f0907eee56cee63f4bcde86e6a794c/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember-resolver'; 2 | 3 | export default Resolver; 4 | -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import config from './config/environment'; 3 | 4 | const Router = Ember.Router.extend({ 5 | location: config.locationType, 6 | rootURL: config.rootURL 7 | }); 8 | 9 | Router.map(function() { 10 | this.route('foo'); 11 | this.route('bar', {resetNamespace: true}, function() { 12 | this.route('baz'); 13 | this.route('nested', {resetNamespace: true}, function() { 14 | this.route('quz'); 15 | }); 16 | }); 17 | }); 18 | 19 | export default Router; 20 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonexmachina/ember-devtools/6b28190278f0907eee56cee63f4bcde86e6a794c/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/routes/bar.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | export default Ember.Route.extend({ 4 | model: function() { 5 | return 'bar'; 6 | } 7 | }); 8 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/foo.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | export default Ember.Route.extend({ 4 | model: function() { 5 | return 'foo'; 6 | } 7 | }); 8 | -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 20px; 3 | } 4 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 |

Welcome to Ember

2 | 3 | {{outlet}} -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonexmachina/ember-devtools/6b28190278f0907eee56cee63f4bcde86e6a794c/tests/dummy/app/templates/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/templates/foo.hbs: -------------------------------------------------------------------------------- 1 | {{test-component}} 2 | {{test-component}} 3 | -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 3 | module.exports = function(environment) { 4 | var ENV = { 5 | modulePrefix: 'dummy', 6 | environment: environment, 7 | rootURL: '/', 8 | locationType: 'auto', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. 'with-controller': true 13 | }, 14 | EXTEND_PROTOTYPES: { 15 | // Prevent Ember Data from overriding Date.parse. 16 | Date: false 17 | } 18 | }, 19 | 20 | APP: { 21 | // Here you can pass flags/options to your application instance 22 | // when it is created 23 | }, 24 | 25 | 'ember-devtools': { 26 | enabled: true, 27 | global: 'devTools' 28 | } 29 | }; 30 | 31 | if (environment === 'development') { 32 | // ENV.APP.LOG_RESOLVER = true; 33 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 34 | // ENV.APP.LOG_TRANSITIONS = true; 35 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 36 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 37 | } 38 | 39 | if (environment === 'test') { 40 | // Testem prefers this... 41 | ENV.locationType = 'none'; 42 | 43 | // keep test console output quieter 44 | ENV.APP.LOG_ACTIVE_GENERATION = false; 45 | ENV.APP.LOG_VIEW_LOOKUPS = false; 46 | 47 | ENV.APP.rootElement = '#ember-testing'; 48 | } 49 | 50 | if (environment === 'production') { 51 | 52 | } 53 | 54 | return ENV; 55 | }; 56 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 3 | module.exports = { 4 | browsers: [ 5 | 'ie 9', 6 | 'last 1 Chrome versions', 7 | 'last 1 Firefox versions', 8 | 'last 1 Safari versions' 9 | ] 10 | }; 11 | -------------------------------------------------------------------------------- /tests/dummy/public/crossdomain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/destroy-app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | export default function destroyApp(application) { 4 | Ember.run(application, 'destroy'); 5 | } 6 | -------------------------------------------------------------------------------- /tests/helpers/module-for-acceptance.js: -------------------------------------------------------------------------------- 1 | import { module } from 'qunit'; 2 | import Ember from 'ember'; 3 | import startApp from '../helpers/start-app'; 4 | import destroyApp from '../helpers/destroy-app'; 5 | 6 | const { RSVP: { Promise } } = Ember; 7 | 8 | export default function(name, options = {}) { 9 | module(name, { 10 | beforeEach() { 11 | this.application = startApp(); 12 | 13 | if (options.beforeEach) { 14 | return options.beforeEach.apply(this, arguments); 15 | } 16 | }, 17 | 18 | afterEach() { 19 | let afterEach = options.afterEach && options.afterEach.apply(this, arguments); 20 | return Promise.resolve(afterEach).then(() => destroyApp(this.application)); 21 | } 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /tests/helpers/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from '../../resolver'; 2 | import config from '../../config/environment'; 3 | 4 | const resolver = Resolver.create(); 5 | 6 | resolver.namespace = { 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix 9 | }; 10 | 11 | export default resolver; 12 | -------------------------------------------------------------------------------- /tests/helpers/start-app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import Application from '../../app'; 3 | import config from '../../config/environment'; 4 | 5 | export default function startApp(attrs) { 6 | let attributes = Ember.merge({}, config.APP); 7 | attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; 8 | 9 | return Ember.run(() => { 10 | let application = Application.create(attributes); 11 | application.setupForTesting(); 12 | application.injectTestHelpers(); 13 | return application; 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | {{content-for "test-head"}} 12 | 13 | 14 | 15 | 16 | 17 | {{content-for "head-footer"}} 18 | {{content-for "test-head-footer"}} 19 | 20 | 21 | {{content-for "body"}} 22 | {{content-for "test-body"}} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {{content-for "body-footer"}} 31 | {{content-for "test-body-footer"}} 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/integration/components/test-component-test.js: -------------------------------------------------------------------------------- 1 | import { moduleForComponent, test } from 'ember-qunit'; 2 | import hbs from 'htmlbars-inline-precompile'; 3 | 4 | moduleForComponent('test-component', 'Integration | Component | test component', { 5 | integration: true 6 | }); 7 | 8 | test('devTools saves the number of times that the component gets rendered', function(assert) { 9 | let devTools = this.container.lookup('service:ember-devtools'); 10 | 11 | devTools.logRenders(); 12 | 13 | this.render(hbs`{{test-component}}`); 14 | this.render(hbs` 15 | {{#test-component}} 16 | template block text 17 | {{/test-component}} 18 | `); 19 | 20 | assert.equal(devTools.get('renderedComponents.component:test-component.length'), 2); 21 | }); 22 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import resolver from './helpers/resolver'; 2 | import { 3 | setResolver 4 | } from 'ember-qunit'; 5 | import { start } from 'ember-cli-qunit'; 6 | 7 | setResolver(resolver); 8 | start(); 9 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonexmachina/ember-devtools/6b28190278f0907eee56cee63f4bcde86e6a794c/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/services/devtools-test.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import DS from 'ember-data'; 3 | import { 4 | moduleFor, 5 | test 6 | } from 'ember-qunit'; 7 | 8 | moduleFor('service:ember-devtools', 'DevtoolsService'); 9 | 10 | test('it exists', function(assert) { 11 | var service = this.subject(); 12 | assert.ok(service); 13 | }); 14 | 15 | test('log() resolves and logs the value', function(assert) { 16 | assert.expect(1); 17 | var called = false; 18 | var devTools = this.subject({ 19 | consoleLog: function(value) { 20 | called = value; 21 | } 22 | }); 23 | var promise = Ember.RSVP.resolve(true); 24 | devTools.log(promise).then(function() { 25 | assert.equal(called, true); 26 | }); 27 | }); 28 | 29 | test('log() resolves and logs a property', function(assert) { 30 | assert.expect(1); 31 | var called = false; 32 | var devTools = this.subject({ 33 | consoleLog: function(value) { 34 | called = value; 35 | } 36 | }); 37 | var promise = Ember.RSVP.resolve(Ember.Object.create({ 38 | foo: 'bar' 39 | })); 40 | devTools.log(promise, 'foo').then(function() { 41 | assert.equal(called, 'bar'); 42 | }); 43 | }); 44 | 45 | test('log() resolves and logs using getEach()', function(assert) { 46 | assert.expect(2); 47 | var called = false; 48 | var devTools = this.subject({ 49 | consoleLog: function(value) { 50 | called = value; 51 | } 52 | }); 53 | var promise = Ember.RSVP.resolve(Ember.A([{ 54 | foo: 'bar' 55 | }, { 56 | foo: 'baz' 57 | } 58 | ])); 59 | devTools.log(promise, 'foo', true).then(function() { 60 | assert.equal(called[0], 'bar'); 61 | assert.equal(called[1], 'baz'); 62 | }); 63 | }); 64 | 65 | test('lookup() returns instances', function(assert) { 66 | assert.ok(this.subject().lookup('service:store') instanceof DS.Store); 67 | }); 68 | 69 | test('inspect() is an alias to Ember.inspect', function(assert) { 70 | assert.ok(this.subject().inspect === Ember.inspect); 71 | }); 72 | 73 | test('globalize() attaches stuff to the global scope', function(assert) { 74 | var global = {}; 75 | var devTools = this.subject({ 76 | global: global 77 | }); 78 | devTools.globalize(); 79 | assert.ok(global.store === this.subject().store); 80 | }); 81 | 82 | test('globalize() doesn\'t stomp on pre-existing global vars', function(assert) { 83 | var global = {owner: 'foo'}; 84 | var devTools = this.subject({ 85 | global: global 86 | }); 87 | devTools.globalize(); 88 | assert.ok(global.owner !== this.subject().owner); 89 | }); 90 | --------------------------------------------------------------------------------