Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ntwcklng committed Dec 31, 2016
1 parent 1e4681e commit adeb199
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 33 deletions.
30 changes: 22 additions & 8 deletions test/create-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import {VERSIONS} from '../build/constants'
let origCwd
let tmpDir

const run = args => Promise.resolve()
.then(async () => {
try {
await cli(args)
} catch (err) {
if (err.userError) {
console.error(`> ${err.message}`)
} else {
console.error(`> ${err.stack}`)
}
}
})

test.before(() => {
origCwd = process.cwd()
tmpDir = temp.mkdirSync('frame-new')
Expand All @@ -23,6 +36,7 @@ test('create a new react project without errors', async t => {
t.is(pkg.dependencies.react, VERSIONS[proj.type])
t.is(proj.name, tmpDir)
t.is(proj.type, 'react')
return
})
})

Expand All @@ -33,6 +47,7 @@ test('create a new preact project without errors', async t => {
t.is(pkg.dependencies.preact, VERSIONS[proj.type])
t.is(proj.name, tmpDir)
t.is(proj.type, 'preact')
return
})
})

Expand All @@ -43,18 +58,17 @@ test('create a new Next.js project without errors', async t => {
t.is(pkg.dependencies.next, VERSIONS[proj.type])
t.is(proj.name, tmpDir)
t.is(proj.type, 'next')
return
})
})

test('should exit when an invalid project type is passed', async t => {
await cli({_: ['invalid', 'tmp-no-exist']}).catch(err => {
if (err) {
const firstLine = err.message.split('\n')[0]
t.is(firstLine, 'invalid is not a valid FRAME project type')
} else {
t.fail('No errors?')
}
})
try {
await run({_: ['invalid', 'tmp-no-exist']})
} catch (err) {
const firstLine = err.message.split('\n')[0]
t.is(firstLine, 'invalid is not a valid FRAME project type')
}
})

test.after.always('cleanup', () => {
Expand Down
57 changes: 32 additions & 25 deletions test/install-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ import temp from 'temp'
import cli from '../build/'
import {VERSIONS} from '../build/constants'

function run(opts = {}) {
return new Promise((resolve, reject) => {
cli({_: [opts.type, opts.targetDir], 'skip-git': true, silent: true}).then(() => {
const cwd = path.resolve(process.cwd(), `./${opts.targetDir}`)
const pkg = require(path.join(cwd, 'package.json'))
exec('npm run build', {cwd, stdio: 'ignore'}, () => {
glob('**', {
dot: true,
cwd,
ignore: opts.ignore
}, (err, matches) => {
if (err) {
reject(err)
}
resolve({matches, pkg})
})
const run = opts => new Promise(async (resolve, reject) => {
try {
await cli({_: [opts.type, opts.targetDir], 'skip-git': true, silent: false})
const cwd = path.resolve(process.cwd(), `./${opts.targetDir}`)
const pkg = require(path.join(cwd, 'package.json'))
await exec('npm run build', {cwd, stdio: 'inherit'}, () => {
glob('**', {
dot: true,
cwd,
ignore: opts.ignore
}, (err, matches) => {
if (err) {
throw new Error(err)
}
return resolve({matches, pkg})
})
})
})
}
} catch (err) {
reject(err)
}
})

let origCwd
let tmpDir
Expand Down Expand Up @@ -97,6 +98,7 @@ test('SKIP_WATCH create a new Preact Project, install dependencies and build', a
})
t.deepEqual(result.matches, shouldMatch)
t.is(result.pkg.dependencies[type], VERSIONS[type])
return
})

/**
Expand All @@ -113,13 +115,18 @@ test('SKIP_WATCH create a new Next.js Project, install dependencies and build',
'pages',
'pages/index.js'
]
const result = await run({
type,
targetDir,
ignore: ['node_modules/**', '.next/bundles/**', '.next/dist/**']
})
t.deepEqual(result.matches, shouldMatch)
t.is(result.pkg.dependencies[type], VERSIONS[type])
try {
const result = await run({
type,
targetDir,
ignore: ['node_modules/**', '.next/bundles/**', '.next/dist/**']
})
t.deepEqual(result.matches, shouldMatch)
t.is(result.pkg.dependencies[type], VERSIONS[type])
return
} catch (err) {
throw new Error(err)
}
})

test.after.always('cleanup', () => {
Expand Down

0 comments on commit adeb199

Please sign in to comment.