Closed kimroen closed 7 years ago
@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);
}));
});
});
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?
I added it to dev dependencies although maybe it would be better to use the implicit dependency from broccoli-coffee
Fixed by #124 🎉
Here's an example of a test for generating and destroying
ember g adapter foo
: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):