mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-21 20:08:41 -05:00
test lint on commit
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user