Code Monkey home page Code Monkey logo

ember-cli-pretender's Introduction

ember-cli-pretender

Simple wrapper for pretender.js, this project removes the need for the developer to know which files need to be imported.

NOTE: Please use pretender directly instead. Use ember-auto-import to import pretender without the need for ember-cli-pretender to add it via app.imports.

Usage

ember install ember-cli-pretender

You can then import Pretender in your tests:

import Pretender from 'pretender';

see: pretenderjs/pretender for pretender docs

Configuration

By default pretender.enabled will be set to app.tests. This means that pretender will only be available as an import when your app includes your test suite.

If you'd like to include Pretender into production builds as well, you can set pretender.enabled to true in your ember-cli-build.js or Brocfile.js:

var app = new EmberApp({
  pretender: {
    enabled: true
  }
});

You can also opt out of including the fetch polyfill, if you do not need to run your tests in older browsers:

var app = new EmberApp({
  pretender: {
    includeFetchPolyfill: false
  }
});

Nested Addon Usage Caveat

To publish an addon that exports functionality driven by ember-cli-pretender, note that ember-cli-pretender must be listed in the dependencies for NPM and not the devDependencies.

ember-cli-pretender's People

Contributors

alexlafroscia avatar bantic avatar bgentry avatar cball avatar cromwellryan avatar dcyriller avatar gabrielcsapo avatar givanse avatar jdjkelly avatar karelvuong avatar mike-north avatar mmun avatar nlfurniss avatar rwjblue avatar saygun avatar stefanpenner avatar tehviking avatar tim-evans avatar tricknotes avatar turbo87 avatar vitch avatar xg-wang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ember-cli-pretender's Issues

Path or pattern "undefined/FakeXMLHttpRequest/fake_xml_http_request.js" did not match any files

Just after the command: npm install --save-dev ember-cli-pretender
When I run 'ember server', I obtain the error:

Path or pattern "undefined/FakeXMLHttpRequest/fake_xml_http_request.js" did not match any files
Error: Path or pattern "undefined/FakeXMLHttpRequest/fake_xml_http_request.js" did not match any files
at Object.multiGlob (/Volumes/SYSTEME/Users/colin/Documents/dev/git/rails-chaos/ember/node_modules/ember-cli/node_modules/broccoli-concat/node_modules/broccoli-kitchen-sink-helpers/index.js:221:13)
at /Volumes/SYSTEME/Users/colin/Documents/dev/git/rails-chaos/ember/node_modules/ember-cli/node_modules/broccoli-concat/index.js:41:30
at $$$internal$$tryCatch (/Volumes/SYSTEME/Users/colin/Documents/dev/git/rails-chaos/ember/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:470:16)
at $$$internal$$invokeCallback (/Volumes/SYSTEME/Users/colin/Documents/dev/git/rails-chaos/ember/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:482:17)
at $$$internal$$publish (/Volumes/SYSTEME/Users/colin/Documents/dev/git/rails-chaos/ember/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:453:11)
at $$rsvp$asap$$flush (/Volumes/SYSTEME/Users/colin/Documents/dev/git/rails-chaos/ember/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:1531:9)
at process._tickCallback (node.js:415:13)

Do you know what happens ?
I use
OS X 10.9.5
ember-cli: version: 0.0.40
node: 0.10.25
npm: 1.4.21

[suggestion] Default install produces missing source map warning (ENOENT route-recognizer.js.map)

Hi, would it make sense to add an dummy source map to route recognizer or to this addon? It's not very convenient to install some addon on an vanilla ember new project and get immediately and warning.

Warning: ignoring input sourcemap for bower_components/route-recognizer/dist/route-recognizer.js because ENOENT, no such file or directory '/foo/bar//tmp/tree_merger-tmp_dest_dir-Uy6Uig0l.tmp/bower_components/route-recognizer/dist/route-recognizer.js.map'

Compatibility with `andThen` from ember-testing?

