From 26923355a6ec1216235cd1945ed6df4d18b903ef Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Mon, 8 Feb 2016 21:14:00 -0800 Subject: [PATCH 1/4] updated to latest yeoman-generator (0.22) updated package.json dependencies to match latest generator-generator output minor changes to generator files - a few formating chagnes for new ejs template engine - importing yeoman.generator.Base directly major overhaul to test files - directly requiring/using yeoman-assert - using helper.run().inTmpDir() - using mkdrip instead of mkdir - removed load test - using before() instead of beforeAll() for all widget generator tests --- app/index.js | 7 +- package.json | 15 +- test/test-creation.js | 151 ++++------- test/test-load.js | 10 - test/test-widget.js | 453 +++++++++++++++----------------- widget/index.js | 8 +- widget/templates/_manifest.json | 2 +- 7 files changed, 276 insertions(+), 370 deletions(-) delete mode 100644 test/test-load.js diff --git a/app/index.js b/app/index.js index 166cd2c..11b0979 100644 --- a/app/index.js +++ b/app/index.js @@ -1,11 +1,12 @@ 'use strict'; var path = require('path'); -var yeoman = require('yeoman-generator'); +var Base = require('yeoman-generator').Base; var yosay = require('yosay'); var chalk = require('chalk'); var isWin = process.platform === 'win32'; var homedir = (isWin) ? process.env.HOMEPATH : process.env.HOME; var fs = require('fs'); +var mkdirp = require('mkdirp'); function getDirectories(srcpath) { return fs.readdirSync(srcpath).filter(function(file) { @@ -13,7 +14,7 @@ function getDirectories(srcpath) { }); } -module.exports = yeoman.generators.Base.extend({ +module.exports = Base.extend({ initializing: function () { // check for existence of package.json try { @@ -134,7 +135,7 @@ module.exports = yeoman.generators.Base.extend({ if (this.abort) { return; } - this.mkdir('widgets'); + mkdirp('widgets'); }, gruntConfig: function() { diff --git a/package.json b/package.json index aebfaf0..4510fa2 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "generator-esri-appbuilder-js", - "version": "1.2.0", + "version": "2.0.0", "description": "Yeoman generator to help customize the ArcGIS Web AppBuilder", - "license": "Apache", + "license": "Apache-2.0", "main": "app/index.js", "repository": "Esri/generator-esri-appbuilder-js", "author": { @@ -28,15 +28,12 @@ "AppBuilder" ], "dependencies": { - "chalk": "~0.4.0", - "yeoman-generator": "^0.17.0", - "yosay": "^0.1.0" + "chalk": "^1.0.0", + "underscore.string": "^3.2.3", + "yeoman-generator": "^0.22.5", + "yosay": "^1.0.2" }, "devDependencies": { - "mkdirp": "^0.5.1", "mocha": "*" - }, - "peerDependencies": { - "yo": ">=1.0.0" } } diff --git a/test/test-creation.js b/test/test-creation.js index 498e205..f5be098 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -1,49 +1,34 @@ /*global describe, before, it */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; +var assert = require('yeoman-assert'); +var helpers = require('yeoman-test'); var mkdirp = require('mkdirp'); var fs = require('fs'); -var wabRoot = path.join(__dirname, 'temp'); +var wabRoot = 'wab_root'; var appDirId = '5'; // arbitrary number since we're creating everything anyway. var appTitle = 'TestTitle'; // arbitrary title -var appDirPath = path.join('server', 'apps', appDirId); -var filePath = path.join(appDirPath, 'config.json'); +var appDirPath = path.join(wabRoot, 'server', 'apps', appDirId); +var configFilePath = path.join(appDirPath, 'config.json'); var configFileContents = '{title:"' + appTitle + '"}'; -describe('esri-appbuilder-js generator', function () { +describe('esri-appbuilder-js:app', function () { before(function (done) { - helpers.testDirectory(wabRoot, function (err) { - if (err) { - return done(err); - } - - // Write the config file to the "filePath", so it's available to - // read when the generator goes to lookup the possible values - // for the apps. - mkdirp(appDirPath, function (err) { - if (err) { - console.error(err); - } else { - fs.writeFileSync(filePath, configFileContents); - - this.app = helpers.createGenerator('esri-appbuilder-js:app', [ - '../../app' - ]); - - helpers.mockPrompt(this.app, { - 'abort': false, - 'wabRoot': wabRoot, - 'appDirId': appDirId - }); - this.app.options['skip-install'] = true; - this.app.run({}, function () { - done(); - }); - } - }.bind(this)); - }.bind(this)); + helpers.run(path.join(__dirname, '../app')) + .withOptions({ skipInstall: true }) + .withPrompts({ + 'abort': false, + 'wabRoot': wabRoot, + 'appDirId': appDirId + }).inTmpDir(function(/*dir*/) { + var done = this.async(); + mkdirp(appDirPath, function () { + fs.writeFileSync(configFilePath, configFileContents); + done(); + }); + }) + .on('end', done); }); // TODO: test for existence of widgets folder? @@ -53,68 +38,55 @@ describe('esri-appbuilder-js generator', function () { '.jshintrc', '.editorconfig' ]; - helpers.assertFile(expected); + assert.file(expected); }); describe('when creating gruntfile', function() { it('sets stemappDir variable', function() { - helpers.assertFileContent('Gruntfile.js', new RegExp('var stemappDir = \'' + path.join(wabRoot, 'client', 'stemapp').replace(/\\/g, '/'))); + assert.fileContent('Gruntfile.js', new RegExp('var stemappDir = \'' + path.join(wabRoot, 'client', 'stemapp').replace(/\\/g, '/'))); }); it('sets appDir variable', function() { - helpers.assertFileContent('Gruntfile.js', new RegExp('var appDir = \'' + path.join(wabRoot, 'server', 'apps', appDirId).replace(/\\/g, '/'))); + assert.fileContent('Gruntfile.js', new RegExp('var appDir = \'' + path.join(wabRoot, 'server', 'apps', appDirId).replace(/\\/g, '/'))); }); it('sets watch config', function() { - helpers.assertFileContent('Gruntfile.js', new RegExp('watch:')); + assert.fileContent('Gruntfile.js', new RegExp('watch:')); }); it('loads watch task', function() { - helpers.assertFileContent('Gruntfile.js', /grunt.loadNpmTasks\('grunt-contrib-watch'\);/); + assert.fileContent('Gruntfile.js', /grunt.loadNpmTasks\('grunt-contrib-watch'\);/); }); it('sets sync config', function() { - helpers.assertFileContent('Gruntfile.js', new RegExp('sync:')); + assert.fileContent('Gruntfile.js', new RegExp('sync:')); }); it('loads sync task', function() { - helpers.assertFileContent('Gruntfile.js', /grunt.loadNpmTasks\('grunt-sync'\);/); + assert.fileContent('Gruntfile.js', /grunt.loadNpmTasks\('grunt-sync'\);/); }); it('registers default task', function() { - helpers.assertFileContent('Gruntfile.js', /grunt.registerTask\('default',/); + assert.fileContent('Gruntfile.js', /grunt.registerTask\('default',/); }); }); }); describe('esri-appbuilder-js generator - no app', function () { before(function (done) { - helpers.testDirectory(wabRoot, function (err) { - if (err) { - return done(err); - } - - mkdirp(appDirPath, function (err) { - if (err) { - console.error(err); - } else { - fs.writeFileSync(filePath, configFileContents); - - this.app = helpers.createGenerator('esri-appbuilder-js:app', [ - '../../app' - ]); - - helpers.mockPrompt(this.app, { - 'abort': false, - 'wabRoot': wabRoot, - 'appDirId': 'None' - }); - this.app.options['skip-install'] = true; - this.app.run({}, function () { - done(); - }); - } - }.bind(this)); - }.bind(this)); + helpers.run(path.join(__dirname, '../app')) + .withOptions({ skipInstall: true }) + .withPrompts({ + 'abort': false, + 'wabRoot': wabRoot, + 'appDirId': 'None' + }).inTmpDir(function(/*dir*/) { + var done = this.async(); + mkdirp(appDirPath, function () { + fs.writeFileSync(configFilePath, configFileContents); + done(); + }); + }) + .on('end', done); }); describe('when creating gruntfile', function() { it('appDir set to "todo"', function() { - helpers.assertFileContent('Gruntfile.js', new RegExp('var appDir = \'TODO(.*)')); + assert.fileContent('Gruntfile.js', new RegExp('var appDir = \'TODO(.*)')); }); // TODO - not testing the other parts of the gruntfile here since it's the same as the previous // case. That common code should be pulled out in the future. @@ -123,33 +95,14 @@ describe('esri-appbuilder-js generator - no app', function () { describe('esri-appbuilder-js abort', function () { before(function (done) { - helpers.testDirectory(path.join(__dirname, 'temp'), function (err) { - if (err) { - return done(err); - } - - mkdirp(appDirPath, function (err) { - if (err) { - console.error(err); - } else { - fs.writeFileSync(filePath, configFileContents); - - this.app = helpers.createGenerator('esri-appbuilder-js:app', [ - '../../app' - ]); - - helpers.mockPrompt(this.app, { - 'abort': true, - 'wabRoot': wabRoot, - 'appDirId': appDirId - }); - this.app.options['skip-install'] = true; - this.app.run({}, function () { - done(); - }); - } - }.bind(this)); - }.bind(this)); + helpers.run(path.join(__dirname, '../app')) + .withOptions({ skipInstall: true }) + .withPrompts({ + 'abort': true, + 'wabRoot': wabRoot, + 'appDirId': appDirId + }) + .on('end', done); }); it('does not create dotfiles or Gruntfile', function () { @@ -158,6 +111,6 @@ describe('esri-appbuilder-js abort', function () { '.editorconfig', 'Gruntfile.js' ]; - helpers.assertNoFile(expected); + assert.noFile(expected); }); }); diff --git a/test/test-load.js b/test/test-load.js deleted file mode 100644 index c546480..0000000 --- a/test/test-load.js +++ /dev/null @@ -1,10 +0,0 @@ -/*global describe, beforeEach, it*/ -'use strict'; -var assert = require('assert'); - -describe('esri-appbuilder-js generator', function () { - it('can be imported without blowing up', function () { - var app = require('../app'); - assert(app !== undefined); - }); -}); diff --git a/test/test-widget.js b/test/test-widget.js index 4a13a3e..765949b 100644 --- a/test/test-widget.js +++ b/test/test-widget.js @@ -1,45 +1,30 @@ /*global describe, before, beforeEach, it */ 'use strict'; var path = require('path'); -var helpers = require('yeoman-generator').test; +var assert = require('yeoman-assert'); +var helpers = require('yeoman-test'); var fs = require('fs'); -var wabRoot = path.join(__dirname, 'temp'); -var filePath = 'package.json'; +var generatorPath = path.join(__dirname, '../widget'); var testAuthorName = 'Barney Rubble'; var testAuthorEmail = 'b@rubble.com'; var testAuthorUrl = 'http://barnyrubble.tumblr.com'; var testLicense = 'Apache-2.0'; describe('esri-appbuilder-js:widget subgenerator', function () { - beforeEach(function (done) { - helpers.testDirectory(wabRoot, function (err) { - if (err) { - return done(err); - } - - this.widget = helpers.createGenerator('esri-appbuilder-js:widget', [ - '../../widget' - ]); - console.log('cleared folder and created widget generator'); - done(); - }.bind(this)); - }); describe('when creating an inPanel widget', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', path: 'widgets', baseClass: 'test-widget', features: [ 'inPanel', 'hasLocale', 'hasStyle', 'hasConfig', 'hasUIFile' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -56,66 +41,64 @@ describe('esri-appbuilder-js:widget subgenerator', function () { ]; // TODO: replace w/ assertFileContent(pairs)? // see: http://yeoman.github.io/generator/assert.html - helpers.assertFile(expected); + assert.file(expected); }); it('should set Label to widgetTitle', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); + assert.fileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); }); it('should set inPanel to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); }); it('sets manifest hasLocale to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); }); it('sets manifest hasConfig to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); }); it('sets manifest hasStyle to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); }); it('sets manifest hasUIFile to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); }); it('has baseClass in widget', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); + assert.fileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); }); it('has baseClass in css', function() { - helpers.assertFileContent('widgets/TestWidget/css/style.css', /\.test-widget/); + assert.fileContent('widgets/TestWidget/css/style.css', /\.test-widget/); }); it('references nls in template', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); + assert.fileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); }); it('has title/description in nls', function() { - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); }); }); describe('when creating a non-inPanel widget', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', path: 'widgets', baseClass: 'test-widget', features: [ 'hasLocale', 'hasStyle', 'hasConfig', 'hasUIFile' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -130,66 +113,64 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/manifest.json' // TODO: settings ]; - helpers.assertFile(expected); + assert.file(expected); }); it('should set Label to widgetTitle', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); + assert.fileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); }); it('sets inPanel to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"inPanel": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"inPanel": false/); }); it('sets manifest hasLocale to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); }); it('sets manifest hasConfig to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); }); it('sets manifest hasStyle to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); }); it('sets manifest hasUIFile to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); }); it('has baseClass in widget', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); + assert.fileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); }); it('has baseClass in css', function() { - helpers.assertFileContent('widgets/TestWidget/css/style.css', /\.test-widget/); + assert.fileContent('widgets/TestWidget/css/style.css', /\.test-widget/); }); it('references nls in template', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); + assert.fileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); }); it('has title/description in nls', function() { - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); }); }); describe('when creating a widget w/o locale', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', path: 'widgets', baseClass: 'test-widget', features: [ 'inPanel', 'hasStyle', 'hasConfig', 'hasUIFile' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -203,66 +184,64 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/manifest.json' // TODO: settings ]; - helpers.assertFile(expected); - helpers.assertNoFile('widgets/TestWidget/nls/strings.js'); + assert.file(expected); + assert.noFile('widgets/TestWidget/nls/strings.js'); }); it('should set Label to widgetTitle', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); + assert.fileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); }); it('should set inPanel to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); }); it('sets manifest hasLocale to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasLocale": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasLocale": false/); }); it('sets manifest hasConfig to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); }); it('sets manifest hasStyle to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); }); it('sets manifest hasUIFile to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); }); it('has baseClass in widget', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); + assert.fileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); }); it('has baseClass in css', function() { - helpers.assertFileContent('widgets/TestWidget/css/style.css', /\.test-widget/); + assert.fileContent('widgets/TestWidget/css/style.css', /\.test-widget/); }); it('does not reference nls in template', function() { - helpers.assertNoFileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); + assert.noFileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); }); it('references title/description in template', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.html', /Test Widget/); - helpers.assertFileContent('widgets/TestWidget/Widget.html', /A test widget\./); + assert.fileContent('widgets/TestWidget/Widget.html', /Test Widget/); + assert.fileContent('widgets/TestWidget/Widget.html', /A test widget\./); }); }); describe('when creating a widget w/o style', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', path: 'widgets', baseClass: 'test-widget', features: [ 'inPanel', 'hasLocale', 'hasConfig', 'hasUIFile' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -276,63 +255,61 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/manifest.json' // TODO: settings ]; - helpers.assertFile(expected); - helpers.assertNoFile('widgets/TestWidget/css/style.css'); + assert.file(expected); + assert.noFile('widgets/TestWidget/css/style.css'); }); it('should set Label to widgetTitle', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); + assert.fileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); }); it('should set inPanel to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); }); it('sets manifest hasLocale to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); }); it('sets manifest hasStyle to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasStyle": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasStyle": false/); }); it('sets manifest hasUIFile to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); }); it('sets manifest hasConfig to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); }); it('has baseClass in widget', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); + assert.fileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); }); it('references nls in template', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); + assert.fileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); }); it('has title/description in nls', function() { - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); }); }); describe('when creating a widget w/o config', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', path: 'widgets', baseClass: 'test-widget', features: [ 'inPanel', 'hasLocale', 'hasStyle', 'hasUIFile' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -346,45 +323,45 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/manifest.json' // TODO: settings ]; - helpers.assertFile(expected); - helpers.assertNoFile('widgets/TestWidget/config.json'); + assert.file(expected); + assert.noFile('widgets/TestWidget/config.json'); }); it('should set Label to widgetTitle', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); + assert.fileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); }); it('should set inPanel to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); }); it('sets manifest hasLocale to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); }); it('sets manifest hasStyle to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); }); it('sets manifest hasUIFile to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasUIFile": true/); }); it('sets manifest hasConfig to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasConfig": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasConfig": false/); }); it('has baseClass in widget', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); + assert.fileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); }); it('references nls in template', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); + assert.fileContent('widgets/TestWidget/Widget.html', /\$\{nls\./); }); it('has title/description in nls', function() { - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); }); }); @@ -392,18 +369,16 @@ describe('esri-appbuilder-js:widget subgenerator', function () { describe('when creating a widget w/o template', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', path: 'widgets', baseClass: 'test-widget', features: [ 'inPanel', 'hasLocale', 'hasStyle', 'hasConfig' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -417,41 +392,41 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/manifest.json' // TODO: settings ]; - helpers.assertFile(expected); - helpers.assertNoFile('widgets/TestWidget/Widget.html'); + assert.file(expected); + assert.noFile('widgets/TestWidget/Widget.html'); }); it('should set Label to widgetTitle', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); + assert.fileContent('widgets/TestWidget/manifest.json', /"label": "Test Widget"/); }); it('should set inPanel to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"inPanel": true/); }); it('sets manifest hasLocale to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasLocale": true/); }); it('sets manifest hasStyle to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasStyle": true/); }); it('sets manifest hasConfig to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasConfig": true/); }); it('sets manifest hasUIFile to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasUIFile": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasUIFile": false/); }); it('has baseClass in widget', function() { - helpers.assertFileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); + assert.fileContent('widgets/TestWidget/Widget.js', /baseClass: 'test-widget'/); }); it('has title/description in nls', function() { - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); - helpers.assertFileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /widgetTitle: "Test Widget"/); + assert.fileContent('widgets/TestWidget/nls/strings.js', /description: "A test widget\."/); }); }); @@ -459,8 +434,8 @@ describe('esri-appbuilder-js:widget subgenerator', function () { /** SETTINGS */ describe('when creating a widget with settings', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -469,10 +444,8 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [ 'inPanel', 'hasLocale', 'hasStyle', 'hasConfig' ], hasSettingPage: true, settingsFeatures: [ 'hasSettingUIFile', 'hasSettingLocale', 'hasSettingStyle' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -489,28 +462,29 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/setting/css/style.css', 'widgets/TestWidget/setting/nls/strings.js' ]; + assert.file(expected); }); it('should set hasSettingUIFile to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": true/); }); it('should set hasSettingLocale to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": true/); }); it('should set hasSettingStyle to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": true/); }); it('has baseClass in Setting.js', function() { - helpers.assertFileContent('widgets/TestWidget/setting/Setting.js', /baseClass: 'test-widget-setting'/); + assert.fileContent('widgets/TestWidget/setting/Setting.js', /baseClass: 'test-widget-setting'/); }); }); describe('when creating a widget without settings', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -518,10 +492,8 @@ describe('esri-appbuilder-js:widget subgenerator', function () { baseClass: 'test-widget', features: [ 'inPanel', 'hasLocale', 'hasStyle', 'hasConfig' ], hasSettingPage: false - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -534,29 +506,29 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/images/icon.png', 'widgets/TestWidget/manifest.json' ]; - helpers.assertFile(expected); - helpers.assertNoFile('widgets/TestWidget/setting/Setting.js'); - helpers.assertNoFile('widgets/TestWidget/setting/Setting.html'); - helpers.assertNoFile('widgets/TestWidget/setting/css/style.css'); - helpers.assertNoFile('widgets/TestWidget/setting/nls/strings.js'); + assert.file(expected); + assert.noFile('widgets/TestWidget/setting/Setting.js'); + assert.noFile('widgets/TestWidget/setting/Setting.html'); + assert.noFile('widgets/TestWidget/setting/css/style.css'); + assert.noFile('widgets/TestWidget/setting/nls/strings.js'); }); it('should set hasSettingUIFile to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": false/); }); it('should set hasSettingLocale to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": false/); }); it('should set hasSettingStyle to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": false/); }); }); describe('when creating a widget with settings without style', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -565,10 +537,8 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [ 'inPanel', 'hasLocale', 'hasStyle', 'hasConfig' ], hasSettingPage: true, settingsFeatures: [ 'hasSettingUIFile', 'hasSettingLocale' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); @@ -587,26 +557,26 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/setting/nls/strings.js' ]; - helpers.assertFile(expected); - helpers.assertNoFile('widgets/TestWidget/setting/css/style.css'); + assert.file(expected); + assert.noFile('widgets/TestWidget/setting/css/style.css'); }); it('should set hasSettingUIFile to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": true/); }); it('should set hasSettingLocale to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": true/); }); it('should set hasSettingStyle to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": false/); }); }); describe('when creating a widget with settings without locale', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -615,10 +585,8 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [ 'inPanel', 'hasLocale', 'hasStyle', 'hasConfig' ], hasSettingPage: true, settingsFeatures: [ 'hasSettingUIFile', 'hasSettingStyle' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -634,26 +602,26 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/setting/Setting.html', 'widgets/TestWidget/setting/css/style.css' ]; - helpers.assertFile(expected); - helpers.assertNoFile('widgets/TestWidget/setting/nls/strings.js'); + assert.file(expected); + assert.noFile('widgets/TestWidget/setting/nls/strings.js'); }); it('should set hasSettingUIFile to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": true/); }); it('should set hasSettingLocale to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": false/); }); it('should set hasSettingStyle to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": true/); }); }); describe('when creating a widget with settings without UIFile', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -662,10 +630,8 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [ 'inPanel', 'hasLocale', 'hasStyle', 'hasConfig' ], hasSettingPage: true, settingsFeatures: [ 'hasSettingLocale', 'hasSettingStyle' ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('creates expected files', function (/*done*/) { @@ -682,28 +648,27 @@ describe('esri-appbuilder-js:widget subgenerator', function () { 'widgets/TestWidget/setting/nls/strings.js' ]; - helpers.assertFile(expected); - helpers.assertNoFile('widgets/TestWidget/setting/Setting.html'); + assert.file(expected); + assert.noFile('widgets/TestWidget/setting/Setting.html'); }); it('should set hasSettingUIFile to false in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": false/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingUIFile": false/); }); it('should set hasSettingLocale to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingLocale": true/); }); it('should set hasSettingStyle to true in manifest', function() { - helpers.assertFileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": true/); + assert.fileContent('widgets/TestWidget/manifest.json', /"hasSettingStyle": true/); }); }); describe('when creating a widget that has a package.json', function() { - beforeEach(function(done) { - fs.writeFileSync(filePath, '{"author":"' + testAuthorName + '", "license":"' + testLicense + '"}'); + before(function(done) { - helpers.mockPrompt(this.widget, { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -712,26 +677,27 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [], hasSettingPage: false, settingsFeatures: [ ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .inTmpDir(function(dir) { + console.log(path.join(dir, 'package.json')); + fs.writeFileSync(path.join(dir, 'package.json'), '{"author":"' + testAuthorName + '", "license":"' + testLicense + '"}'); + }) + .on('end', done); }); it('has author name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + '",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + '",')); }); it('has license name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); }); }); describe('when creating a widget that has a package.json with author object - name only', function() { - beforeEach(function(done) { - fs.writeFileSync(filePath, '{"author":{"name":"' + testAuthorName + '"}, "license":"' + testLicense + '"}'); + before(function(done) { - helpers.mockPrompt(this.widget, { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -740,26 +706,26 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [], hasSettingPage: false, settingsFeatures: [ ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .inTmpDir(function(dir) { + fs.writeFileSync(path.join(dir, 'package.json'), '{"author":{"name":"' + testAuthorName + '"}, "license":"' + testLicense + '"}'); + }) + .on('end', done); }); it('has author name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + '",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + '",')); }); it('has license name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); }); }); describe('when creating a widget that has a package.json with author object - author and email', function() { - beforeEach(function(done) { - fs.writeFileSync(filePath, '{"author":{"name":"' + testAuthorName + '", "email":"' + testAuthorEmail + '"}, "license":"' + testLicense + '"}'); + before(function(done) { - helpers.mockPrompt(this.widget, { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -768,26 +734,26 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [], hasSettingPage: false, settingsFeatures: [ ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .inTmpDir(function(dir) { + fs.writeFileSync(path.join(dir, 'package.json'), '{"author":{"name":"' + testAuthorName + '", "email":"' + testAuthorEmail + '"}, "license":"' + testLicense + '"}'); + }) + .on('end', done); }); it('has author name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + ' <' + testAuthorEmail + '>",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + ' <' + testAuthorEmail + '>",')); }); it('has license name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); }); }); - describe('when creating a widget that has a package.json with author object but no name property', function() { - beforeEach(function(done) { - fs.writeFileSync(filePath, '{"author":{"url":"' + testAuthorUrl + '"}, "license":"' + testLicense + '"}'); + describe('when creating a widget that has a package.json with author object but no name property', function() { + before(function(done) { - helpers.mockPrompt(this.widget, { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -796,26 +762,26 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [], hasSettingPage: false, settingsFeatures: [ ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .inTmpDir(function(dir) { + fs.writeFileSync(path.join(dir, 'package.json'), '{"author":{"url":"' + testAuthorUrl + '"}, "license":"' + testLicense + '"}'); + }) + .on('end', done); }); it('has blank author in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "",')); }); it('has license name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); }); }); describe('when creating a widget that has a package.json with author object - author and url', function() { - beforeEach(function(done) { - fs.writeFileSync(filePath, '{"author":{"name":"' + testAuthorName + '", "url":"' + testAuthorUrl + '"}, "license":"' + testLicense + '"}'); + before(function(done) { - helpers.mockPrompt(this.widget, { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -824,26 +790,26 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [], hasSettingPage: false, settingsFeatures: [ ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .inTmpDir(function(dir) { + fs.writeFileSync(path.join(dir, 'package.json'), '{"author":{"name":"' + testAuthorName + '", "url":"' + testAuthorUrl + '"}, "license":"' + testLicense + '"}'); + }) + .on('end', done); }); it('has author name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + ' \\(' + testAuthorUrl + '\\)"')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + ' \\(' + testAuthorUrl + '\\)"')); }); it('has license name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); }); }); describe('when creating a widget that has a package.json with author object - author, email, url', function() { - beforeEach(function(done) { - fs.writeFileSync(filePath, '{"author":{"name":"' + testAuthorName + '", "email":"' + testAuthorEmail + '", "url":"' + testAuthorUrl + '"}, "license":"' + testLicense + '"}'); + before(function(done) { - helpers.mockPrompt(this.widget, { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -852,24 +818,25 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [], hasSettingPage: false, settingsFeatures: [ ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .inTmpDir(function(dir) { + fs.writeFileSync(path.join(dir, 'package.json'), '{"author":{"name":"' + testAuthorName + '", "email":"' + testAuthorEmail + '", "url":"' + testAuthorUrl + '"}, "license":"' + testLicense + '"}'); + }) + .on('end', done); }); it('has author name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + ' <' + testAuthorEmail + '> \\(' + testAuthorUrl + '\\)"')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "' + testAuthorName + ' <' + testAuthorEmail + '> \\(' + testAuthorUrl + '\\)"')); }); it('has license name in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "' + testLicense + '",')); }); }); describe('when creating a widget that does not have a package.json', function() { - beforeEach(function(done) { - helpers.mockPrompt(this.widget, { + before(function(done) { + helpers.run(generatorPath).withPrompts({ widgetName: 'TestWidget', widgetTitle: 'Test Widget', description: 'A test widget.', @@ -878,18 +845,16 @@ describe('esri-appbuilder-js:widget subgenerator', function () { features: [], hasSettingPage: false, settingsFeatures: [ ] - }); - this.widget.run({}, function () { - done(); - }); + }) + .on('end', done); }); it('has blank author in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"author": "",')); }); it('has blank license in manifest.json', function (/*done*/) { - helpers.assertFileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "",')); + assert.fileContent('widgets/TestWidget/manifest.json', new RegExp('"license": "",')); }); }); diff --git a/widget/index.js b/widget/index.js index b445a23..4d3ed4e 100644 --- a/widget/index.js +++ b/widget/index.js @@ -1,13 +1,13 @@ 'use strict'; var path = require('path'); -var yeoman = require('yeoman-generator'); +var Base = require('yeoman-generator').Base; var chalk = require('chalk'); +var dasherize = require('underscore.string/dasherize'); var utils = require('./utils'); -var WidgetGenerator = yeoman.generators.Base.extend({ +var WidgetGenerator = Base.extend({ askFor: function () { var done = this.async(); - var dasherize = this._.dasherize; console.log(chalk.green('Welcome to the ArcGIS Web AppBuilder widget generator!')); @@ -149,7 +149,7 @@ var WidgetGenerator = yeoman.generators.Base.extend({ files: function () { // NOTE: this is needed b/c _Widget.html has ES6 style interpolation delimiters // see: https://github.com/lodash/lodash/issues/399 - this._.templateSettings.interpolate = /<%=([\s\S]+?)%>/g; + // this._.templateSettings.interpolate = /<%=([\s\S]+?)%>/g; var basePath = path.join('widgets', this.widgetName); this.template('_Widget.js', path.join(basePath, 'Widget.js')); if (this.hasUIFile) { diff --git a/widget/templates/_manifest.json b/widget/templates/_manifest.json index f73f365..acc8ace 100644 --- a/widget/templates/_manifest.json +++ b/widget/templates/_manifest.json @@ -6,7 +6,7 @@ "platform": "HTML", "version": "0.0.1", "wabVersion": "1.4", - "author": "<%= author %>", + "author": "<%- author %>", "description": "<%= description %>", "copyright": "", "license": "<%= license %>", From cb85b46a3a3bae21c5c28229867acb358cddfe7d Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Tue, 9 Feb 2016 11:18:19 -0800 Subject: [PATCH 2/4] changes needed to support node v0.10-v0.12 --- package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4510fa2..670ed67 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "node": ">=0.10.0" }, "scripts": { - "test": "mocha" + "test": "mocha --timeout 10000" }, "files": [ "app", @@ -34,6 +34,9 @@ "yosay": "^1.0.2" }, "devDependencies": { - "mocha": "*" + "mkdirp": "^0.5.1", + "mocha": "*", + "yeoman-assert": "^2.0.0", + "yeoman-test": "^1.0.0" } } From 7d528f84c3aa9d52915c070be372b0a28f6098ba Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Tue, 9 Feb 2016 11:17:05 -0800 Subject: [PATCH 3/4] remove comments --- widget/index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/widget/index.js b/widget/index.js index 4d3ed4e..ef77b43 100644 --- a/widget/index.js +++ b/widget/index.js @@ -147,9 +147,6 @@ var WidgetGenerator = Base.extend({ }, files: function () { - // NOTE: this is needed b/c _Widget.html has ES6 style interpolation delimiters - // see: https://github.com/lodash/lodash/issues/399 - // this._.templateSettings.interpolate = /<%=([\s\S]+?)%>/g; var basePath = path.join('widgets', this.widgetName); this.template('_Widget.js', path.join(basePath, 'Widget.js')); if (this.hasUIFile) { From d6c3faa804f4ac679182a82c41b5c3937f628a93 Mon Sep 17 00:00:00 2001 From: Tom Wayson Date: Tue, 9 Feb 2016 11:17:42 -0800 Subject: [PATCH 4/4] test in all supported node envs --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index aeda4c5..77a752d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ +sudo: false language: node_js node_js: - - "stable" + - 'stable' + - 'v4' + - '0.12' - '0.10' -before_install: - - currentfolder=${PWD##*/} - - if [ "$currentfolder" != 'generator-esri-appbuilder-js' ]; then cd .. && eval "mv $currentfolder generator-esri-appbuilder-js" && cd generator-esri-appbuilder-js; fi -