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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test blueprint that adds node: current to the targets file #789

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/ember-cli-fastboot/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ module.exports = {
env: {
embertest: true
}
},

// mocha test files
{
files: ['test/**/*.js'],
env: {
node: true,
mocha: true
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
};
29 changes: 24 additions & 5 deletions packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
/* eslint-env node */
const recast = require('recast');
const { readFileSync, writeFileSync } = require('fs');
const { join, dirname } = require('path')
const tmp = require('tmp');
const mkdirp = require('mkdirp');

module.exports = {
description: '',
normalizeEntityName() {
// no-op
},

afterInstall() {
let targetsFile = './config/targets.js'
filesPath() {
return this._filesPath;
},

_targetsFile(project) {
let configPath = 'config';

if(this.project.isEmberCLIAddon()) {
targetsFile = './tests/dummy/config/targets.js';
if (project.pkg['ember-addon'] && project.pkg['ember-addon']['configPath']) {
configPath = project.pkg['ember-addon']['configPath'];
}

return join(configPath, 'targets.js');
},

install(options) {
this._filesPath = tmp.dirSync().name;

const targetsFile = this._targetsFile(options.project);

const targetsAst = recast.parse(readFileSync(targetsFile));

recast.visit(targetsAst, {
Expand All @@ -39,6 +54,10 @@ module.exports = {
}
});

writeFileSync(targetsFile, recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code);
let newFile = join(this._filesPath, targetsFile);
mkdirp.sync(dirname(newFile));
writeFileSync(newFile, recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code);

return this._super.install.apply(this, arguments);
}
};
5 changes: 4 additions & 1 deletion packages/ember-cli-fastboot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"broccoli-plugin": "^1.3.1",
"chalk": "^2.4.1",
"ember-cli-babel": "^7.1.0",
"ember-cli-blueprint-test-helpers": "mansona/ember-cli-blueprint-test-helpers#fix-ember-generate-options",
"ember-cli-lodash-subset": "2.0.1",
"ember-cli-preprocess-registry": "^3.1.2",
"ember-cli-version-checker": "^3.0.0",
Expand All @@ -39,8 +40,10 @@
"fs-extra": "^7.0.0",
"json-stable-stringify": "^1.0.1",
"md5-hex": "^2.0.0",
"mkdirp": "^1.0.4",
"recast": "^0.19.1",
"silent-error": "^1.1.0"
"silent-error": "^1.1.0",
"tmp": "^0.2.1"
},
"devDependencies": {
"body-parser": "^1.18.3",
Expand Down
44 changes: 44 additions & 0 deletions packages/ember-cli-fastboot/test/default-blueprint-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');

const { emberGenerate, emberNew, setupTestHooks } = blueprintHelpers;

const MockUI = require('console-ui/mock');

const expect = require('ember-cli-blueprint-test-helpers/chai').expect;

describe.only('Acceptance: ember generate and destroy default-blueprint', function() {
setupTestHooks(this);

it('default-blueprint foo', async function() {
let args = ['ember-cli-fastboot'];

// process.stdout.on('data', function(data) {
// console.log('face', data.toString());
// process.stdin.writeLine('y');
// // process.stdout.write(data);
// });



// pass any additional command line options in the arguments array
await emberNew();

// let ui = new MockUI();

// let interval = setInterval(() => {
// ui.inputStream.write('y\n\r');
// }, 2000);

const ember = await emberGenerate(args);

setTimeout(() => {
ember.inputStream.write('y\n');
}, 4000)

// clearInterval(interval);

// expect(file('config/targets.js')).to.contain(`node: 'current'`);
});
});