I'm using Ember Data and I'd like to mock a response to a model.save() request using ember-cli-pretender. The issue I'm having is that when I do this, the andThen helper in ember-testing does not seem to wait for the save() promise to successfully resolve before executing the assertions handed to it and my tests fail.

  1. Is this the appropriate place for raising this issue? If not, what do you recommend is appropriate?
  2. Can you suggest any workarounds?

blueprint references pretender 0.1.0

I was expecting the blueprint to reference the 0.6.0 bower package but I am seeing 0.1.0:

$ ember -v
version: 0.2.3
node: 0.12.2
npm: 2.7.6
$ npm cache clear
$ npm cache clean
$ npm install --save-dev ember-cli-pretender
[email protected] node_modules/ember-cli-pretender
$ cat node_modules/ember-cli-pretender/package.json |grep version
"version": "0.3.1",
$ cat node_modules/ember-cli-pretender/blueprints/ember-cli-pretender/index.js 
'use strict';

module.exports = {
  normalizeEntityName: function() {
    // this prevents an error when the entityName is
    // not specified (since that doesn't actually matter
    // to us
  },

  afterInstall: function() {
    return this.addBowerPackageToProject('pretender', '0.1.0');
  }
};

Pin pretender

I've started seeing the following error come from my acceptance tests in an Ember app.

message: >
[16:59:07]            You created a second Pretender instance while there was already one running. Running two Pretender servers at once will lead to unexpected results!Please call .shutdown() on your instances when you no longer need them to respond.
[16:59:07]        stack: >
[16:59:07]            interceptor@http://localhost:7357/assets/vendor.js:95670:11
[16:59:07]            Pretender@http://localhost:7357/assets/vendor.js:95530:25
[16:59:07]            createPretender@http://localhost:7357/assets/vendor.js:159797:12
[16:59:07]            config@http://localhost:7357/assets/vendor.js:159922:44
[16:59:07]            Server@http://localhost:7357/assets/vendor.js:159890:7
[16:59:07]            startMirage@http://localhost:7357/assets/frost-orchestrate-ui.js:7282:12
[16:59:07]            initialize@http://localhost:7357/assets/frost-orchestrate-ui.js:7270:9
[16:59:07]            Engine<.runInitializers/<@http://localhost:7357/assets/vendor.js:20539:11
[16:59:07]            Engine<._runInitializer/<@http://localhost:7357/assets/vendor.js:20568:9
[16:59:07]            visit@http://localhost:7357/assets/vendor.js:68985:5
[16:59:07]            DAG.prototype.topsort@http://localhost:7357/assets/vendor.js:17619:9
[16:59:07]            Engine<._runInitializer@http://localhost:7357/assets/vendor.js:20567:7
[16:59:07]            Engine<.runInitializers@http://localhost:7357/assets/vendor.js:20528:7
[16:59:07]            Application<._bootSync@http://localhost:7357/assets/vendor.js:19830:9
[16:59:07]            Application<.domReady@http://localhost:7357/assets/vendor.js:19719:7
[16:59:07]            Queue.prototype.invoke@http://localhost:7357/assets/vendor.js:16021:9
[16:59:07]            Queue.prototype.flush@http://localhost:7357/assets/vendor.js:16085:11
[16:59:07]            DeferredActionQueues.prototype.flush@http://localhost:7357/assets/vendor.js:15893:11
[16:59:07]            Backburner.prototype.end@http://localhost:7357/assets/vendor.js:15207:9
[16:59:07]            Backburner.prototype.run@http://localhost:7357/assets/vendor.js:15329:13
[16:59:07]            run@http://localhost:7357/assets/vendor.js:35602:12
[16:59:07]            startApp@http://localhost:7357/assets/tests.js:7210:5
[16:59:07]            @http://localhost:7357/assets/tests.js:10:22
[16:59:07]            wrapper/</</<@http://localhost:7357/assets/test-support.js:22555:22
[16:59:07]            Backburner.prototype.run@http://localhost:7357/assets/vendor.js:15325:18
[16:59:07]            run@http://localhost:7357/assets/vendor.js:35602:12
[16:59:07]            wrapper/<@http://localhost:7357/assets/test-support.js:22553:18
[16:59:07]            invoke@http://localhost:7357/assets/test-support.js:14005:18
[16:59:07]            fixAsync/</asyncFn@http://localhost:7357/assets/test-support.js:13990:11
[16:59:07]            Runnable.prototype.run@http://localhost:7357/assets/test-support.js:6467:7
[16:59:07]            next@http://localhost:7357/assets/test-support.js:6793:5
[16:59:07]            Runner.prototype.hook/<@http://localhost:7357/assets/test-support.js:6814:5
[16:59:07]            timeslice@http://localhost:7357/assets/test-support.js:8421:5

