Skip to content

Commit

Permalink
add tests for addon merging in different scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Feb 16, 2019
1 parent bbe1910 commit 2a981bf
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/broccoli/default-packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const p = require('ember-cli-preprocess-registry/preprocessors');
const path = require('path');
const fs = require('fs');
const concat = require('broccoli-concat');
const Funnel = require('broccoli-funnel');
const BroccoliDebug = require('broccoli-debug');
Expand Down Expand Up @@ -844,7 +845,7 @@ module.exports = class DefaultPackager {
annotation: 'Tests To Process',
});

if (this.isModuleUnificationEnabled) {
if (this.isModuleUnificationEnabled && fs.existsSync('src')) {

let destDir,
testSrcTree,
Expand Down
4 changes: 2 additions & 2 deletions lib/models/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ let addonProto = {
@return {Tree} App file tree
*/
treeForApp(tree) {
if (!isExperimentEnabled('MODULE_UNIFICATION')) {
if (!this.project.isModuleUnification() && !this.isModuleUnification()) {
return tree;
} else if (this.project.isModuleUnification() && this.isModuleUnification()) {
return null;
Expand Down Expand Up @@ -855,7 +855,7 @@ let addonProto = {
@return
*/
treeForSrc(rawSrcTree) {
if (!isExperimentEnabled('MODULE_UNIFICATION')) {
if (!this.isModuleUnification()) {
return null;
}
if (!rawSrcTree) { return null; }
Expand Down
87 changes: 87 additions & 0 deletions tests/acceptance/addon-smoke-test-slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const path = require('path');
const fs = require('fs-extra');
const spawn = require('child_process').spawn;
const chalk = require('chalk');
const rimraf = require("rimraf");

const { isExperimentEnabled } = require('../../lib/experiments');
const runCommand = require('../helpers/run-command');
Expand Down Expand Up @@ -101,6 +102,50 @@ describe('Acceptance: addon-smoke-test', function() {
expect(result.code).to.eql(0);
}));

if (!isExperimentEnabled('MODULE_UNIFICATION')) {
it('works with MU addon and classic dummy app', co.wrap(function *() {
let fixtureFile = 'kitchen-sink-mu-classic-dummy-app';
yield copyFixtureFiles(`addon/${fixtureFile}`);

// remove MU specific things from base addon
if (yield fs.exists('tests/dummy/src')) {
rimraf.sync('tests/dummy/src');
}

let packageJsonPath = path.join(addonRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);

expect(packageJson.devDependencies['ember-source']).to.not.be.empty;

packageJson.dependencies = packageJson.dependencies || {};
// add HTMLBars for templates (generators do this automatically when components/templates are added)
packageJson.dependencies['ember-cli-htmlbars'] = 'latest';

fs.writeJsonSync(packageJsonPath, packageJson);

let result = yield runCommand('node_modules/ember-cli/bin/ember', 'build');

expect(result.code).to.eql(0);
let contents;

let indexPath = path.join(addonRoot, 'dist', 'index.html');
contents = fs.readFileSync(indexPath, { encoding: 'utf8' });
expect(contents).to.contain('"SOME AWESOME STUFF"');

let cssPath = path.join(addonRoot, 'dist', 'assets', 'vendor.css');
contents = fs.readFileSync(cssPath, { encoding: 'utf8' });
expect(contents).to.contain('addon/styles/app.css is present');
//
let robotsPath = path.join(addonRoot, 'dist', 'robots.txt');
contents = fs.readFileSync(robotsPath, { encoding: 'utf8' });
expect(contents).to.contain('tests/dummy/public/robots.txt is present');

result = yield runCommand('node_modules/ember-cli/bin/ember', 'test');

expect(result.code).to.eql(0);
}));
}

it('npm pack does not include unnecessary files', co.wrap(function *() {
let handleError = function(error, commandName) {
if (error.code === 'ENOENT') {
Expand Down Expand Up @@ -145,6 +190,48 @@ describe('Acceptance: addon-smoke-test', function() {

if (isExperimentEnabled('MODULE_UNIFICATION')) {

it('works with classic addon and MU dummy app', co.wrap(function *() {
let fixtureFile = 'kitchen-sink-classic-mu-dummy-app';
yield copyFixtureFiles(`addon/${fixtureFile}`);

// prevent MU detection
if (yield fs.exists('src')) {
rimraf.sync('src');
}

let packageJsonPath = path.join(addonRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);

expect(packageJson.devDependencies['ember-source']).to.not.be.empty;

packageJson.dependencies = packageJson.dependencies || {};
// add HTMLBars for templates (generators do this automatically when components/templates are added)
packageJson.dependencies['ember-cli-htmlbars'] = 'latest';

fs.writeJsonSync(packageJsonPath, packageJson);

let result = yield runCommand('node_modules/ember-cli/bin/ember', 'build');

expect(result.code).to.eql(0);
let contents;

let indexPath = path.join(addonRoot, 'dist', 'index.html');
contents = fs.readFileSync(indexPath, { encoding: 'utf8' });
expect(contents).to.contain('"SOME AWESOME STUFF"');

let cssPath = path.join(addonRoot, 'dist', 'assets', 'vendor.css');
contents = fs.readFileSync(cssPath, { encoding: 'utf8' });
expect(contents).to.contain('addon/styles/app.css is present');
//
let robotsPath = path.join(addonRoot, 'dist', 'robots.txt');
contents = fs.readFileSync(robotsPath, { encoding: 'utf8' });
expect(contents).to.contain('tests/dummy/public/robots.txt is present');

result = yield runCommand('node_modules/ember-cli/bin/ember', 'test');

expect(result.code).to.eql(0);
}));

it('can run a MU unit test with a relative import', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/mu-unit-test-with-relative-import');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function truthyHelper() {
return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import template from '../templates/components/basic-thing';
import Component from '@ember/component';

export default Component.extend({
layout: template
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* addon/styles/app.css is present */
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="basic-thing">
{{yield}}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import BasicThing from 'some-cool-addon/components/basic-thing';
export default BasicThing;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
name: require('./package').name,

contentFor(type, config) {
if (type === 'head') {
return '"SOME AWESOME STUFF"';
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { setupApplicationTest } from 'ember-qunit';
import { visit } from '@ember/test-helpers';
import truthyHelper from 'some-cool-addon/test-support/helper';
import { module, test } from 'qunit';

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

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

var element = this.element.querySelector('.basic-thing');
assert.equal(element.textContent.trim(), 'WOOT!!');
assert.ok(truthyHelper(), 'addon-test-support helper');
});

test('renders imported component', async function(assert) {
await visit('/');

var element = this.element.querySelector('.second-thing');
assert.equal(element.textContent.trim(), 'SECOND!!');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tests/dummy/public/robots.txt is present
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BasicThing from 'some-cool-addon/components/basic-thing';

export default BasicThing.extend({
classNames: ['second-thing']
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{#basic-thing}}WOOT!!{{/basic-thing}}
{{#second-thing}}SECOND!!{{/second-thing}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function truthyHelper() {
return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
name: require('./package').name,

contentFor(type, config) {
if (type === 'head') {
return '"SOME AWESOME STUFF"';
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import template from './template';
import Component from '@ember/component';

export default Component.extend({
layout: template
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="basic-thing">
{{yield}}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* addon/styles/app.css is present */
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { setupApplicationTest } from 'ember-qunit';
import { visit } from '@ember/test-helpers';
import truthyHelper from 'some-cool-addon/test-support/helper';
import { module, test } from 'qunit';

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

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

var element = this.element.querySelector('.basic-thing');
assert.equal(element.textContent.trim(), 'WOOT!!');
assert.ok(truthyHelper(), 'addon-test-support helper');
});

test('renders imported component', async function(assert) {
await visit('/');

var element = this.element.querySelector('.second-thing');
assert.equal(element.textContent.trim(), 'SECOND!!');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BasicThing from 'some-cool-addon/src/ui/components/basic-thing/component';

export default BasicThing.extend({
classNames: ['second-thing']
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{#basic-thing}}WOOT!!{{/basic-thing}}
{{#second-thing}}SECOND!!{{/second-thing}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tests/dummy/public/robots.txt is present

0 comments on commit 2a981bf

Please sign in to comment.