test: refactor cli integration tests (#6537)

This commit is contained in:
Pim 2019-10-11 09:35:10 +02:00 committed by Pooya Parsa
parent a0ef4a3736
commit 67d5601142
6 changed files with 62 additions and 36 deletions

View File

@ -1,3 +1,8 @@
const fs = require('fs')
const path = require('path')
const corePackages = fs.readdirSync(path.resolve(__dirname, 'packages'))
module.exports = { module.exports = {
testEnvironment: 'node', testEnvironment: 'node',
@ -48,6 +53,10 @@ module.exports = {
'json' 'json'
], ],
moduleNameMapper: {
[`@nuxt/(${corePackages.join('|')})(/?.*)$`]: '<rootDir>/packages/$1/src/$2'
},
reporters: [ reporters: [
'default', 'default',
['jest-junit', { outputDirectory: 'reports/junit' }] ['jest-junit', { outputDirectory: 'reports/junit' }]

View File

@ -1,10 +1,12 @@
import * as _commands from './commands' import * as commands from './commands'
import * as _imports from './imports' import * as imports from './imports'
import * as _options from './options' import * as options from './options'
export const commands = _commands export {
export const imports = _imports commands,
export const options = _options imports,
options
}
export { default as NuxtCommand } from './command' export { default as NuxtCommand } from './command'
export { default as setup } from './setup' export { default as setup } from './setup'

View File

@ -1,11 +1,17 @@
import consola from 'consola'
export default { export default {
test: true, test: true,
mode: 'spa',
hooks (hook) { hooks (hook) {
hook('build:done', () => { hook('build:done', () => {
process.stdout.write('Compiled successfully') consola.log('Compiled successfully')
}) })
hook('listen', (server, { port, host }) => { hook('listen', (server, { port, host }) => {
process.stdout.write(`Listening on http://${host}:${port}`) consola.log(`Listening on http://${host}:${port}`)
}) })
},
build: {
terser: false
} }
} }

View File

@ -1,21 +1,20 @@
import { exec } from 'child_process' import { NuxtCommand, commands } from '@nuxt/cli'
import { resolve } from 'path' import consola from 'consola'
import { promisify } from 'util'
const execify = promisify(exec)
const rootDir = __dirname
const nuxtBin = resolve(__dirname, '../../../packages/cli/bin/nuxt.js')
describe('cli build', () => { describe('cli build', () => {
test.skip('nuxt build', async () => { test('nuxt build', async () => {
const { stdout } = await execify(`node -r esm ${nuxtBin} build ${rootDir} -c cli.build.config.js`) const buildCommand = await commands.default('build')
expect(stdout.includes('Compiled successfully')).toBe(true) const argv = [
}, 80000) __dirname,
'--no-force-exit',
'-c',
'cli.build.config.js'
]
test.skip('nuxt build -> error config', async () => { const cmd = new NuxtCommand(buildCommand, argv)
await expect(execify(`node -r esm ${nuxtBin} build ${rootDir} -c config.js`)).rejects.toMatchObject({ await expect(cmd.run()).resolves.toBeUndefined()
stderr: expect.stringContaining('Could not load config file: config.js')
}) expect(consola.log).toBeCalledWith('Compiled successfully')
}) })
}) })

View File

@ -1,3 +1,5 @@
import consola from 'consola'
export default { export default {
test: true, test: true,
buildDir: '.nuxt-generate/build', buildDir: '.nuxt-generate/build',
@ -7,10 +9,13 @@ export default {
hooks (hook) { hooks (hook) {
hook('generate:done', (generator, errors) => { hook('generate:done', (generator, errors) => {
if (!errors || errors.length === 0) { if (!errors || errors.length === 0) {
process.stdout.write('Generated successfully') consola.log('Generated successfully')
} else { } else {
process.stderr.write('Generated failed') consola.log('Generated failed')
} }
}) })
},
build: {
terser: false
} }
} }

View File

@ -1,15 +1,20 @@
import { exec } from 'child_process' import { NuxtCommand, commands } from '@nuxt/cli'
import { resolve } from 'path' import consola from 'consola'
import { promisify } from 'util'
const execify = promisify(exec)
const rootDir = __dirname
const nuxtBin = resolve(__dirname, '../../../packages/cli/bin/nuxt.js')
describe('cli generate', () => { describe('cli generate', () => {
test.skip('nuxt generate', async () => { test('nuxt generate', async () => {
const { stdout } = await execify(`node -r esm ${nuxtBin} generate ${rootDir} -c cli.gen.config.js`) const generateCommand = await commands.default('generate')
expect(stdout.includes('Generated successfully')).toBe(true) const argv = [
}, 80000) __dirname,
'--no-force-exit',
'-c',
'cli.gen.config.js'
]
const cmd = new NuxtCommand(generateCommand, argv)
await expect(cmd.run()).resolves.toBeUndefined()
expect(consola.log).toBeCalledWith('Generated successfully')
})
}) })