I noticed pretender released version 1.4.0 which now throws this warning. I think what probably needs to happen is the version in this projects package.json needs to be changed from ^1.1.0 to >=1.1.0 <=1.3.0. Otherwise I'm guessing some code needs changed somewhere. I also had this error in an addons acceptance tests (using ember-cli-mocha), and when I converted the tests to use a before instead of a beforeEach to start the app, the error went away.

Pretender causes `ember test` to hang

Steps to reproduce:

  1. Install ember-cli-pretender
  2. import Pretender from 'pretender' in test-helper.js
  3. Initialize a new Pretender(...)
  4. Tests hang. (This works in-browser though)

This was all working in ember-cli 0.4.6 but it's been broken since the upgrade to 0.1.2. Apologies as this is not entirely related to ember-cli-pretender, but any ideas you may have are greatly appreciated as it's quite tough to debug a hanging console!

missing vendor-addon/

I just installed version 0.1.0 and it did not include the vendor-addon/ directory:

➜  ~  npm install ember-cli-pretender && tree node_modules/
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
[email protected] node_modules/ember-cli-pretender
node_modules/
└── ember-cli-pretender
    ├── index.js
    └── package.json

1 directory, 2 files

I did an npm cache clean first, maybe I am missing something obvious here?

Fastboot Compatibility

ember-cli-pretender throws an error when used with fastboot.

2016-06-30T03:13:47.773Z 500 Unknown Error: ReferenceError: document is not defined at parseURL (/ember/public/dist/fastboot/vendor.js:68010:16)

The offending code:

