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

Enhance blueprints #4023

Merged
merged 1 commit into from
Apr 6, 2016
Merged

Enhance blueprints #4023

merged 1 commit into from
Apr 6, 2016

Conversation

pangratz
Copy link
Member

This is a followup PR, made due to a comment by @igorT: currently a serializer generate via ember generate ember-data:serializer foo extends DS.JSONAPIAdapter, where it should extend the ApplicationAdapter. This behavior is already the case when an adapter is generated, so this PR aligns the behavior of the serializer blueprint to the one of the adapter blueprint.


TODO

  • Investigate timeout in test for ember g adapter foo when application adapter is present
  • Investigate how to check if a file exists within a blueprints' index.js
  • Check why test for serializer fail but for the adapter doesn't (though it's the same)

@rwjblue
Copy link
Member

rwjblue commented Dec 21, 2015

Can we extract a common shared function from https://github.com/emberjs/data/blob/master/blueprints/adapter/index.js to reuse?

@pangratz
Copy link
Member Author

@rwjblue I extracted the common functionality into lib/utilities/extend-from-application-entity.js and additionally added a logic so we only extend from the application adapter / serializer if it actually exists (otherwise DS.JSONAPIAdapter or DS.JSONAPISerializer is used for the base class).

Is this something you had in mind?

@rwjblue
Copy link
Member

rwjblue commented Dec 21, 2015

Looks perfect, thank you @pangratz!

@pangratz
Copy link
Member Author

The tests fail for the scenarios which check if we extend from the application entity only if it exists. The setup uses the afterGenerate callback of generateAndDestroy:

  it('adapter extends application adapter, if available', function() {
    return generateAndDestroy(['adapter', 'application'], {
      afterGenerate: function() {
        return generateAndDestroy(['adapter', 'foo'], {
          files: [
            // ...
          ]
        });
      }
    });
  });

Error: timeout of 20000ms exceeded. Ensure the done() callback is being called in this test. is thrown. I will investigate ...

@pangratz
Copy link
Member Author

pangratz commented Jan 5, 2016

May I shamelessly ping @trabus' 👀 here: do you spot any obvious mis-use of the generateAndDestroy helper using the afterGenerate hook? I took the sample from ember-cli-blueprint-test-helpers README, but I don't see why the test times out. Do you have an idea?

@trabus
Copy link
Contributor

trabus commented Jan 5, 2016

I don't have any time to look right now, but you might want to look at https://github.com/trabus/ember-cli-legacy-blueprints/blob/blueprints/node-tests/blueprints/adapter-test.js for tips.

Also, I have a PR that needs to be merged into ember-cli for the blueprint-test-helpers to work properly, so you might be running into an issue there.

@trabus
Copy link
Contributor

trabus commented Jan 5, 2016

@trabus
Copy link
Contributor

trabus commented Jan 5, 2016

@pangratz I made a note to document it. Sorry about that.

@pangratz
Copy link
Member Author

pangratz commented Jan 5, 2016

@trabus thank you so much for your help! I will try to help you out with the issue you opened.

@trabus
Copy link
Contributor

trabus commented Jan 5, 2016

Awesome, looks like it unblocked it!

Generating after generating a project is kind of tricky, I wish there were a cleaner way to set that up.

@stefanpenner
Copy link
Member

thats a first:
screen shot 2016-01-05 at 1 23 09 pm

@pangratz
Copy link
Member Author

pangratz commented Jan 5, 2016

AppVeyor with its New Year's resolution. Now 78% more green.

@pangratz
Copy link
Member Author

pangratz commented Jan 5, 2016

So I just tested this locally and the detection of an existing application adapter / serializer works. I am not sure why the tests are failing...

@trabus
Copy link
Contributor

trabus commented Jan 5, 2016

So the error here: https://travis-ci.org/emberjs/data/builds/100452185#L7477

We need to cut another release of ember-cli-internal-test-helpers and ember-cli-blueprint-test-helpers. I fixed it on master, but in my holiday distraction, I forgot to cut the release.

I will have to take care of this later tonight when I get home to my personal machine.

@trabus
Copy link
Contributor

trabus commented Jan 13, 2016

I will have to take care of this later tonight when I get home to my personal machine.

@pangratz Unfortunately I've been heavily distracted by life stuff. I will try to cut out some time this week, but I'm not exactly sure when I'll be able to get to it. Sorry for the holdup.

@pangratz
Copy link
Member Author

No worries @trabus!

@pangratz
Copy link
Member Author

Ok, thanks to a new release by señor trabus the tests run now without a timeout 🚀


But, unfortunately it seems that there is a new issue:

