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

Test that generated blueprints are valid CoffeeScript #132

Closed
kimroen opened this issue Feb 1, 2017 · 4 comments
Closed

Test that generated blueprints are valid CoffeeScript #132

kimroen opened this issue Feb 1, 2017 · 4 comments

Comments

@kimroen
Copy link
Owner

kimroen commented Feb 1, 2017

Here's an example of a test for generating and destroying ember g adapter foo:

it('adapter foo', function() {
  var args = ['adapter', 'foo'];

  return emberNew()
    .then(() => emberGenerateDestroy(args, (file) => {
      expect(file('app/adapters/foo.coffee'))
        .to.contain("stuff");
  }));
});

What I want to do is to add a step here after the generator has run (but before it has been destroyed) that compiles the specified file with CoffeeScript and checks that it worked.

This will make sure we keep producing valid CoffeeScript, and should allow us to catch all kinds of bugs.

We could make our own test helper that compiles the specified file and verifies that it doesn't blow up. Something like this (just thinking out loud, this won't work):

it('adapter foo', function() {
  var args = ['adapter', 'foo'];

  return emberNew()
    .then(() => emberGenerateDestroy(args, (file) => {
      adapterFile = file('app/adapters/foo.coffee');
      expect(adapterFile)
        .to.contain("stuff");

      expect(compileCoffee(adapterFile)).to.not.throw(Error);
      // or something more contained like
      compileAndExpectCoffee(adapterFile);
  }));
});
This was referenced Feb 1, 2017
@jakesjews
Copy link
Contributor

@kimroen I made a small spike for this and wanted to run it past you to see if you like the direction.
I made a test helper file which looks like

var coffeescript = require('coffee-script');
var expect = require('ember-cli-blueprint-test-helpers/chai').expect;

module.exports = function(file) {
  var compileFunc = function() {
    coffeescript.compile(file.content);
  }

  expect(compileFunc).to.not.throw(Error);
}

and a test file using it looks like

'use strict';

var blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
var setupTestHooks = blueprintHelpers.setupTestHooks;
var emberNew = blueprintHelpers.emberNew;
var emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;

var expect = require('ember-cli-blueprint-test-helpers/chai').expect;
var expectCoffee = require('../helpers/expect-coffee');

describe('Acceptance: ember generate and destroy acceptance-test', function() {
  setupTestHooks(this);

  it('acceptance-test foo', function() {
    var args = ['acceptance-test', 'foo'];

    return emberNew()
      .then(() => emberGenerateDestroy(args, (file) => {
        var acceptanceFile = file('tests/acceptance/foo-test.coffee');

        expect(acceptanceFile)
          .to.contain("import Ember from 'ember")
          .to.contain("import { module, test } from 'qunit'")
          .to.contain("import startApp from 'my-app/tests/helpers/start-app'")
          .to.contain("module 'Acceptance: Foo',")
          .to.contain("test 'visiting /foo', (assert) ->")
          .to.contain("visit '/foo'")
          .to.contain("andThen ->")
          .to.contain("assert.equal currentURL(), '/foo'");

        expectCoffee(acceptanceFile);
    }));
  });
});

@kimroen
Copy link
Owner Author

kimroen commented Feb 2, 2017

Yeah, that looks like a very good starting point 👍

This project doesn't depend on coffee-script directly though - will it work to require it like that anyway? Should we try to compile it using broccoli-coffee instead, maybe?

@jakesjews
Copy link
Contributor

I added it to dev dependencies although maybe it would be better to use the implicit dependency from broccoli-coffee

@kimroen
Copy link
Owner Author

kimroen commented Feb 6, 2017

Fixed by #124 🎉

@kimroen kimroen closed this as completed Feb 6, 2017
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

2 participants