From 2bc550e9bd610ab5f4b36f6503d324522f6971e7 Mon Sep 17 00:00:00 2001 From: Tomster Date: Wed, 1 Nov 2017 22:15:43 -0400 Subject: [PATCH] Initial implementation --- .editorconfig | 20 +++++ .ember-cli | 9 ++ .eslintrc.js | 13 +++ .gitignore | 23 +++++ .npmignore | 16 ++++ .travis.yml | 41 +++++++++ .watchmanconfig | 3 + LICENSE.md | 9 ++ README.md | 26 ++++++ addon/services/online-status.js | 34 ++++++++ app/services/online-status.js | 1 + config/ember-try.js | 83 +++++++++++++++++++ config/environment.js | 6 ++ ember-cli-build.js | 11 +++ index.js | 6 ++ package.json | 60 ++++++++++++++ testem.js | 19 +++++ tests/.eslintrc.js | 5 ++ tests/dummy/app/app.js | 14 ++++ tests/dummy/app/components/.gitkeep | 0 tests/dummy/app/controllers/.gitkeep | 0 tests/dummy/app/controllers/index.js | 7 ++ tests/dummy/app/helpers/.gitkeep | 0 tests/dummy/app/index.html | 29 +++++++ tests/dummy/app/models/.gitkeep | 0 tests/dummy/app/resolver.js | 3 + tests/dummy/app/router.js | 12 +++ tests/dummy/app/routes/.gitkeep | 0 tests/dummy/app/styles/app.css | 3 + tests/dummy/app/templates/application.hbs | 4 + tests/dummy/app/templates/components/.gitkeep | 0 tests/dummy/app/templates/index.hbs | 17 ++++ tests/dummy/config/environment.js | 59 +++++++++++++ tests/dummy/config/targets.js | 9 ++ tests/dummy/public/crossdomain.xml | 15 ++++ tests/dummy/public/robots.txt | 3 + tests/helpers/destroy-app.js | 5 ++ tests/helpers/module-for-acceptance.js | 23 +++++ tests/helpers/resolver.js | 11 +++ tests/helpers/start-app.js | 15 ++++ tests/index.html | 33 ++++++++ tests/test-helper.js | 4 + tests/unit/.gitkeep | 0 vendor/.gitkeep | 0 44 files changed, 651 insertions(+) create mode 100644 .editorconfig create mode 100644 .ember-cli create mode 100644 .eslintrc.js create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 .travis.yml create mode 100644 .watchmanconfig create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 addon/services/online-status.js create mode 100644 app/services/online-status.js create mode 100644 config/ember-try.js create mode 100644 config/environment.js create mode 100644 ember-cli-build.js create mode 100644 index.js create mode 100644 package.json create mode 100644 testem.js create mode 100644 tests/.eslintrc.js create mode 100644 tests/dummy/app/app.js create mode 100644 tests/dummy/app/components/.gitkeep create mode 100644 tests/dummy/app/controllers/.gitkeep create mode 100644 tests/dummy/app/controllers/index.js create mode 100644 tests/dummy/app/helpers/.gitkeep create mode 100644 tests/dummy/app/index.html create mode 100644 tests/dummy/app/models/.gitkeep create mode 100644 tests/dummy/app/resolver.js create mode 100644 tests/dummy/app/router.js create mode 100644 tests/dummy/app/routes/.gitkeep create mode 100644 tests/dummy/app/styles/app.css create mode 100644 tests/dummy/app/templates/application.hbs create mode 100644 tests/dummy/app/templates/components/.gitkeep create mode 100644 tests/dummy/app/templates/index.hbs create mode 100644 tests/dummy/config/environment.js create mode 100644 tests/dummy/config/targets.js create mode 100644 tests/dummy/public/crossdomain.xml create mode 100644 tests/dummy/public/robots.txt create mode 100644 tests/helpers/destroy-app.js create mode 100644 tests/helpers/module-for-acceptance.js create mode 100644 tests/helpers/resolver.js create mode 100644 tests/helpers/start-app.js create mode 100644 tests/index.html create mode 100644 tests/test-helper.js create mode 100644 tests/unit/.gitkeep create mode 100644 vendor/.gitkeep diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..219985c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.hbs] +insert_final_newline = false + +[*.{diff,md}] +trim_trailing_whitespace = false diff --git a/.ember-cli b/.ember-cli new file mode 100644 index 0000000..ee64cfe --- /dev/null +++ b/.ember-cli @@ -0,0 +1,9 @@ +{ + /** + Ember CLI sends analytics information by default. The data is completely + anonymous, but there are times when you might want to disable this behavior. + + Setting `disableAnalytics` to true will prevent any data from being sent. + */ + "disableAnalytics": false +} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..2873e2f --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,13 @@ +module.exports = { + root: true, + parserOptions: { + ecmaVersion: 2017, + sourceType: 'module' + }, + extends: 'eslint:recommended', + env: { + browser: true + }, + rules: { + } +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fa39a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp + +# dependencies +/node_modules +/bower_components + +# misc +/.sass-cache +/connect.lock +/coverage/* +/libpeerconnection.log +npm-debug.log* +yarn-error.log +testem.log + +# ember-try +.node_modules.ember-try/ +bower.json.ember-try +package.json.ember-try diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..889b2bf --- /dev/null +++ b/.npmignore @@ -0,0 +1,16 @@ +/bower_components +/config/ember-try.js +/dist +/tests +/tmp +**/.gitkeep +.bowerrc +.editorconfig +.ember-cli +.gitignore +.eslintrc.js +.watchmanconfig +.travis.yml +bower.json +ember-cli-build.js +testem.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d04ff8a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,41 @@ +--- +language: node_js +node_js: + # we recommend testing addons with the same minimum supported node version as Ember CLI + # so that your addon works for all apps + - "4" + +sudo: false +dist: trusty + +addons: + chrome: stable + +cache: + directories: + - $HOME/.npm + +env: + # we recommend new addons test the current and previous LTS + # as well as latest stable release (bonus points to beta/canary) + - EMBER_TRY_SCENARIO=ember-lts-2.8 + - EMBER_TRY_SCENARIO=ember-lts-2.12 + - EMBER_TRY_SCENARIO=ember-release + - EMBER_TRY_SCENARIO=ember-beta + - EMBER_TRY_SCENARIO=ember-canary + - EMBER_TRY_SCENARIO=ember-default + +matrix: + fast_finish: true + allow_failures: + - env: EMBER_TRY_SCENARIO=ember-canary + +before_install: + - npm config set spin false + - npm install -g npm@4 + - npm --version + +script: + # Usually, it's ok to finish the test scenario without reverting + # to the addon's original dependency state, skipping "cleanup". + - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup diff --git a/.watchmanconfig b/.watchmanconfig new file mode 100644 index 0000000..e7834e3 --- /dev/null +++ b/.watchmanconfig @@ -0,0 +1,3 @@ +{ + "ignore_dirs": ["tmp", "dist"] +} diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0d5e3ef --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2017 + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5467e72 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# ember-online-status + +This README outlines the details of collaborating on this Ember addon. + +## Installation + +* `git clone ` this repository +* `cd ember-online-status` +* `npm install` + +## Running + +* `ember serve` +* Visit your app at [http://localhost:4200](http://localhost:4200). + +## Running Tests + +* `npm test` (Runs `ember try:each` to test your addon against multiple Ember versions) +* `ember test` +* `ember test --server` + +## Building + +* `ember build` + +For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). diff --git a/addon/services/online-status.js b/addon/services/online-status.js new file mode 100644 index 0000000..522dec5 --- /dev/null +++ b/addon/services/online-status.js @@ -0,0 +1,34 @@ +import Ember from 'ember'; +import _isOnline from 'npm:is-online'; + +export default Ember.Service.extend({ + config: Ember.inject.service(), + isOnline: false, + isCheckingConnection: true, + timeout: Ember.computed.alias('config.onlineStatus.timeout'), + version: Ember.computed.alias('config.onlineStatus.version'), + interval: Ember.computed.alias('config.onlineStatus.pollInterval'), + setup: Ember.on('init', function () { + const connectionStatus = () => { + this.set('isCheckingConnection', true); + const params = { + timeout: this.get('timeout') || 5000, + version: this.get('version') || 'v4' + }; + + _isOnline(params).then((online) => { + this.set('isOnline', online); + this.set('isCheckingConnection', false); + + Ember.run.later(this, function () { + connectionStatus() + }, this.get('interval') || 15000); + }); + }; + connectionStatus(); + + window.addEventListener('offline', () => { + this.set('isOnline', false); + }); + }) +}); diff --git a/app/services/online-status.js b/app/services/online-status.js new file mode 100644 index 0000000..5022ee1 --- /dev/null +++ b/app/services/online-status.js @@ -0,0 +1 @@ +export { default } from 'ember-online-status/services/online-status'; diff --git a/config/ember-try.js b/config/ember-try.js new file mode 100644 index 0000000..21f6079 --- /dev/null +++ b/config/ember-try.js @@ -0,0 +1,83 @@ +/* eslint-env node */ +module.exports = { + scenarios: [ + { + name: 'ember-lts-2.8', + bower: { + dependencies: { + 'ember': 'components/ember#lts-2-8' + }, + resolutions: { + 'ember': 'lts-2-8' + } + }, + npm: { + devDependencies: { + 'ember-source': null + } + } + }, + { + name: 'ember-lts-2.12', + npm: { + devDependencies: { + 'ember-source': '~2.12.0' + } + } + }, + { + name: 'ember-release', + bower: { + dependencies: { + 'ember': 'components/ember#release' + }, + resolutions: { + 'ember': 'release' + } + }, + npm: { + devDependencies: { + 'ember-source': null + } + } + }, + { + name: 'ember-beta', + bower: { + dependencies: { + 'ember': 'components/ember#beta' + }, + resolutions: { + 'ember': 'beta' + } + }, + npm: { + devDependencies: { + 'ember-source': null + } + } + }, + { + name: 'ember-canary', + bower: { + dependencies: { + 'ember': 'components/ember#canary' + }, + resolutions: { + 'ember': 'canary' + } + }, + npm: { + devDependencies: { + 'ember-source': null + } + } + }, + { + name: 'ember-default', + npm: { + devDependencies: {} + } + } + ] +}; diff --git a/config/environment.js b/config/environment.js new file mode 100644 index 0000000..012a412 --- /dev/null +++ b/config/environment.js @@ -0,0 +1,6 @@ +/* eslint-env node */ +'use strict'; + +module.exports = function(/* environment, appConfig */) { + return { }; +}; diff --git a/ember-cli-build.js b/ember-cli-build.js new file mode 100644 index 0000000..9052005 --- /dev/null +++ b/ember-cli-build.js @@ -0,0 +1,11 @@ +/* eslint-env node */ +'use strict'; + +const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); + +module.exports = function(defaults) { + let app = new EmberAddon(defaults, { + snippetSearchPaths: ['tests/dummy/app', 'tests/dummy/config'] + }); + return app.toTree(); +}; diff --git a/index.js b/index.js new file mode 100644 index 0000000..680fc78 --- /dev/null +++ b/index.js @@ -0,0 +1,6 @@ +/* eslint-env node */ +'use strict'; + +module.exports = { + name: 'ember-online-status' +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..13b00b0 --- /dev/null +++ b/package.json @@ -0,0 +1,60 @@ +{ + "name": "ember-online-status", + "version": "1.0.0", + "description": "Ember addon for checking if Internet connection is up", + "keywords": [ + "ember-addon" + ], + "license": "MIT", + "author": "Adam Ward", + "directories": { + "doc": "doc", + "test": "tests" + }, + "repository": "", + "scripts": { + "build": "ember build", + "start": "ember server", + "test": "ember try:each" + }, + "dependencies": { + "ember-browserify": "^1.2.0", + "ember-cli-babel": "^6.3.0", + "is-online": "^7.0.0" + }, + "devDependencies": { + "broccoli-asset-rev": "^2.4.5", + "chai-jquery": "^2.0.0", + "ember-ajax": "^3.0.0", + "ember-cli": "~2.15.0", + "ember-cli-chai": "^0.4.3", + "ember-cli-dependency-checker": "^2.0.0", + "ember-cli-eslint": "^4.0.0", + "ember-cli-htmlbars": "^2.0.1", + "ember-cli-htmlbars-inline-precompile": "^1.0.0", + "ember-cli-inject-live-reload": "^1.4.1", + "ember-cli-mocha": "^0.14.4", + "ember-cli-shims": "^1.1.0", + "ember-cli-sri": "^2.1.0", + "ember-cli-uglify": "^1.2.0", + "ember-code-snippet": "^2.0.0", + "ember-config-service": "^0.1.7", + "ember-disable-prototype-extensions": "^1.1.2", + "ember-export-application-global": "^2.0.0", + "ember-load-initializers": "^1.0.0", + "ember-mocha": "^0.12.0", + "ember-promise-helpers": "^1.0.3", + "ember-resolver": "^4.0.0", + "ember-sinon": "^1.0.1", + "ember-source": "~2.15.0", + "ember-test-utils": "^6.0.0", + "loader.js": "^4.2.3", + "sinon-chai": "^2.14.0" + }, + "engines": { + "node": "^4.5 || 6.* || >= 7.*" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + } +} diff --git a/testem.js b/testem.js new file mode 100644 index 0000000..a40a530 --- /dev/null +++ b/testem.js @@ -0,0 +1,19 @@ +/* eslint-env node */ +module.exports = { + test_page: 'tests/index.html?hidepassed', + disable_watching: true, + launch_in_ci: [ + 'Chrome' + ], + launch_in_dev: [ + 'Chrome' + ], + browser_args: { + Chrome: [ + '--disable-gpu', + '--headless', + '--remote-debugging-port=9222', + '--window-size=1440,900' + ] + } +}; diff --git a/tests/.eslintrc.js b/tests/.eslintrc.js new file mode 100644 index 0000000..fbf2555 --- /dev/null +++ b/tests/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + env: { + embertest: true + } +}; diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js new file mode 100644 index 0000000..c15f935 --- /dev/null +++ b/tests/dummy/app/app.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; +import Resolver from './resolver'; +import loadInitializers from 'ember-load-initializers'; +import config from './config/environment'; + +const App = Ember.Application.extend({ + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix, + Resolver +}); + +loadInitializers(App, config.modulePrefix); + +export default App; diff --git a/tests/dummy/app/components/.gitkeep b/tests/dummy/app/components/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/controllers/.gitkeep b/tests/dummy/app/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/controllers/index.js b/tests/dummy/app/controllers/index.js new file mode 100644 index 0000000..d57c39b --- /dev/null +++ b/tests/dummy/app/controllers/index.js @@ -0,0 +1,7 @@ +// BEGIN-SNIPPET controller-example +import Ember from 'ember'; + +export default Ember.Controller.extend({ + onlineStatus: Ember.inject.service() +}); +// END-SNIPPET diff --git a/tests/dummy/app/helpers/.gitkeep b/tests/dummy/app/helpers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/index.html b/tests/dummy/app/index.html new file mode 100644 index 0000000..3bc4b9e --- /dev/null +++ b/tests/dummy/app/index.html @@ -0,0 +1,29 @@ + + + + + + ember-online-status + + + + {{content-for "head"}} + + + + + + + {{content-for "head-footer"}} + + + {{content-for "body"}} + + + + + + + {{content-for "body-footer"}} + + diff --git a/tests/dummy/app/models/.gitkeep b/tests/dummy/app/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/resolver.js b/tests/dummy/app/resolver.js new file mode 100644 index 0000000..2fb563d --- /dev/null +++ b/tests/dummy/app/resolver.js @@ -0,0 +1,3 @@ +import Resolver from 'ember-resolver'; + +export default Resolver; diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js new file mode 100644 index 0000000..cdc2578 --- /dev/null +++ b/tests/dummy/app/router.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import config from './config/environment'; + +const Router = Ember.Router.extend({ + location: config.locationType, + rootURL: config.rootURL +}); + +Router.map(function() { +}); + +export default Router; diff --git a/tests/dummy/app/routes/.gitkeep b/tests/dummy/app/routes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css new file mode 100644 index 0000000..e472c01 --- /dev/null +++ b/tests/dummy/app/styles/app.css @@ -0,0 +1,3 @@ +.demo { + margin: 15px; +} diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs new file mode 100644 index 0000000..b8bf226 --- /dev/null +++ b/tests/dummy/app/templates/application.hbs @@ -0,0 +1,4 @@ +
+

ember-online-status Live Demo

+ {{outlet}} +
diff --git a/tests/dummy/app/templates/components/.gitkeep b/tests/dummy/app/templates/components/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs new file mode 100644 index 0000000..8eda5a0 --- /dev/null +++ b/tests/dummy/app/templates/index.hbs @@ -0,0 +1,17 @@ +

Controller

+{{code-snippet name='controller-example.js'}} +

Template

+{{code-snippet name='template-example.hbs'}} +

Environment Configuration

+{{code-snippet name='environment-example.js'}} +{{!-- BEGIN-SNIPPET template-example --}} +{{#if onlineStatus.isCheckingConnection}} +
Checking connection...
+{{else}} + {{#if onlineStatus.isOnline}} +
Online
+ {{else}} +
Offline
+ {{/if}} +{{/if}} +{{!-- END-SNIPPET --}} diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js new file mode 100644 index 0000000..7447e51 --- /dev/null +++ b/tests/dummy/config/environment.js @@ -0,0 +1,59 @@ +/* eslint-env node */ +'use strict'; + +module.exports = function(environment) { + let ENV = { + modulePrefix: 'dummy', + environment, + rootURL: '/', + locationType: 'auto', + EmberENV: { + 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 + } + }, + + APP: { + // Here you can pass flags/options to your application instance + // when it is created + } + }; + + if (environment === 'development') { + // ENV.APP.LOG_RESOLVER = true; + // ENV.APP.LOG_ACTIVE_GENERATION = true; + // ENV.APP.LOG_TRANSITIONS = true; + // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; + // ENV.APP.LOG_VIEW_LOOKUPS = true; + } + + if (environment === 'test') { + // Testem prefers this... + ENV.locationType = 'none'; + + // keep test console output quieter + ENV.APP.LOG_ACTIVE_GENERATION = false; + ENV.APP.LOG_VIEW_LOOKUPS = false; + + ENV.APP.rootElement = '#ember-testing'; + } + + if (environment === 'production') { + + } + + // BEGIN-SNIPPET environment-example + ENV.onlineStatus = { + version: 'v4', + pollInterval: 5000, + timeout: 2500 + }; + // END-SNIPPET + + return ENV; +}; diff --git a/tests/dummy/config/targets.js b/tests/dummy/config/targets.js new file mode 100644 index 0000000..df7664c --- /dev/null +++ b/tests/dummy/config/targets.js @@ -0,0 +1,9 @@ +/* eslint-env node */ +module.exports = { + browsers: [ + 'ie 9', + 'last 1 Chrome versions', + 'last 1 Firefox versions', + 'last 1 Safari versions' + ] +}; diff --git a/tests/dummy/public/crossdomain.xml b/tests/dummy/public/crossdomain.xml new file mode 100644 index 0000000..0c16a7a --- /dev/null +++ b/tests/dummy/public/crossdomain.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/tests/dummy/public/robots.txt b/tests/dummy/public/robots.txt new file mode 100644 index 0000000..f591645 --- /dev/null +++ b/tests/dummy/public/robots.txt @@ -0,0 +1,3 @@ +# http://www.robotstxt.org +User-agent: * +Disallow: diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js new file mode 100644 index 0000000..c3d4d1a --- /dev/null +++ b/tests/helpers/destroy-app.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default function destroyApp(application) { + Ember.run(application, 'destroy'); +} diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js new file mode 100644 index 0000000..5a1a583 --- /dev/null +++ b/tests/helpers/module-for-acceptance.js @@ -0,0 +1,23 @@ +import { module } from 'qunit'; +import Ember from 'ember'; +import startApp from '../helpers/start-app'; +import destroyApp from '../helpers/destroy-app'; + +const { RSVP: { resolve } } = Ember; + +export default function(name, options = {}) { + module(name, { + beforeEach() { + this.application = startApp(); + + if (options.beforeEach) { + return options.beforeEach.apply(this, arguments); + } + }, + + afterEach() { + let afterEach = options.afterEach && options.afterEach.apply(this, arguments); + return resolve(afterEach).then(() => destroyApp(this.application)); + } + }); +} diff --git a/tests/helpers/resolver.js b/tests/helpers/resolver.js new file mode 100644 index 0000000..b208d38 --- /dev/null +++ b/tests/helpers/resolver.js @@ -0,0 +1,11 @@ +import Resolver from '../../resolver'; +import config from '../../config/environment'; + +const resolver = Resolver.create(); + +resolver.namespace = { + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix +}; + +export default resolver; diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js new file mode 100644 index 0000000..9a605eb --- /dev/null +++ b/tests/helpers/start-app.js @@ -0,0 +1,15 @@ +import Ember from 'ember'; +import Application from '../../app'; +import config from '../../config/environment'; + +export default function startApp(attrs) { + let attributes = Ember.merge({}, config.APP); + attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; + + return Ember.run(() => { + let application = Application.create(attributes); + application.setupForTesting(); + application.injectTestHelpers(); + return application; + }); +} diff --git a/tests/index.html b/tests/index.html new file mode 100644 index 0000000..5209b85 --- /dev/null +++ b/tests/index.html @@ -0,0 +1,33 @@ + + + + + + Dummy Tests + + + + {{content-for "head"}} + {{content-for "test-head"}} + + + + + + {{content-for "head-footer"}} + {{content-for "test-head-footer"}} + + + {{content-for "body"}} + {{content-for "test-body"}} + + + + + + + + {{content-for "body-footer"}} + {{content-for "test-body-footer"}} + + diff --git a/tests/test-helper.js b/tests/test-helper.js new file mode 100644 index 0000000..bbe42fa --- /dev/null +++ b/tests/test-helper.js @@ -0,0 +1,4 @@ +import resolver from './helpers/resolver'; +import { setResolver } from 'ember-mocha'; + +setResolver(resolver); diff --git a/tests/unit/.gitkeep b/tests/unit/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/.gitkeep b/vendor/.gitkeep new file mode 100644 index 0000000..e69de29