diff --git a/bin/encore.js b/bin/encore.js index b8ba29e2..c8b96b41 100755 --- a/bin/encore.js +++ b/bin/encore.js @@ -15,7 +15,7 @@ const context = require('../lib/context'); const chalk = require('chalk'); const runtimeConfig = parseRuntime( - require('yargs').argv, + require('yargs/yargs')(process.argv.slice(2)).argv, process.cwd() ); context.runtimeConfig = runtimeConfig; diff --git a/test/bin/encore.js b/test/bin/encore.js new file mode 100644 index 00000000..acdcc831 --- /dev/null +++ b/test/bin/encore.js @@ -0,0 +1,50 @@ +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +'use strict'; + +const chai = require('chai'); +chai.use(require('chai-fs')); +const path = require('path'); +const testSetup = require('../../lib/test/setup'); +const fs = require('fs-extra'); +const exec = require('child_process').exec; + +describe('bin/encore.js', function() { + // being functional tests, these can take quite long + this.timeout(8000); + + it('Basic smoke test', (done) => { + testSetup.emptyTmpDir(); + const testDir = testSetup.createTestAppDir(); + + fs.writeFileSync( + path.join(testDir, 'webpack.config.js'), + ` +const Encore = require('../../index.js'); +Encore + .setOutputPath('build/') + .setPublicPath('/build') + .addEntry('main', './js/no_require') +; + +module.exports = Encore.getWebpackConfig(); + ` + ); + + const binPath = path.resolve(__dirname, '../', '../', 'bin', 'encore.js'); + exec(`node ${binPath} dev --context=${testDir}`, { cwd: testDir }, (err, stdout, stderr) => { + if (err) { + throw new Error(`Error executing encore: ${err} ${stderr} ${stdout}`); + } + + done(); + }); + }); +});