https://travis-ci.org/emberjs/data/builds/103402540#L7449-L7466:

  1) Acceptance: generate and destroy serializer blueprints serializer extends application serializer if it exists:
      EqualityError: expected: `app/serializers/foo.js`
      + expected - actual
      -import DS from 'ember-data';
      -
      -export default DS.RESTSerializer.extend({
      -});
      +import ApplicationSerializer from './application';

      at node_modules/ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper.js:154:14
      at Array.forEach (native)
      at assertGenerated (node_modules/ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper.js:151:9)
      at lib$rsvp$$internal$$tryCatch (node_modules/rsvp/dist/rsvp.js:493:16)
      at lib$rsvp$$internal$$invokeCallback (node_modules/rsvp/dist/rsvp.js:505:17)
      at lib$rsvp$$internal$$publish (node_modules/rsvp/dist/rsvp.js:476:11)
      at lib$rsvp$asap$$flush (node_modules/rsvp/dist/rsvp.js:1198:9)

When testing that it is correctly extended from an existing application serializer, it extends from DS.RESTSerializer which is never used in the blueprints anymore. So I have the feeling that somehow the ember-cli-legacy-blueprints are used for this test, since those blueprints still extend from DS.RESTAdapter. This package is defined in node-tests/fixtures/app/package/package.json. When this package is removed, the test still fail, even after a nombom.

Now comes the strange part: If the beforeDestroy hook is used instead of afterGenerate, the failing test passes. Woot?

The weird thing is that the test for the application adapter works correctly, though the same test is used (only difference is that an adapter is created instead of a serializer)...


@trabus I am sorry to ping you again here but do you have a clue what's going on?

@pangratz
Copy link
Member Author

After further digging the ember-cli package also has a blueprint for a serializer using DS.RESTSerializer, so maybe that one's used instead of the one provided by ember-data? But why only for the serializer test and for the adapter it's not? 😜

@bmac
Copy link
Member

bmac commented Mar 27, 2016

@pangratz whats currently blocking this pr? Is the DS.RESTSerializer thing an ember-cli issue?

@pangratz
Copy link
Member Author

Is the DS.RESTSerializer thing an ember-cli issue?

@bmac if I understand this correctly then it seems that the tests using ember-cli-blueprint-test-helpers use the blueprints defined in ember-cli instead of the ones defined within ember-data.

If you checkout the branch of this PR, replace the contents of node_modules/ember-cli/blueprints/adapter/files/__root__/__path__/__name__.js with TEST, run npm run-script node-tests then the adapter tests are failing too...

@Turbo87
Copy link
Member

Turbo87 commented Mar 28, 2016

@pangratz I've stepped through it and the problem is definitely not the ember-cli blueprint. it seems that the code actually works correctly but after the assertions pass they are executed a second time where they suddenly fail. I'm not sure where the problem exactly is yet, but I'll see if I can figure it out.

@pangratz
Copy link
Member Author

@Turbo87 thanks for checking! Much appreciated.

@Turbo87
Copy link
Member

Turbo87 commented Mar 28, 2016

@pangratz ember-cli/ember-cli-blueprint-test-helpers@7a709c8 seems to fix the issue

@Turbo87
Copy link
Member

Turbo87 commented Mar 28, 2016

@pangratz we've just released ember-cli-blueprint-test-helpers v0.10.1 including that bugfix. your test suite should pass fine once you update the dependency. sorry for the troubles!

@pangratz
Copy link
Member Author

@Turbo87 thanks for the quick fix!

I've updated the ember-cli-blueprint-test-helpers dependency to use the latest version, and now the problem with the "wrong blueprint" is fixed!

Unfortunately there seems to be an issue with the assertions, checking that a SilentError is thrown when it is tried to extend from the same entity:

$ npm run-script node-tests
> ember-data@2.6.0-canary node-tests /home/travis/build/emberjs/data
> node node-tests/nodetest-runner.js
Verifing `.only` in tests
No `.only` found
  Acceptance: generate and destroy adapter blueprints
  ✓ adapter (1811ms)
  ✓ adapter extends application adapter if it exists (748ms)
  ✓ adapter with --base-class (340ms)
  1) adapter throws when --base-class is same as name
