From 206e26a74aea16e1b343c7e15572ffb27a500cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 30 Jan 2020 22:00:40 +0100 Subject: [PATCH] fix(bin/elm-app): pass the correct argument to `elm-app create` command #385 --- bin/elm-app-cli.js | 5 ++++- tests/elm-app.create.spec.js | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/elm-app.create.spec.js diff --git a/bin/elm-app-cli.js b/bin/elm-app-cli.js index a81f5b25..0f960b78 100755 --- a/bin/elm-app-cli.js +++ b/bin/elm-app-cli.js @@ -30,7 +30,6 @@ if (commands.length === 0) { const script = commands[0]; switch (script) { - case 'create': case 'build': case 'eject': case 'start': @@ -55,6 +54,10 @@ switch (script) { spawnSyncNode(path.resolve(__dirname, '../scripts', script), args, env); break; + case 'create': + spawnSyncNode(path.resolve(__dirname, '../scripts/create'), commands[1]); + break; + case 'test': { let args = []; Object.keys(argv || {}).forEach(key => { diff --git a/tests/elm-app.create.spec.js b/tests/elm-app.create.spec.js new file mode 100644 index 00000000..091d2062 --- /dev/null +++ b/tests/elm-app.create.spec.js @@ -0,0 +1,39 @@ +const path = require('path'); +const expect = require('unexpected'); +const spawn = require('cross-spawn'); +const dircompare = require('dir-compare'); +const fs = require('fs'); +const rimraf = require('rimraf'); + +const testAppName = 'test-app-eject'; +const rootDir = path.resolve(__dirname, '..'); +const testAppDir = path.join(rootDir, testAppName); +const elmAppCmd = path.join(rootDir, 'bin/elm-app-cli.js'); + +describe('Create Elm application with `elm-app create` command', () => { + after(() => { + rimraf.sync(testAppDir); + }); + + it(`'elm-app create ${testAppName}' should succeed`, () => { + const { status } = spawn.sync('node', [elmAppCmd, 'create', testAppName]); + expect(status, 'to be', 0); + }).timeout(60 * 1000); + + it(`'${testAppName}' should have elm.json file`, () => { + expect(fs.existsSync(path.join(testAppDir, 'elm.json')), 'to be', true); + }); + + it(`'${testAppName}' should have .gitignore file`, () => { + expect(fs.existsSync(path.join(testAppDir, '.gitignore')), 'to be', true); + }); + + it(`'${testAppName}' should have the same file structure as template`, () => { + const templateDir = path.join(rootDir, 'template'); + const options = { + excludeFilter: 'elm-stuff, elm.json, gitignore, .gitignore, build' + }; + const { same } = dircompare.compareSync(templateDir, testAppDir, options); + expect(same, 'to be', true); + }); +});