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

Commit

Permalink
add some unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed May 6, 2016
1 parent 23dfea5 commit f29bca6
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cooking [![Build Status](https://travis-ci.org/ElemeFE/cooking.svg?branch=master)](https://travis-ci.org/ElemeFE/cooking) [![Coverage Status](https://coveralls.io/repos/github/ElemeFE/cooking/badge.svg?branch=master)](https://coveralls.io/github/ElemeFE/cooking?branch=master) [![npm](https://img.shields.io/npm/dm/localeval.svg?maxAge=2592000)]()
# cooking [![Build Status](https://travis-ci.org/ElemeFE/cooking.svg?branch=master)](https://travis-ci.org/ElemeFE/cooking) [![Coverage Status](https://coveralls.io/repos/github/ElemeFE/cooking/badge.svg?branch=master)](https://coveralls.io/github/ElemeFE/cooking?branch=master) [![npm](https://img.shields.io/npm/dm/cooking.svg?maxAge=2592000)](https://www.npmjs.com/package/cooking) [![npm](https://img.shields.io/npm/v/cooking.svg?maxAge=2592000)](https://www.npmjs.com/package/cooking)

> 基于 webpack 的模块化构建工具
Expand Down
33 changes: 33 additions & 0 deletions test/check.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import path from 'path'
import fs from 'fs'
import test from 'ava'
import check from '../util/check'
import PATH from '../util/path'

test('check registry', t => {
const result = check.registry('abc')

t.is(result, '--registry=abc')
})

test('check registry error', t => {
const result = check.registry()

t.is(result, '')
})

test('check init package', t => {
check.initPluginPackage()

t.true(fs.existsSync(path.join(PATH.PLUGIN_PATH, 'package.json')))
})

test('check pluginExists', t => {
t.notThrows(function () {
check.pluginExists('vue')
})
})

test('check version', t => {
t.notThrows(check.checkVersion)
})
10 changes: 10 additions & 0 deletions test/cooking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ test('cooking set format', t => {
t.is(cooking.config.output.library, 'ABC')
})

test('cooking set format no moduleName', t => {
process.env.NODE_ENV = 'testing'

t.throws(function () {
cooking.set({
format: 'umd'
})
}, 'exit')
})

test('cooking set chunk', t => {
cooking.set({
chunk: 'vendor'
Expand Down
15 changes: 15 additions & 0 deletions test/exec.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import test from 'ava'
import exec from '../util/exec'

test('exec', t => {
t.notThrows(function () {
exec('echo', ['hello world'])
})

t.notThrows(function () {
exec('echo', ['hello world'], {
stdio: 'inherit',
errMessage: 'error'
})
})
})
8 changes: 8 additions & 0 deletions test/hot-reload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ test('disabled hotreload', t => {
app: ['entry.js']
})
})

test('no entry', t => {
process.env.NODE_ENV = 'testing'

t.throws(function () {
hotReload('', 'http://localhost:8080', false)
}, 'exit')
})
12 changes: 12 additions & 0 deletions test/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ test('logger error', t => {
t.notThrows(function () {
logger.error('ok')
})

t.notThrows(function () {
logger.error(new Error('ok'))
})
})

test('logger fatal', t => {
process.env.NODE_ENV = 'testing'

t.throws(function () {
logger.fatal('ok')
}, 'exit')
})
7 changes: 6 additions & 1 deletion util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ exports.log = function () {
*/
exports.fatal = function (message) {
exports.error(message)
process.exit(1)

if (process.env.NODE_ENV === 'testing') {
throw new Error('exit')
} else {
process.exit(1)
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion util/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function (userConfig, baseConfig) {

// plugin
config.plugins.NoErrors = new webpack.NoErrorsPlugin()
} else if (process.env.NODE_ENV === 'production') {
} else {
config.devtool = userConfig.sourceMap ? '#source-map' : false

// hash
Expand Down

0 comments on commit f29bca6

Please sign in to comment.