diff --git a/__test__/copy.test.js b/__test__/copy.test.js new file mode 100644 index 0000000..ca6e619 --- /dev/null +++ b/__test__/copy.test.js @@ -0,0 +1,38 @@ +const kopy = require('../lib') +const { fixture } = require('./utils') + +describe('copy', () => { + it('requires cwd', async () => { + const generator = kopy({ + actions() { + return [ + { + type: 'copy', + files: '**' + } + ] + } + }) + try { + await generator.emulate() + } catch (err) { + expect(err.message).toMatch('"cwd" is required for "copy" action!') + } + }) + + it('copies with glob patterns', async () => { + const generator = kopy({ + actions() { + return [ + { + type: 'copy', + files: '*.js', + cwd: fixture('copy-glob') + } + ] + } + }) + await generator.emulate() + expect(generator.fileList).toEqual(['foo.js']) + }) +}) diff --git a/__test__/fixtures/copy-glob/foo.js b/__test__/fixtures/copy-glob/foo.js new file mode 100644 index 0000000..e69de29 diff --git a/__test__/index.test.js b/__test__/index.test.js index 4b22b9a..70966b8 100644 --- a/__test__/index.test.js +++ b/__test__/index.test.js @@ -5,14 +5,20 @@ test('simple', async () => { prompts: [ { name: 'name', - type: 'input', message: 'what is your name', default: 'kevin' + }, + { + name: 'gender', + message: 'select your gender', + choices: ['male', 'female'], + initial: 'female' } ] }) await generator.emulate() expect(generator.answers).toEqual({ - name: 'kevin' + name: 'kevin', + gender: 'female' }) }) diff --git a/__test__/utils.js b/__test__/utils.js new file mode 100644 index 0000000..7a69d14 --- /dev/null +++ b/__test__/utils.js @@ -0,0 +1,5 @@ +const path = require('path') + +exports.fixture = name => { + return path.join(__dirname, 'fixtures', name) +} diff --git a/lib/Generator.js b/lib/Generator.js index a7560cf..0ca9acd 100644 --- a/lib/Generator.js +++ b/lib/Generator.js @@ -26,9 +26,6 @@ module.exports = class Generator { } get outDir() { - if (this.opts.test) { - return path.join(os.tmpdir(), `kopy-${Date.now()}`, 'output') - } return path.resolve(this.opts.outDir) } @@ -190,7 +187,8 @@ module.exports = class Generator { { emulator, test: true, - logLevel: 1 + logLevel: 1, + outDir: path.join(os.tmpdir(), `kopy-${Date.now()}`, 'output') }, opts ) diff --git a/lib/runAction.js b/lib/runAction.js index 52b88bb..53b0a93 100644 --- a/lib/runAction.js +++ b/lib/runAction.js @@ -9,6 +9,9 @@ module.exports = async (action, generator) => { if (!action.cwd) { throw new Error(`"cwd" is required for "copy" action!`) } + if (!action.files) { + throw new Error(`"files" is required for "copy" action!`) + } const stream = majo() stream.source(action.files, { baseDir: action.cwd }) if (action.filters) {