function parseURL(url) { // TODO: something for when document isn't present... #yolo var anchor = document.createElement('a'); anchor.href = url; anchor.fullpath = anchor.pathname + (anchor.search || '') + (anchor.hash || ''); return anchor; }

Release Request

The last release was in September, but there have been some fixes and version dependency increases since then.

Receiving TypeError: object is not a function when installing

After installing ember-cli-pretender with
npm install --save-dev ember-cli-pretender

I run
ember generate ember-cli-pretender

and I receive

version: 0.0.39 object is not a functionTypeError: object is not a function at /Users/bradwheel/Development/poly-example/node_modules/ember-cli/lib/models/project.js:109:25 at visit (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/lib/utilities/DAG.js:23:3) at DAG.topsort (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/lib/utilities/DAG.js:82:7) at Project.initializeAddons (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/lib/models/project.js:96:9) at Project.eachAddonCommand (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/lib/models/project.js:130:10) at module.exports (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/lib/cli/lookup-command.js:55:13) at CLI.<anonymous> (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/lib/cli/cli.js:24:26) at $$$internal$$tryCatch (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:470:16) at $$$internal$$invokeCallback (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:482:17) at $$$internal$$publish (/Users/bradwheel/Development/poly-example/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:453:1

Does this have to do with ember-cli versions? In the changelog for 0.0.40 I noticed a PR for allowing ember addons to export an object. (ember-cli/ember-cli#1377).

self is not defined

While following: http://reefpoints.dockyard.com/2014/05/09/building-an-ember-app-with-rails-part-3.html, I install ember install:addon ember-cli-pretender. When I try to run the server after that, I get:

Livereload server on port 35729
Serving on http://localhost:4200/
self is not defined
ReferenceError: self is not defined
    at JSHinter.getConfig (/Users/matejlukasik/Documents/unpolluteit/ember/node_modules/ember-cli-qunit/node_modules/broccoli-jshint/index.js:114:7)
    at /Users/matejlukasik/Documents/unpolluteit/ember/node_modules/ember-cli-qunit/node_modules/broccoli-jshint/index.js:37:28
    at lib$rsvp$$internal$$tryCatch (/Users/matejlukasik/Documents/unpolluteit/ember/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:489:16)
    at lib$rsvp$$internal$$invokeCallback (/Users/matejlukasik/Documents/unpolluteit/ember/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:501:17)
    at lib$rsvp$$internal$$publish (/Users/matejlukasik/Documents/unpolluteit/ember/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:472:11)
    at lib$rsvp$asap$$flush (/Users/matejlukasik/Documents/unpolluteit/ember/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:1290:9)
    at process._tickCallback (node.js:355:11)

Why is that? Can anyone help?

Fetch polyfill included after Pretender, breaks on startup

I'm upgrading a project to Ember 3.5, and with it, ember-cli-pretender 3.0.0. When I run the application, the build seems to place the fetch.umd.js file after pretender.js in the vendor js bundle. This causes a problem because at the top of pretender.js, it does this:

var FakeFetch = appearsBrowserified ? getModuleDefault(require('@xg-wang/whatwg-fetch')) : self.WHATWGFetch;

self.WHATWGFetch has not been defined yet though, so FakeFetch is undefined. Then later the code in fetch.umd.js runs, and defines it. After that, this code in pretender.js runs:

  this._fetchProps = ['fetch', 'Headers', 'Request', 'Response'];
  this._fetchProps.forEach(function(name) {
    this['_native' + name] = self[name];
    self[name] = FakeFetch[name];
  }, this);

But since FakeFetch is set to undefined, it blows up.

The other possible fix would be pretender.js to move defining FakeFetch closer to where it used, but on an abstract level, it seems more appropriate to place the fetch polyfill above in the bundle to something that depends on it, particularly since it is looking on the window object for it.

Pretender is undefined after installing ember-cli-pretender in ember canary app

On a new app using ember-cli, but installing canary instead of the default 1.7.0. After npm install --save-dev ember-cli-pretender and restarting ember serve the QUnit tests don't seem to import ember-cli-pretender correctly.

I tried manually adding import Pretender from 'vendor/pretender/pretender' to the top of the acceptance test, but it didn't work. Sorry this isn't a better bug report but I'm a little unsure of how to proceed as ember-cli is so new.

Any suggestions?

Source:     
    at Object.eval (dotexam-ember/tests/dotexam-ember/tests/acceptance/set-the-correct-title-test.jshint.js:7:7)
    at Object.Test.run (http://localhost:4200/assets/test-support.js:491:18)
    at http://localhost:4200/assets/test-support.js:649:10
    at process (http://localhost:4200/assets/test-support.js:1741:24)
    at http://localhost:4200/assets/test-support.js:767:5

[BUG] Adding to project causes exception

  1. ember new testapp
  2. cd testapp
  3. Add "ember-cli-pretender": "^0.3.1" to devDependencies in the packages.json
  4. run ember server
  5. Get the following error:

Path or pattern "bower_components/FakeXMLHttpRequest/fake_xml_http_request.js" did not match any files [string exception]

Looks like some files are referenced that aren't included in the project anymore. Pull request incoming.

why ember generate?

This seems wrong. Every addon that wants to include bower components will have to individually be added to CI environment build steps. This should be happening automatically. What is the rationale behind this? /cc @stefanpenner

Why does my test not fail?

If I forget to mock a request with pretender, the exception thrown by the default implementation of the unhandledRequest hook gets swallowed; it does not cause the ember-cli test to fail (but I think it should). So, why is that? How can I fix it? Is that something that should be fixed by ember-cli-pretender?

I'll create an example project if necessary. Just let me know.

Not sure if this is the best place to ask this question...If not I move it to stackoverflow.

Allow disabling of fetch polyfill

For people that do not run their tests in old browsers (e.g. IE11) - like I guess a decent enough amount of people do - it would be great if you could disable the import of the fetch/abort controller polyfills.

Right now, it was very unexpected to me that a polyfill was installed in my development environment - maybe it would also be an idea to note that this is happening in the readme. And since we run our tests only in modern browsers, we could actually get rid of that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.