test lint on commit

This commit is contained in:
Evan You
2018-01-06 22:33:38 -05:00
parent 692f1bf13f
commit 7db29118ef
7 changed files with 54 additions and 30 deletions
@@ -0,0 +1,50 @@
jest.setTimeout(10000)
const path = require('path')
const create = require('@vue/cli-test-utils/createTestProject')
// const serve = require('@vue/cli-test-utils/serveWithPuppeteer')
const runSilently = fn => {
const log = console.log
console.log = () => {}
fn()
console.log = log
}
test('should work', async () => {
const project = await create('eslint', {
plugins: {
'@vue/cli-plugin-babel': {},
'@vue/cli-plugin-eslint': {
config: 'airbnb',
lintOn: 'commit'
}
}
})
const { read, write, run } = project
// should've applied airbnb autofix
const main = await read('src/main.js')
expect(main).toMatch(';')
// remove semicolons
const updatedMain = main.replace(/;/g, '')
await write('src/main.js', updatedMain)
// lint
await run('vue-cli-service lint')
expect(await read('src/main.js')).toMatch(';')
// lint-on-commit
runSilently(() => {
require('yorkie/src/install')(path.join(project.dir, 'node_modules'))
})
const hook = await read('.git/hooks/pre-commit')
expect(hook).toMatch('#yorkie')
await write('src/main.js', updatedMain)
// nvm doesn't like PREFIX env
delete process.env.PREFIX
await run('git add -A')
await run('git commit -m save')
// should be linted on commit
expect(await read('src/main.js')).toMatch(';')
// TODO lint-on-save
})
@@ -1,27 +0,0 @@
jest.setTimeout(10000)
const create = require('@vue/cli-test-utils/createTestProject')
test('should work', async () => {
const { read, write, run } = await create('eslint', {
plugins: {
'@vue/cli-plugin-babel': {},
'@vue/cli-plugin-eslint': {
config: 'airbnb',
lintOn: 'commit'
}
}
})
// should've applied airbnb autofix
const main = await read('src/main.js')
expect(main).toMatch(';')
// remove semicolons
await write('src/main.js', main.replace(/;/g, ''))
// lint
await run('vue-cli-service lint')
expect(await read('src/main.js')).toMatch(';')
// TODO lint-on-commit
// TODO lint-on-save
})
@@ -18,7 +18,7 @@ test('serve', async () => {
await project.write(`src/App.vue`, file.replace(msg, `Updated`))
await nextUpdate() // wait for child stdout update signal
await sleep(1000) // give the client time to update, should happen in 1s
await sleep(process.env.CI ? 3000 : 500) // give the client time to update
await assertText('h1', `Updated`)
})
})
@@ -30,8 +30,8 @@ module.exports = function createTestProject (name, config, cwd) {
const run = (command, args) => {
if (!args) { [command, ...args] = command.split(/\s+/) }
const child = execa(command, args, { cwd: projectRoot })
child.then(({ stderr }) => {
if (stderr) console.error(stderr)
child.then(({ code, stderr }) => {
if (code !== 0 && stderr) console.error(stderr)
})
return child
}
@@ -52,6 +52,7 @@ module.exports = function createTestProject (name, config, cwd) {
}
return execa(cliBinPath, args, options).then(() => ({
dir: projectRoot,
read,
write,
run