Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

'server' is not defined #953

Closed
imhuytq opened this issue Nov 28, 2016 · 23 comments
Closed

'server' is not defined #953

imhuytq opened this issue Nov 28, 2016 · 23 comments

Comments

@imhuytq
Copy link

imhuytq commented Nov 28, 2016

I writing an acceptance test and got an error:

acceptance/redirect-test.js: line 7, col 3, 'server' is not defined.

acceptance/redirect-test.js file

import { test } from 'qunit';
import moduleForAcceptance from 'websizy-dashboard/tests/helpers/module-for-acceptance';

moduleForAcceptance('Acceptance | redirect');

test('should redirect to website index', function(assert) {
  server.createList('website', 1);

  visit('/websites');

  andThen(function() {
    assert.equal(currentRouteName(), 'website.index');
  });
});

Ember: 2.9.1
ember-cli: 2.9.1
ember-cli-mirage: 0.2.4
node: 6.8.0
phantomjs: 2.1.1

@dustinfarris
Copy link
Contributor

is the error coming from the acceptance test or from JSHint?

@imhuytq
Copy link
Author

imhuytq commented Nov 29, 2016

I found solution at #401 Thank you :)

@imhuytq imhuytq closed this as completed Nov 29, 2016
@dustinfarris
Copy link
Contributor

possible you did not install with ember install ember-cli-mirage which would mean the default blueprint didn't run which adds "server" to tests/.jshintrc

You can do this yourself, or you can run:

ember generate ember-cli-mirage

@jonblack
Copy link

Just came across this error as well. Adding server to "predef" in tests/.jshintrc resolves it. Running ember generate ember-cli-mirage did not add this, so perhaps something is broken?

@imhuytq
Copy link
Author

imhuytq commented Nov 30, 2016

@dustinfarris I was run ember install ember-cli-mirage, but it did not add server to "predef" in tests/.jshintrc.

@dustinfarris
Copy link
Contributor

@imhuytq weird, this might be broken then. can you reopen the issue?

@imhuytq imhuytq reopened this Dec 1, 2016
@albertpak
Copy link

Ran into this issue this week - generated an acceptance test, tried to use server.create('user') and got an error that server is not defined, checked .jshintrc and "server" is in it

@albertpak
Copy link

I've even compared it to another app (2.3.4) and I don't see anything different in it, as to why the server wouldn't be available during tests.

@albertpak
Copy link

anyone else run into this issue?

@muttli
Copy link

muttli commented Dec 14, 2016

I'm also having this issue, on Ember 2.10.0. I'm using eslint however.

tests/.eslintrc.js

module.exports = {
  root: true,
  extends: '../.eslintrc.js',
  globals: {
    'server': true
  },
  env: {
    'embertest': true,
    'es6': true
  }
};

@muttli
Copy link

muttli commented Dec 14, 2016

Incase it could help debugging, here is my full package file

    "broccoli-asset-rev": "^2.4.5",
    "ember-ajax": "^2.4.1",
    "ember-cli": "2.10.0",
    "ember-cli-app-version": "^2.0.0",
    "ember-cli-babel": "^5.1.10",
    "ember-cli-dependency-checker": "^1.3.0",
    "ember-cli-eslint": "3.0.0",
    "ember-cli-htmlbars": "^1.0.10",
    "ember-cli-htmlbars-inline-precompile": "^0.3.3",
    "ember-cli-inject-live-reload": "^1.4.1",
    "ember-cli-mirage": "0.2.4",
    "ember-cli-page-object": "1.7.0",
    "ember-cli-qunit": "^3.0.1",
    "ember-cli-release": "^0.2.9",
    "ember-cli-sass": "^5.5.2",
    "ember-cli-sri": "^2.1.0",
    "ember-cli-test-loader": "^1.1.0",
    "ember-cli-uglify": "^1.2.0",
    "ember-cp-validations": "3.1.3",
    "ember-data": "^2.10.0",
    "ember-export-application-global": "^1.0.5",
    "ember-intl": "2.13.1",
    "ember-intl-cp-validations": "2.3.1",
    "ember-keyboard": "2.1.3",
    "ember-load-initializers": "^0.5.1",
    "ember-local-storage": "1.3.1",
    "ember-radio-button": "1.0.7",
    "ember-resolver": "^2.0.3",
    "ember-simple-auth": "1.1.0",
    "ember-svg-jar": "0.9.3",
    "ember-wormhole": "0.4.1",
    "eslint-plugin-ember-suave": "^1.0.0",
    "liquid-fire": "0.27.0",
    "loader.js": "^4.0.10",
    "phantomjs-prebuilt": "^2.1.14"

@albertpak
Copy link

mine looks pretty much the same as mine...I don't understand what could be happening with a package that started disabling server...my only thought that it was related to 2.10 release...but i'm running 2.5.x and still running into that issue

@muttli
Copy link

muttli commented Dec 15, 2016

@albertpak I'm not quite sure what I did since I was on a dirty branch, but I suspect that somewhere the config setting for mirage changed from defaulting to true for testing env to false. After setting Mirage to true for the test env, the server error went away.

Again, I'm not sure this is the actual solution since I had tried alot of stuff to fix this, but give it a try.

@albertpak
Copy link

@taheilo in your app, are you using a --proxy option in your app?

@muttli
Copy link

muttli commented Dec 16, 2016

@albertpak thats it. And no, im not using --proxy.

@albertpak
Copy link

albertpak commented Dec 16, 2016

Figured it out - i had a system wide setting for the environment to be set to development mode, so the app never went into test environment 👊

Lesson learned - pay attention even closer! lol

So take away is to enable the server - make sure you set the settings correctly in your config/environment file and enable mirage in your proper environment.

Hopefully this will somehow help someone else :)

@muttli
Copy link

muttli commented Dec 16, 2016

Oh lol :) Good that you got it solved.

@albertpak
Copy link

That's weird...not to familiar with that function, but loading of mirage should be separate from that. Check in your config/environment.js that you're enabling mirage server in test environment. Also, if you run your Ember app with proxy option, Mirage might not be enabled

@acorncom
Copy link
Collaborator

Sounds like this isn't a Mirage issue, so I'll close it for now

@backspace
Copy link
Contributor

This happened to me with a fresh application recently. To test it out, I tried making a new application and running ember install ember-cli-mirage with these Ember CLI versions:

  • 2.10
  • 2.9
  • 2.8
  • 2.7
  • 2.3

In none of them did the correct lines get added to the .jshintrc files. It’s confusing because surely this did work at some point, so maybe it’s some other dependency at fault?

It was easy enough for me to fix but I find it concerning because Mirage is used in the guides and it might be confusing for newcomers.

@imhuytq
Copy link
Author

imhuytq commented Jan 12, 2017

@backspace Ember-CLI use fs-extra.outputFile function for insertIntoFile function.
I think it is the original of this problem.

@backspace
Copy link
Contributor

hmm, do you have any idea of how we could use that understanding to fix it, @imhuytq?

@imhuytq
Copy link
Author

imhuytq commented Jan 12, 2017

I was test fs-extra.outputFile function on new project (not Ember) and work correctly.
But on Ember, fs.exists (line 12) callback in fs-extra.outputFile function was not fire.
That's strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants