Skip to content

Commit

Permalink
Add basic AST transform test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Jul 31, 2018
1 parent c880be6 commit b85cde0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

class Plugin {
transform(ast) {
this.syntax.traverse(ast, {
MustacheStatement(node) {
if (node.path.original === 'ast-transform-will-replace') {
let value = node.hash.pairs.find(x => x.key === 'with').value.value;

node.type = 'TextNode';
node.chars = value;
}
}
});
}
}

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
// Add options here
});

app.registry.add('htmlbars-ast-plugin', {
name: 'replace-ast-transform',
plugin: Plugin
});

/*
This build file specifies the options for the dummy test app of this
addon, located in `/tests/dummy`
Expand Down
14 changes: 14 additions & 0 deletions tests/acceptance/root-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';

module('Acceptance | root', function(hooks) {
setupApplicationTest(hooks);

test('visiting /', async function(assert) {
await visit('/');

assert.equal(currentURL(), '/');
assert.equal(this.element.querySelector('#will-contain-replaced-text').textContent, 'Hello, World');
});
});
1 change: 1 addition & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<h1>ember-cli-htmlbars</h1>
<a href="/tests">Run Tests</a>
<div id="will-contain-replaced-text">{{ast-transform-will-replace with="Hello, World"}}</div>
{{outlet}}

0 comments on commit b85cde0

Please sign in to comment.