Skip to content

Commit

Permalink
use code templates
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Jun 5, 2019
1 parent f7fe1d5 commit cdca0b4
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 56 deletions.
87 changes: 52 additions & 35 deletions index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions new-relic-templates/new-relic-spa.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions new-relic-templates/new-relic.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 18 additions & 8 deletions node_tests/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ QUnit.module('ember-new-relic | When config[\'ember-new-relic\'].spaMonitoring i
assert.equal(EmberNewRelic.wantsSPAMonitoring(this.newRelicConfig), false);
});

QUnit.test('getNewRelicTrackingCode returns classicTrackingCode', function(assert) {
QUnit.test('getTemplateFile returns correct classic template', function(assert) {
assert.equal(
EmberNewRelic.getNewRelicTrackingCode(this.newRelicConfig),
EmberNewRelic.classicTrackingCode(this.newRelicConfig)
EmberNewRelic.getTemplateFile(this.newRelicConfig),
'new-relic.js'
);
});
});
Expand Down Expand Up @@ -71,10 +71,10 @@ QUnit.module('ember-new-relic | When config[\'ember-new-relic\'].spaMonitoring i
assert.equal(EmberNewRelic.wantsSPAMonitoring(this.newRelicConfig), true);
});

QUnit.test('getNewRelicTrackingCode returns spaTrackingCode', function(assert) {
QUnit.test('getTemplateFile returns correct spa template', function(assert) {
assert.equal(
EmberNewRelic.getNewRelicTrackingCode(this.newRelicConfig),
EmberNewRelic.spaTrackingCode(this.newRelicConfig)
EmberNewRelic.getTemplateFile(this.newRelicConfig),
'new-relic-spa.js'
);
});

Expand Down Expand Up @@ -108,8 +108,18 @@ QUnit.module('ember-new-relic | When outputPath, applicationId, and licenseKey a
let builder = new broccoli.Builder(tree);
await builder.build();

let contents = fs.readFileSync(path.join(builder.outputPath, EmberNewRelic.outputPath), 'utf-8');
assert.equal(contents, EmberNewRelic.getNewRelicTrackingCode(newRelicConfig));
// simulate template replacement
let template = fs.readFileSync(path.join(__dirname, '..', 'new-relic-templates/new-relic-spa.js'), 'utf-8');
template = template.replace(/{{(.*?)}}/g, function(match, value) {
return EmberNewRelic.getTemplateValue(newRelicConfig, value);
});

// get actual result
let result = fs.readFileSync(path.join(builder.outputPath, EmberNewRelic.outputPath), 'utf-8');

// here we test that the result includes the template and not just that it is equal
// this is because the result file includes the fastboot guard wrapper
assert.ok(result.indexOf(template) !== -1);

await builder.cleanup();
});
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
"test:node": "qunit \"node_tests/*-test.js\""
},
"dependencies": {
"broccoli-file-creator": "^2.1.1",
"broccoli-funnel": "^2.0.2",
"broccoli-merge-trees": "^3.0.2",
"ember-cli-babel": "^7.7.3"
"broccoli-replace": "^0.12.0",
"ember-cli-babel": "^7.7.3",
"fastboot-transform": "^0.1.3"
},
"devDependencies": {
"@ember/optional-features": "^0.7.0",
Expand Down
Loading

0 comments on commit cdca0b4

Please sign in to comment.