adapters cannot extend from themself. To resolve this, remove the `--base-class` option or change to a different base-class.
adapters cannot extend from themself. To resolve this, remove the `--base-class` option or change to a different base-class.
  ✓ adapter when is named "application" (650ms)
  ✓ adapter-test (386ms)
  ✓ adapter-test for mocha (381ms)
  Acceptance: generate and destroy model blueprints
  ✓ model (424ms)
  ✓ model with attrs (408ms)
  ✓ model with belongsTo (395ms)
  ✓ model with hasMany (450ms)
  ✓ model with belongsTo and hasMany has both imports (445ms)
  ✓ model-test (440ms)
  ✓ model-test for mocha (387ms)
  Acceptance: generate and destroy serializer blueprints
  ✓ serializer (390ms)
  ✓ serializer extends application serializer if it exists (723ms)
  ✓ serializer with --base-class (424ms)
  2) serializer throws when --base-class is same as name
  ✓ serializer when is named "application" (472ms)
  ✓ serializer-test (404ms)
  ✓ serializer-test for mocha (383ms)
  Acceptance: generate and destroy transform blueprints
  ✓ transform (508ms)
  ✓ transforms-test (311ms)
  ✓ transform-test for mocha (462ms)
  22 passing (12s)
  2 failing
  1) Acceptance: generate and destroy adapter blueprints adapter throws when --base-class is same as name:
     TypeError: expect(...).to.be.rejectedWith is not a function
      at assertThrows (node_modules/ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper.js:257:32)
      at generateAndDestroy (node_modules/ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper.js:81:12)
      at Context.<anonymous> (node-tests/blueprints/adapter-test.js:74:12)
  2) Acceptance: generate and destroy serializer blueprints serializer throws when --base-class is same as name:
     TypeError: expect(...).to.be.rejectedWith is not a function
      at assertThrows (node_modules/ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper.js:257:32)
      at generateAndDestroy (node_modules/ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper.js:81:12)
      at Context.<anonymous> (node-tests/blueprints/serializer-test.js:74:12)

@trabus
Copy link
Contributor

trabus commented Mar 28, 2016

@pangratz The weird thing is, we have the exact same test in ember-cli-legacy-blueprints and it's passing (locally with v0.10.1). https://github.com/ember-cli/ember-cli-legacy-blueprints/blob/master/node-tests/blueprints/adapter-test.js#L48

Did you re-run the ember-cli-blueprint-test-helpers generator after upgrading the package? We've had some changes to it since early on when you were working on this. Try ember g ember-cli-blueprint-test-helpers and see if that makes any changes that you didn't have before.

@pangratz
Copy link
Member Author

@trabus I ran ember g ember-cli-blueprint-test-helpers and this resulted in some files being updated (see latest commit). Unfortunately the error still seems to be present. This is strange, I can't spot any differences to the setup in ember-cli-legacy-blueprints...

@Turbo87
Copy link
Member

Turbo87 commented Mar 28, 2016

Can you check if chai-as-promised is installed? It sounds like a missing dependency to me.

@pangratz
Copy link
Member Author

Hmm, looks like it is installed.

$ npm ls chai-as-promised
ember-data@2.6.0-canary
├─┬ ember-cli-blueprint-test-helpers@0.10.1
│ └── chai-as-promised@5.3.0
└─┬ ember-cli-internal-test-helpers@0.8.1
  └── chai-as-promised@5.3.0

@Turbo87
Copy link
Member

Turbo87 commented Mar 28, 2016

In that case I would suspect that chai.use(require('chai-as-promised')) is somehow not called by one of those test helpers.

@Turbo87
Copy link
Member

Turbo87 commented Mar 28, 2016

@pangratz you can fix the current error by changing require('RSVP') to require('rsvp') in the nodetest-runner.js file (see ember-cli/ember-cli-blueprint-test-helpers#44 for the upstream fix)

@pangratz
Copy link
Member Author

@Turbo87 you are a 🚀 Thank you kindly!

@Turbo87
Copy link
Member

Turbo87 commented Mar 28, 2016

@pangratz unfortunately that only fixes the broken require() call. I'm still not sure why the Promise it not rejected as expected

@Turbo87
Copy link
Member

Turbo87 commented Mar 30, 2016

@pangratz ember-cli/ember-cli-blueprint-test-helpers#47 is solving your TypeError: expect(...).to.be.rejectedWith is not a function issue once it's merged.

@pangratz
Copy link
Member Author

Thanks to the hard work by @trabus and @Turbo87 this is ready to go 🚀 .

This change updates the blueprints for adapter and serializer, so they
extend from the application entity if it exists: If there is an
application adapter - located in `app/adapters/application.js` - and the
command `ember g adapter foo` is invoked, the created adapter extends
from the application adapter:

```js
// app/adapters/foo.js
import ApplicationAdapter from './application';

export default ApplicationAdapter.extend();
```

If there is no application entity, the JSONAPI equivalent is used.
Consider no application serializer in  `app/serializers/appliation.js`
and the command `ember generate serializer foo` is invoked, then the
created serializer extends from JSONAPISerializer:

```js
// app/serializers/foo.js
import JSONAPISerializer from 'ember-data/serializers/json-api';

export default JSONAPISerializer.extend();
```
@pangratz pangratz merged commit 7f5d53a into emberjs:master Apr 6, 2016
@pangratz pangratz deleted the enhance-blueprints branch April 6, 2016 16:49
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

Successfully merging this pull request may close these issues.

6 participants