├── .editorconfig ├── .ember-cli ├── .eslintrc.js ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc.js ├── .template-lintrc.js ├── .travis.yml ├── .watchmanconfig ├── CHANGELOG.MD ├── LICENSE.md ├── README.md ├── addon ├── .gitkeep └── index.js ├── ember-cli-build.js ├── index.d.ts ├── index.js ├── jsconfig.json ├── package-lock.json ├── package.json ├── testem.js └── tests ├── dummy ├── app │ ├── app.js │ ├── components │ │ └── .gitkeep │ ├── controllers │ │ └── .gitkeep │ ├── helpers │ │ └── .gitkeep │ ├── index.html │ ├── models │ │ └── .gitkeep │ ├── router.js │ ├── routes │ │ └── .gitkeep │ ├── styles │ │ └── app.css │ └── templates │ │ └── application.hbs ├── config │ ├── ember-cli-update.json │ ├── environment.js │ ├── optional-features.json │ └── targets.js └── public │ └── robots.txt ├── index.html ├── integration └── .gitkeep ├── test-helper.js └── unit ├── .gitkeep └── index-test.js /.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 | [*.hbs] 17 | insert_final_newline = false 18 | 19 | [*.{diff,md}] 20 | trim_trailing_whitespace = false 21 | -------------------------------------------------------------------------------- /.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 | /** 11 | Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript 12 | rather than JavaScript by default, when a TypeScript version of a given blueprint is available. 13 | */ 14 | "isTypeScriptProject": false 15 | } 16 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | ecmaVersion: 2018, 8 | sourceType: 'module', 9 | ecmaFeatures: { 10 | legacyDecorators: true, 11 | }, 12 | }, 13 | plugins: ['ember'], 14 | extends: [ 15 | 'eslint:recommended', 16 | 'plugin:ember/recommended', 17 | 'plugin:prettier/recommended', 18 | ], 19 | env: { 20 | browser: true, 21 | }, 22 | rules: {}, 23 | overrides: [ 24 | // node files 25 | { 26 | files: [ 27 | 'index.js', 28 | 'testem.js', 29 | 'ember-cli-build.js', 30 | 'config/**/*.js', 31 | './.eslintrc.js', 32 | './.prettierrc.js', 33 | './.template-lintrc.js', 34 | './tests/dummy/config/**/*.js', 35 | ], 36 | excludedFiles: ['app/**', 'addon/**', 'tests/dummy/app/**'], 37 | parserOptions: { 38 | sourceType: 'script', 39 | }, 40 | env: { 41 | browser: false, 42 | node: true, 43 | }, 44 | plugins: ['node'], 45 | extends: ['plugin:node/recommended'], 46 | }, 47 | { 48 | // test files 49 | files: ['tests/**/*-test.{js,ts}'], 50 | extends: ['plugin:qunit/recommended'], 51 | }, 52 | ], 53 | }; 54 | -------------------------------------------------------------------------------- /.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 | /.env* 13 | /.pnp* 14 | /.sass-cache 15 | /.eslintcache 16 | /connect.lock 17 | /coverage/* 18 | /libpeerconnection.log 19 | npm-debug.log* 20 | yarn-error.log 21 | testem.log 22 | 23 | # ember-try 24 | /.node_modules.ember-try/ 25 | /bower.json.ember-try 26 | /npm-shrinkwrap.json.ember-try 27 | /package.json.ember-try 28 | /package-lock.json.ember-try 29 | /yarn.lock.ember-try 30 | 31 | # broccoli-debug 32 | /DEBUG/ 33 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist/ 3 | /tmp/ 4 | 5 | # dependencies 6 | /bower_components/ 7 | 8 | # misc 9 | /.bowerrc 10 | /.editorconfig 11 | /.ember-cli 12 | /.env* 13 | /.eslintcache 14 | /.eslintignore 15 | /.eslintrc.js 16 | /.git/ 17 | /.github/ 18 | /.gitignore 19 | /.prettierignore 20 | /.prettierrc.js 21 | /.template-lintrc.js 22 | /.travis.yml 23 | /.watchmanconfig 24 | /bower.json 25 | /config/ember-try.js 26 | /dist 27 | /tests 28 | /tmp 29 | **/.gitkeep 30 | .bowerrc 31 | .editorconfig 32 | .ember-cli 33 | .eslintrc.js 34 | .gitignore 35 | .watchmanconfig 36 | .travis.yml 37 | bower.json 38 | ember-cli-build.js 39 | testem.js 40 | /CONTRIBUTING.md 41 | /yarn-error.log 42 | /yarn.lock 43 | 44 | # ember-try 45 | /.node_modules.ember-try/ 46 | /bower.json.ember-try 47 | /npm-shrinkwrap.json.ember-try 48 | /package.json.ember-try 49 | /package-lock.json.ember-try 50 | /yarn.lock.ember-try 51 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | .eslintcache 17 | .lint-todo/ 18 | 19 | # ember-try 20 | /.node_modules.ember-try/ 21 | /bower.json.ember-try 22 | /npm-shrinkwrap.json.ember-try 23 | /package.json.ember-try 24 | /package-lock.json.ember-try 25 | /yarn.lock.ember-try 26 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | singleQuote: true, 5 | }; 6 | -------------------------------------------------------------------------------- /.template-lintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'recommended', 5 | }; 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | # we recommend testing addons with the same minimum supported node version as Ember CLI 5 | # so that your addon works for all apps 6 | - "4" 7 | 8 | sudo: false 9 | dist: trusty 10 | 11 | addons: 12 | chrome: stable 13 | 14 | cache: 15 | directories: 16 | - $HOME/.npm 17 | 18 | before_install: 19 | - npm config set spin false 20 | - npm install -g npm@4 21 | - npm --version 22 | 23 | script: 24 | - npm run lint:js 25 | - npm test 26 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.MD: -------------------------------------------------------------------------------- 1 | ## 3.0.0 (19 Sep 2024 (Thursday)) 2 | 3 | ### :boom: Breaking Change 4 | 5 | - Bump to `ember@4.x` [#164](https://github.com/rwjblue/ember-test-friendly-error-handler/pull/164) 6 | * Drop support for node version < 12 7 | * Drop support for ember-cli < 4.x 8 | * Drop support for ember-source < 4.x 9 | 10 | ### :house: Internal 11 | 12 | - Add repository to package.json [#163](https://github.com/rwjblue/ember-test-friendly-error-handler/pull/163) 13 | 14 | 15 | ### Committers: 2 16 | 17 | - Sparshith Nairbalige Rai ([SparshithNR ](https://github.com/SparshithNR)) 18 | - Zhongpeng Zhou ([v-zhzhou](https://github.com/v-zhzhou)) 19 | 20 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 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 | # ember-test-friendly-error-handler 2 | 3 | In production, you often want to catch certain types of errors such as network errors (e.g. `myModel.save().catch(() => this.showNetworkFailureMessage())`) however these kinds of generic catch handlers can wreak havoc on your tests. In tests, _most_ of the time you want these uncaught errors to _actually_ fail your tests unless explicitly testing the generic catch handler behaviors (e.g. `this.showNetworkFailureMessage`). 4 | 5 | ## Installation 6 | 7 | ember install ember-test-friendly-error-handler 8 | 9 | ## Usage 10 | 11 | In your application code you would import the error handler generator, and invoke it with a descriptive label and your callback. 12 | 13 | ### Ember.onerror 14 | 15 | `Ember.onerror` is a hook that is invoked when an error is thrown by any code 16 | within the Ember run loop (e.g. `{{action}}`'s, component event methods, model 17 | hooks, etc). In practice, this is nearly all of your application code. 18 | `Ember.onerror` has the ability to "swallow" errors by handling them without 19 | rethrowing, and ultimately making the failure scenario impossible to detect 20 | while testing. 21 | 22 | It is common for applications to leverage `Ember.onerror` to do error reporting 23 | and attempt to gracefully handle errors thrown within the application, and when 24 | possible prevent those errors from bubbling out and causing issues with the 25 | running application (or providing more detailed information when they do impact 26 | the app). 27 | 28 | Without something like `ember-test-friendly-error-handler`, applications that 29 | implement `Ember.onerror` either have to replicate this addon's behavior, or are 30 | unable to properly test both the "production" mode (eg error swallowing) and 31 | development/testing mode (eg re-throw errors to make them possible to track down 32 | and fix). 33 | 34 | Here is how an application might set this up: 35 | 36 | ```js 37 | // app/app.js 38 | import Ember from 'ember'; 39 | import buildErrorHandler from 'ember-test-friendly-error-handler'; 40 | 41 | Ember.onerror = buildErrorHandler('Ember.onerror', (reason) => { 42 | reportErrorToService(reason); 43 | // whatever else you might want here... 44 | }); 45 | // ...existing `app/app.js` content goes here... 46 | ``` 47 | 48 | ### Promises 49 | 50 | To generate a promise rejection handler (aka `.catch` handler) you might do something like: 51 | 52 | ```js 53 | import buildErrorHandler from 'ember-test-friendly-error-handler'; 54 | 55 | // ... snip ... 56 | myModel.save() 57 | .catch(buildErrorHandler('save-my-model', () => this.showNetworkFailureMessage())); 58 | ``` 59 | 60 | ### Testing 61 | 62 | When you need to test the generic handler behavior (`this.showNetworkFailureMessage()` above), you need to disable the automatic error re-throwing behavior that `ember-test-friendly-error-handler` provides you so that your test more closely resembles your production environment. 63 | 64 | A test that does this might look like: 65 | 66 | ```js 67 | import { module, test } from 'qunit'; 68 | import { 69 | squelchErrorHandlerFor, 70 | unsquelchAllErrorHandlers 71 | } from 'ember-test-friendly-error-handler'; 72 | 73 | module('some good description', { 74 | afterEach() { 75 | unsquelchAllErrorHandlers(); 76 | } 77 | }); 78 | 79 | test('network failure message is displayed', function(assert) { 80 | squelchErrorHandlerFor('save-my-model'); 81 | 82 | triggerNetworkFailure(); // ⚡️ 83 | return triggerModelSave() 84 | .then(() => { 85 | assertNetworkFailureShown(); // 😼 86 | }); 87 | }); 88 | ``` 89 | 90 | ## API 91 | 92 | The following interface describes the `ember-test-friendly-error-handler` module's API: 93 | 94 | ```ts 95 | export default function(label: string, callback: Function): Function; 96 | 97 | // the following are only present when testing 98 | export function squelchErrorHandlerFor(label: string): void; 99 | export function unsquelchAllErrorHandlers(): void; 100 | ``` 101 | 102 | ## Contributing 103 | 104 | ### Installation 105 | 106 | * `git clone ` this repository 107 | * `cd ember-test-friendly-error-handler` 108 | * `npm install` 109 | 110 | 111 | ### Running 112 | 113 | * `ember serve` 114 | * Visit your app at [http://localhost:4200](http://localhost:4200). 115 | 116 | ### Running Tests 117 | 118 | * `npm test` (Runs `ember try:each` to test your addon against multiple Ember versions) 119 | * `ember test` 120 | * `ember test --server` 121 | 122 | ### Building 123 | 124 | * `ember build` 125 | 126 | For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). 127 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/addon/.gitkeep -------------------------------------------------------------------------------- /addon/index.js: -------------------------------------------------------------------------------- 1 | import { resolve } from 'rsvp'; 2 | import { assert } from '@ember/debug'; 3 | import { DEBUG } from '@glimmer/env'; 4 | 5 | let squelchedLabels; 6 | 7 | export let squelchErrorHandlerFor = null; 8 | export let unsquelchAllErrorHandlers = null; 9 | 10 | if (DEBUG) { 11 | squelchedLabels = Object.create(null); 12 | 13 | squelchErrorHandlerFor = function squelchErrorHandlerFor(label) { 14 | squelchedLabels[label] = true; 15 | }; 16 | 17 | unsquelchAllErrorHandlers = function unsquelchAllErrorHandlers() { 18 | squelchedLabels = Object.create(null); 19 | }; 20 | } 21 | 22 | export default function (label, callback) { 23 | assert('ember-test-friendly-error-handler requires a label', label); 24 | if (!DEBUG) { 25 | return callback; 26 | } 27 | 28 | let lastReason; 29 | return function (reason) { 30 | // avoid reentrance and infinite async loops 31 | if (reason === lastReason) { 32 | lastReason = null; 33 | return; 34 | } 35 | 36 | lastReason = reason; 37 | 38 | // only call the callback when squelched 39 | if (squelchedLabels[label]) { 40 | return callback(reason); 41 | } 42 | 43 | // otherwise call the callback, and rethrow 44 | return resolve(callback(reason)).then(() => { 45 | throw reason; 46 | }); 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 4 | 5 | module.exports = function (defaults) { 6 | let app = new EmberAddon(defaults, { 7 | minifyJS: { enabled: false }, 8 | }); 9 | 10 | /* 11 | This build file specifies the options for the dummy test app of this 12 | addon, located in `/tests/dummy` 13 | This build file does *not* influence how the addon or the app using it 14 | behave. You most likely want to be modifying `./index.js` or app's build file 15 | */ 16 | 17 | const { maybeEmbroider } = require('@embroider/test-setup'); 18 | return maybeEmbroider(app, { 19 | skipBabel: [ 20 | { 21 | package: 'qunit', 22 | }, 23 | ], 24 | }); 25 | }; 26 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | // TODO: use `Return` when at TS 2.8. 2 | export default function buildErrorHandler(label: string, callback: (reason: any) => any): (reason: any) => any; 3 | 4 | export function squelchErrorHandlerFor(label: string): void; 5 | export function unsquelchAllErrorHandlers(): void; 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | name: require('./package').name, 5 | }; 6 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | {"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-test-friendly-error-handler", 3 | "version": "3.0.0", 4 | "description": "Build testable error handlers that don't throw in production...", 5 | "keywords": [ 6 | "ember-addon" 7 | ], 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/rwjblue/ember-test-friendly-error-handler.git" 11 | }, 12 | "license": "MIT", 13 | "contributors": [ 14 | "Robert Jackson ", 15 | "David J. Hamilton " 16 | ], 17 | "directories": { 18 | "doc": "doc", 19 | "test": "tests" 20 | }, 21 | "scripts": { 22 | "build": "ember build --environment=production", 23 | "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", 24 | "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix", 25 | "lint:hbs": "ember-template-lint .", 26 | "lint:hbs:fix": "ember-template-lint . --fix", 27 | "lint:js": "eslint . --cache", 28 | "lint:js:fix": "eslint . --fix", 29 | "start": "ember serve", 30 | "test": "ember test && ember test --environment=production" 31 | }, 32 | "dependencies": { 33 | "ember-cli-babel": "^7.26.11", 34 | "ember-cli-htmlbars": "^6.0.1" 35 | }, 36 | "devDependencies": { 37 | "@ember/optional-features": "^2.0.0", 38 | "@ember/test-helpers": "^2.7.0", 39 | "@embroider/test-setup": "^1.6.0", 40 | "@glimmer/component": "^1.1.2", 41 | "@glimmer/tracking": "^1.1.2", 42 | "babel-eslint": "^10.1.0", 43 | "broccoli-asset-rev": "^3.0.0", 44 | "ember-auto-import": "^2.4.1", 45 | "ember-cli": "~4.12.0", 46 | "ember-cli-dependency-checker": "^3.3.1", 47 | "ember-cli-inject-live-reload": "^2.1.0", 48 | "ember-cli-sri": "^2.1.1", 49 | "ember-cli-terser": "^4.0.2", 50 | "ember-disable-prototype-extensions": "^1.1.3", 51 | "ember-export-application-global": "^2.0.1", 52 | "ember-load-initializers": "^2.1.2", 53 | "ember-page-title": "^7.0.0", 54 | "ember-qunit": "^5.1.5", 55 | "ember-resolver": "^8.0.3", 56 | "ember-source": "~4.12.0", 57 | "ember-source-channel-url": "^3.0.0", 58 | "ember-template-lint": "^4.8.0", 59 | "ember-try": "^2.0.0", 60 | "eslint": "^7.32.0", 61 | "eslint-config-prettier": "^8.5.0", 62 | "eslint-plugin-ember": "^10.6.1", 63 | "eslint-plugin-node": "^11.1.0", 64 | "eslint-plugin-prettier": "^4.0.0", 65 | "eslint-plugin-qunit": "^7.2.0", 66 | "loader.js": "^4.7.0", 67 | "npm-run-all": "^4.1.5", 68 | "prettier": "^2.6.2", 69 | "qunit": "^2.19.1", 70 | "qunit-dom": "^3.2.0", 71 | "webpack": "^5.72.1" 72 | }, 73 | "engines": { 74 | "node": "12.* || 14.* || >= 16" 75 | }, 76 | "ember": { 77 | "edition": "octane" 78 | }, 79 | "ember-addon": { 80 | "configPath": "tests/dummy/config" 81 | }, 82 | "volta": { 83 | "node": "16.20.2" 84 | } 85 | } -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | test_page: 'tests/index.html?hidepassed', 5 | disable_watching: true, 6 | launch_in_ci: ['Chrome'], 7 | launch_in_dev: ['Chrome'], 8 | browser_start_timeout: 120, 9 | browser_args: { 10 | Chrome: { 11 | mode: 'ci', 12 | args: [ 13 | // --no-sandbox is needed when running Chrome inside a container 14 | process.env.TRAVIS ? '--no-sandbox' : null, 15 | 16 | '--disable-gpu', 17 | '--headless', 18 | '--remote-debugging-port=0', 19 | '--window-size=1440,900', 20 | ].filter(Boolean), 21 | }, 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Application from '@ember/application'; 2 | import Resolver from 'ember-resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from 'dummy/config/environment'; 5 | 6 | export default class App extends Application { 7 | modulePrefix = config.modulePrefix; 8 | podModulePrefix = config.podModulePrefix; 9 | Resolver = Resolver; 10 | } 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Dummy 6 | 7 | 8 | 9 | {{content-for "head"}} 10 | 11 | 12 | 13 | 14 | {{content-for "head-footer"}} 15 | 16 | 17 | {{content-for "body"}} 18 | 19 | 20 | 21 | 22 | {{content-for "body-footer"}} 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import EmberRouter from '@ember/routing/router'; 2 | import config from 'dummy/config/environment'; 3 | 4 | export default class Router extends EmberRouter { 5 | location = config.locationType; 6 | rootURL = config.rootURL; 7 | } 8 | 9 | Router.map(function () {}); 10 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/tests/dummy/app/styles/app.css -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 | {{page-title "Dummy"}} 2 | 3 |

Welcome to Ember

4 | 5 | {{outlet}} -------------------------------------------------------------------------------- /tests/dummy/config/ember-cli-update.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": "1.0.0", 3 | "packages": [ 4 | { 5 | "name": "ember-cli", 6 | "version": "4.4.1", 7 | "blueprints": [ 8 | { 9 | "name": "addon", 10 | "outputRepo": "https://github.com/ember-cli/ember-addon-output", 11 | "codemodsSource": "ember-addon-codemods-manifest@1", 12 | "isBaseBlueprint": true, 13 | "options": [ 14 | "--no-welcome" 15 | ] 16 | } 17 | ] 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function (environment) { 4 | let ENV = { 5 | modulePrefix: 'dummy', 6 | environment, 7 | rootURL: '/', 8 | locationType: 'history', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. EMBER_NATIVE_DECORATOR_SUPPORT: 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 | 26 | if (environment === 'development') { 27 | // ENV.APP.LOG_RESOLVER = true; 28 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 29 | // ENV.APP.LOG_TRANSITIONS = true; 30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 31 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 32 | } 33 | 34 | if (environment === 'test') { 35 | // Testem prefers this... 36 | ENV.locationType = 'none'; 37 | 38 | // keep test console output quieter 39 | ENV.APP.LOG_ACTIVE_GENERATION = false; 40 | ENV.APP.LOG_VIEW_LOOKUPS = false; 41 | 42 | ENV.APP.rootElement = '#ember-testing'; 43 | ENV.APP.autoboot = false; 44 | } 45 | 46 | if (environment === 'production') { 47 | // here you can enable a production-specific feature 48 | } 49 | 50 | return ENV; 51 | }; 52 | -------------------------------------------------------------------------------- /tests/dummy/config/optional-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "application-template-wrapper": false, 3 | "default-async-observers": true, 4 | "jquery-integration": false, 5 | "template-only-glimmer-components": true 6 | } 7 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browsers = [ 4 | 'last 1 Chrome versions', 5 | 'last 1 Firefox versions', 6 | 'last 1 Safari versions', 7 | ]; 8 | 9 | const isCI = !!process.env.CI; 10 | const isProduction = process.env.EMBER_ENV === 'production'; 11 | 12 | if (isCI || isProduction) { 13 | browsers.push('ie 11'); 14 | } 15 | 16 | module.exports = { 17 | browsers, 18 | }; 19 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Dummy Tests 6 | 7 | 8 | 9 | {{content-for "head"}} 10 | {{content-for "test-head"}} 11 | 12 | 13 | 14 | 15 | 16 | {{content-for "head-footer"}} 17 | {{content-for "test-head-footer"}} 18 | 19 | 20 | {{content-for "body"}} 21 | {{content-for "test-body"}} 22 | 23 |
24 |
25 |
26 |
27 |
28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | {{content-for "body-footer"}} 37 | {{content-for "test-body-footer"}} 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/integration/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/tests/integration/.gitkeep -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from 'dummy/app'; 2 | import config from 'dummy/config/environment'; 3 | import * as QUnit from 'qunit'; 4 | import { setApplication } from '@ember/test-helpers'; 5 | import { setup } from 'qunit-dom'; 6 | import { start } from 'ember-qunit'; 7 | 8 | setApplication(Application.create(config.APP)); 9 | 10 | setup(QUnit.assert); 11 | 12 | start(); 13 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwjblue/ember-test-friendly-error-handler/70fc6fd1924b3f290d5503380c548a2bd6d1b373/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/index-test.js: -------------------------------------------------------------------------------- 1 | import { Promise } from 'rsvp'; 2 | import { test, module } from 'qunit'; 3 | import { DEBUG } from '@glimmer/env'; 4 | import buildErrorHandler, { 5 | squelchErrorHandlerFor, 6 | unsquelchAllErrorHandlers, 7 | } from 'ember-test-friendly-error-handler'; 8 | import Ember from 'ember'; 9 | import { next } from '@ember/runloop'; 10 | 11 | module('ember-test-friendly-error-handler', function () { 12 | module('in both debug and prod', function (hooks) { 13 | hooks.afterEach(() => { 14 | Ember.onerror = undefined; 15 | }); 16 | 17 | // eslint-disable-next-line 18 | test('Ember.onerror does not re-enter', function (assert) { 19 | assert.expect(1); 20 | let done = assert.async(); 21 | 22 | let rejectionReason = {}; 23 | function handler(reason) { 24 | assert.strictEqual( 25 | reason, 26 | rejectionReason, 27 | 'expected rejection reason was passed to callback' 28 | ); 29 | } 30 | 31 | Ember.onerror = buildErrorHandler('Ember.onerror', handler); 32 | 33 | next(() => { 34 | // throwing in a run-wrapped function will hit the Ember.onerror defined just above 35 | throw rejectionReason; 36 | }); 37 | 38 | // ensure we wait long enough for the run.next to complete 39 | setTimeout(done, 10); 40 | }); 41 | }); 42 | 43 | module('in debug', function (hooks) { 44 | if (!DEBUG) { 45 | return; 46 | } 47 | 48 | hooks.afterEach(() => { 49 | unsquelchAllErrorHandlers(); 50 | }); 51 | 52 | test('it calls the provided callback and rethrows the rejection', function (assert) { 53 | assert.expect(2); 54 | 55 | let rejectionReason = {}; 56 | function handler(reason) { 57 | assert.strictEqual( 58 | reason, 59 | rejectionReason, 60 | 'expected rejection reason was passed to callback' 61 | ); 62 | } 63 | 64 | return Promise.reject(rejectionReason) 65 | .catch(buildErrorHandler('label-here', handler)) 66 | .then(() => { 67 | assert.notOk(true, 'should have rejected'); 68 | }) 69 | .catch((reason) => { 70 | assert.strictEqual( 71 | reason, 72 | rejectionReason, 73 | 'expected rejection reason was thrown' 74 | ); 75 | }); 76 | }); 77 | 78 | test('requires label', function (assert) { 79 | assert.throws( 80 | () => buildErrorHandler(null, () => {}), 81 | /requires a label/ 82 | ); 83 | }); 84 | 85 | test('squelchErrorHandlerFor allows testing without rethrowing', function (assert) { 86 | assert.expect(2); 87 | 88 | squelchErrorHandlerFor('some-label-here'); 89 | 90 | let rejectionReason = {}; 91 | function handler(reason) { 92 | assert.strictEqual( 93 | reason, 94 | rejectionReason, 95 | 'expected rejection reason was passed to callback' 96 | ); 97 | } 98 | 99 | return Promise.reject(rejectionReason) 100 | .catch(buildErrorHandler('some-label-here', handler)) 101 | .then(() => { 102 | assert.ok(true, 'does not reject'); 103 | }); 104 | }); 105 | 106 | test('squelched handlers can be cleared', function (assert) { 107 | assert.expect(2); 108 | 109 | squelchErrorHandlerFor('some-label-here'); 110 | unsquelchAllErrorHandlers(); 111 | 112 | let rejectionReason = {}; 113 | function handler(reason) { 114 | assert.strictEqual( 115 | reason, 116 | rejectionReason, 117 | 'expected rejection reason was passed to callback' 118 | ); 119 | } 120 | 121 | return Promise.reject(rejectionReason) 122 | .catch(buildErrorHandler('some-label-here', handler)) 123 | .then(() => { 124 | assert.notOk(true, 'should have rejected'); 125 | }) 126 | .catch((reason) => { 127 | assert.strictEqual( 128 | reason, 129 | rejectionReason, 130 | 'expected rejection reason was thrown' 131 | ); 132 | }); 133 | }); 134 | }); 135 | 136 | module('in prod', function () { 137 | if (DEBUG) { 138 | return; 139 | } 140 | 141 | test('it calls the provided callback', function (assert) { 142 | assert.expect(1); 143 | let rejectionReason = {}; 144 | function handler(reason) { 145 | assert.strictEqual( 146 | reason, 147 | rejectionReason, 148 | 'expected rejection reason was passed to callback' 149 | ); 150 | } 151 | 152 | return Promise.reject(rejectionReason).catch( 153 | buildErrorHandler('some-thing', handler) 154 | ); 155 | }); 156 | 157 | test('handler can decide to throw (who knows why)', function (assert) { 158 | assert.expect(1); 159 | let rejectionReason = {}; 160 | function handler() { 161 | throw rejectionReason; 162 | } 163 | 164 | return Promise.reject('derp') 165 | .catch(buildErrorHandler('lol', handler)) 166 | .catch((reason) => { 167 | assert.strictEqual( 168 | reason, 169 | rejectionReason, 170 | 'expected rejection reason was thrown' 171 | ); 172 | }); 173 | }); 174 | }); 175 | }); 176 | --------------------------------------------------------------------------------