Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an extraCliArgs option to the emberNew helper #394

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Create a new Ember.js app or addon in the current working directory.

- `{Object} [options]` optional parameters
- `{String} [options.target='app']` the type of project to create (`app`, `addon` or `in-repo-addon`)
- `{string[]} [options.extraCliArgs=[]]` any extra arguments you want to pass to ember-cli

**Returns:** `{Promise}`

Expand Down
4 changes: 3 additions & 1 deletion lib/ember-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const rethrowFromErrorLog = require('./rethrow-from-error-log');
*
* @param {Object} [options] optional parameters
* @param {String} [options.target='app'] the type of project to create (`app`, `addon` or `in-repo-addon`)
* @param {string[]} [options.extraCliArgs] any extra arguments you want to pass to ember-cli
* @returns {Promise}
*/
module.exports = function(options) {
Expand All @@ -22,12 +23,13 @@ module.exports = function(options) {

let projectName = isAddon ? 'my-addon' : 'my-app';
let command = isAddon ? 'addon' : 'new';
let extraCliArgs = Array.isArray(options.extraCliArgs) ? options.extraCliArgs : [];

let cliOptions = {
disableDependencyChecker: true
};

return ember([command, projectName, '--skip-npm', '--skip-bower'], cliOptions)
return ember([command, projectName, '--skip-npm', '--skip-bower', ...extraCliArgs], cliOptions)
.then(generateInRepoAddon(target))
.then(linkAddon)
.catch(rethrowFromErrorLog);
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const expect = chai.expect;
const dir = chai.dir;
const file = chai.file;

describe('Acceptance: helpers', function() {
describe('Acceptance: helpers', function () {
setupTestHooks(this);

describe('emberNew', () => {
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/ember-new-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
const setupTestHooks = require('../../lib/helpers/setup');

const chai = require('../../chai');
const expect = chai.expect;
const td = require('testdouble')

let ember;

describe('Unit: emberNew', function () {
setupTestHooks(this);

afterEach(() => {
td.reset();
ember = undefined;
});

it('emberNew - extraCliArgs', () => {
const originalEmber = require('../../lib/helpers/ember.js');
ember = td.replace('../../lib/helpers/ember.js');

// "spy" on the original ember function.
// testdouble.js doesn't have built-in support for this because it considers it a bad practise:
// https://github.com/testdouble/testdouble.js/issues/512#issuecomment-1527511338
td.when(ember(td.matchers.contains('--typescript', '--no-welcome'), td.matchers.anything())).thenDo((...args) => {
return originalEmber(...args);
});

// We require emberNew here so the testdouble dependency replacement works
const emberNew = require('../../lib/ember-new');

return emberNew({ extraCliArgs: ['--typescript', '--no-welcome'] })
.then(() => {
// If we get here that means our testdouble matcher worked and things were called as expected.
expect(true).to.be.true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testdouble has a td.verify feature, but using that here will also run the thenDo callback again, which causes issues. There doesn't seem to be a way to simply check the times it was called and with which arguments.

I'm not sure we need the expect either, maybe it's good enough if the test doesn't throw an error?

});
});
});
Loading