Skip to content

Commit

Permalink
test: copy action
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Jan 10, 2019
1 parent eb90042 commit d04a374
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
38 changes: 38 additions & 0 deletions __test__/copy.test.js
Original file line number Diff line number Diff line change
@@ -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'])
})
})
Empty file.
10 changes: 8 additions & 2 deletions __test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
})
5 changes: 5 additions & 0 deletions __test__/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('path')

exports.fixture = name => {
return path.join(__dirname, 'fixtures', name)
}
6 changes: 2 additions & 4 deletions lib/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
)
Expand Down
3 changes: 3 additions & 0 deletions lib/runAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d04a374

Please sign in to comment.