Skip to content

Commit

Permalink
adopt comments
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Feb 20, 2019
1 parent 33373a3 commit 449fc1c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 61 deletions.
40 changes: 25 additions & 15 deletions lib/broccoli/default-packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,36 +845,46 @@ module.exports = class DefaultPackager {
annotation: 'Tests To Process',
});

// src dir not there when using classic addon with MU dummy app
const srcPath = typeof tree === 'string' ? `${tree}/src` : 'src';
if (this.isModuleUnificationEnabled && fs.existsSync(srcPath)) {

if (this.isModuleUnificationEnabled) {

let destDir,
testSrcTree,
srcDir;
srcDir,
dirNotFound;

// ember-addon
if (this.name === 'dummy') {
testSrcTree = 'src';
destDir = `${this.project.name()}/src`;
// Classic Addon with MU dummy app `kitchen-sink-with-mu-dummy-app` will throw: `Dir not found: src` exception
// `dirNotFound` will skip this error. Find better way to avoid this error.

// also, in tests we pass root path to this function
// in default-packager/tests-test.js
const srcPath = typeof tree === 'string' ? `${tree}/src` : 'src';
dirNotFound = !fs.existsSync(srcPath);
} else {
testSrcTree = tree;
destDir = `${this.name}/src`;
srcDir = 'src';
}
testSrcTree = new Funnel(testSrcTree, {
srcDir,
include: ['**/*-test.{js,ts}'],
annotation: 'Module Unification Tests',
});

testSrcTree = new Funnel(testSrcTree, {
destDir,
});
if (!dirNotFound) {
testSrcTree = new Funnel(testSrcTree, {
srcDir,
include: ['**/*-test.{js,ts}'],
annotation: 'Module Unification Tests',
});

treeToCompile = mergeTrees([treeToCompile, testSrcTree], {
annotation: 'Merge MU Tests',
});
testSrcTree = new Funnel(testSrcTree, {
destDir,
});

treeToCompile = mergeTrees([treeToCompile, testSrcTree], {
annotation: 'Merge MU Tests',
});
}
}

treeToCompile = callAddonsPreprocessTreeHook(this.project, 'test', treeToCompile);
Expand Down
4 changes: 4 additions & 0 deletions lib/models/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ let addonProto = {
public: 'public',
};

if (this.isModuleUnification()) {
this.treePaths.styles = 'src/ui/styles';
}

this.treeForMethods = defaultsDeep({}, DEFAULT_TREE_FOR_METHODS);

if (this.parent) {
Expand Down
93 changes: 47 additions & 46 deletions tests/acceptance/addon-smoke-test-slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,50 +102,6 @@ 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 @@ -191,8 +147,12 @@ describe('Acceptance: addon-smoke-test', function() {
if (isExperimentEnabled('MODULE_UNIFICATION')) {

if (!process.env.EMBER_CLI_ENABLE_ALL_EXPERIMENTS) {
// does not work, since ember-resolver addon checks for env.EMBER_CLI_MODULE_UNIFICATION
// and project.isModuleUnification returns false, since the project is an classic addon
/*
We have to skip the test if `EMBER_CLI_ENABLE_ALL_EXPERIMENTS` is enabled,
because in this case, `isExperimentEnabled('MODULE_UNIFICATION')` returns true
and `env.EMBER_CLI_MODULE_UNIFICATION` is disabled, but `env.EMBER_CLI_MODULE_UNIFICATION` must be enabled,
in order for `ember-resolver` to work correctly.
*/
it('works with classic addon and MU dummy app', co.wrap(function *() {
let fixtureFile = 'kitchen-sink-classic-mu-dummy-app';
yield copyFixtureFiles(`addon/${fixtureFile}`);
Expand Down Expand Up @@ -261,7 +221,48 @@ describe('Acceptance: addon-smoke-test', function() {
expect(result.code).to.eql(0);

}));
} else {
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);
}));
}
});

Expand Down

0 comments on commit 449fc1c

Please sign in to comment.